Compare commits

..

No commits in common. "master" and "v1.0.2" have entirely different histories.

13 changed files with 354 additions and 10135 deletions

View File

@ -1,4 +0,0 @@
.eslintrc.js
babel.config.js
webpack.config.js
dist/

View File

@ -1,22 +0,0 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
overrides: [
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: [
'@typescript-eslint'
],
rules: {
}
}

2
.npmrc
View File

@ -1 +1 @@
package-lock=true package-lock=false

View File

@ -1,6 +0,0 @@
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-typescript'
]
}

266
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

10003
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,31 @@
{ {
"name": "@ijl/fire.app", "name": "@ijl/fire.app",
"version": "1.6.1", "version": "1.0.2",
"description": "", "description": "",
"main": "dist/index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "nodemon ./stubs/server.js", "start": "nodemon ./stubs/server.js",
"build": "webpack --mode development", "build": "webpack --mode development",
"build:prod": "webpack --mode production" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "innoavvlasov@gmail.com", "author": "innoavvlasov@gmail.com",
"license": "ISC", "license": "MIT",
"devDependencies": { "devDependencies": {
"@babel/core": "^7.21.0", "@types/node": "13.7.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0",
"@types/node": "16.18.12",
"@types/systemjs": "6.1.0", "@types/systemjs": "6.1.0",
"@typescript-eslint/eslint-plugin": "^5.53.0", "awesome-typescript-loader": "5.2.1",
"@typescript-eslint/parser": "^5.53.0",
"babel-loader": "^9.1.2",
"clean-webpack-plugin": "3.0.0", "clean-webpack-plugin": "3.0.0",
"es6-promise": "4.2.8", "es6-promise": "4.2.8",
"eslint": "^8.34.0",
"exports-loader": "0.7.0", "exports-loader": "0.7.0",
"fbjs": "1.0.0", "fbjs": "1.0.0",
"file-loader": "5.0.2",
"history": "4.10.1", "history": "4.10.1",
"imports-loader": "0.8.0", "imports-loader": "0.8.0",
"nodemon": "^2.0.20",
"rimraf": "3.0.1", "rimraf": "3.0.1",
"systemjs": "6.2.2", "systemjs": "6.2.2",
"typescript": "^4.9.5", "typescript": "3.7.5",
"webpack": "^5.75.0", "webpack": "4.41.5",
"webpack-cli": "^5.0.1" "webpack-cli": "3.3.10",
"whatwg-fetch": "3.0.0"
} }
} }

View File

@ -1,6 +0,0 @@
import { createBrowserHistory } from 'history'
const history = createBrowserHistory();
export default history;

View File

@ -1,14 +1,11 @@
/* eslint-disable prefer-const */ import "systemjs/dist/s";
import "systemjs/dist/system";
import "systemjs/dist/extras/amd"; import "systemjs/dist/extras/amd";
import "systemjs/dist/extras/named-register"; import "systemjs/dist/extras/named-register";
import "systemjs/dist/extras/named-exports"; import "systemjs/dist/extras/named-exports";
import "systemjs/dist/extras/transform"; import "systemjs/dist/extras/transform";
import "regenerator-runtime/runtime"; import { createBrowserHistory } from 'history'
import { Apps } from './apps' import { Apps } from './apps'
import { defineVirtualModule } from './virtual-module' import { defineVirtualModule } from './virtual-module'
import history from './history';
const systemJSImport = async (requestUrl: string) => { const systemJSImport = async (requestUrl: string) => {
const { default: component, mount, unmount } = await System.import( const { default: component, mount, unmount } = await System.import(
@ -17,47 +14,50 @@ const systemJSImport = async (requestUrl: string) => {
return { component, mount, unmount } return { component, mount, unmount }
} }
let mainMountElement = document.getElementById('app'); // const defaultNavigations = {
// login: '/login',
// main: '/main',
// news: '/news',
// org: '/org',
// sections: '/sections',
// 'news.details': '/news/{{id}}',
// 'org.details': '/org/{{name}}',
// 'sections.details': '/sections/{{name}}'
// }
if (!mainMountElement) { // const defaultApps = {
mainMountElement = document.createElement('div'); // login: { version: '1.0.0', name: 'login' },
mainMountElement.id = 'app'; // main: { version: '1.0.1', name: 'main' },
// news: { version: '1.0.0', name: 'news' },
// org: { version: '1.0.0', name: 'org' },
// sections: { version: '1.0.0', name: 'sections' }
// }
document.body.append(mainMountElement); export default async ({ apps: rawApps, navigations, config }) => {
} defineVirtualModule({navigations, config})
export default async ({ apps: rawApps, navigations, config, features }) => {
defineVirtualModule({ navigations, config, features })
const apps = new Apps(rawApps) const apps = new Apps(rawApps)
const history = createBrowserHistory()
let prevPathname = window.location.pathname let prevPathname = window.location.pathname
async function getApp() { const app = apps.findApp(history.location.pathname)
const app = apps.findApp(history.location.pathname)
const publicPath = `/${app.name}/${app.version}` const publicPath = `/${app.name}/${app.version}`
__webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}` __webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}`
const appPath = `${config.baseUrl}${publicPath}/index.js` const appPath = `${config.baseUrl}${publicPath}/index.js`
const { component, mount, unmount } = await systemJSImport(appPath); const { component, mount, unmount } = await systemJSImport(appPath);
return { component, mount, unmount }; mount(component.default);
}
let { component, mount, unmount } = await getApp() history.listen((location) => {
mount(component.default, mainMountElement);
history.listen(async (location) => {
if (location.pathname !== prevPathname) { if (location.pathname !== prevPathname) {
prevPathname = location.pathname prevPathname = location.pathname
unmount() unmount()
const nextApp = await getApp();
nextApp.mount(nextApp.component.default, mainMountElement)
unmount = nextApp.unmount;
} }
}) })
}; };

View File

@ -1,19 +1,12 @@
import history from './history';
const createVirtualModule = ({ config, navigations, features }) => ({
getConfig: () => config,
getConfigValue: (pkg: string) => config[pkg],
getNavigations: () => navigations,
getNavigationsValue: (pkg: string) => navigations[pkg],
getAllFeatures: () => features,
getFeatures: (pkg: string) => features[pkg],
getHistory: () => history,
})
export const defineVirtualModule = (params) => { export const defineVirtualModule = (params) => {
const virtualModule = createVirtualModule(params) const virtualModule = createVirtualModule(params)
System.set('root.scope', { // @ts-ignore
...virtualModule global.define('root.scope.env', [], virtualModule)
});
} }
const createVirtualModule = ({config, navigations}) => ({
getConfig: () => config,
getConfigValue: (key) => config[key],
getNavigations: () => navigations,
getNavigationsValue: (key) => navigations[key],
})

View File

@ -1,23 +1,29 @@
{ {
"compilerOptions": { "compilerOptions": {
"lib": [ "lib": [
"dom", "dom",
"ESNext" "es7"
], ],
"outDir": "./dist/", "baseUrl": ".",
"sourceMap": true, "paths": {
"esModuleInterop": true, "*": [
"downlevelIteration": true, "*",
"noImplicitAny": false, "src/*",
"module": "commonjs", "lib/*",
"target": "es6", "dist/*"
"typeRoots": [ ]
"node_modules/@types", },
"src/typings", "outDir": "./dist/",
"../../node_modules/@types" "sourceMap": true,
"esModuleInterop": true,
"downlevelIteration" :true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6",
"jsx": "react",
"typeRoots": ["node_modules/@types", "src/typings", "../../node_modules/@types"]
},
"exclude": [
"node_modules"
] ]
},
"exclude": [
"node_modules"
]
} }

View File

@ -6,20 +6,21 @@ const outputDirectory = 'dist';
const pkg = require('./package.json') const pkg = require('./package.json')
module.exports = { module.exports = {
mode: "development",
entry: { entry: {
index: './src/main.ts' index: "./src/main.ts"
}, },
output: { output: {
library: 'fireapp', library: "bootstrap",
path: path.resolve(__dirname, outputDirectory), path: path.resolve(__dirname, outputDirectory),
libraryExport: 'default', libraryExport: "default",
publicPath: `/fireapp/${pkg.version}/` publicPath: `/boorstrap/${pkg.version}/`
}, },
plugins: [new CleanWebpackPlugin()], plugins: [new CleanWebpackPlugin()],
resolve: { resolve: {
extensions: ['.ts', '.js'] extensions: [".ts", ".js"]
}, },
module: { module: {
@ -27,7 +28,11 @@ module.exports = {
{ parser: { system: false } }, { parser: { system: false } },
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
loader: 'babel-loader' loader: "awesome-typescript-loader"
},
{
test: /\.(jpe?g|gif|png|svg|woff|ttf|eot|wav|mp3)$/,
loader: "file-loader"
} }
] ]
} }