@modern-js/app-tools 1.6.10-alpha.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -28
- package/dist/js/modern/analyze/constants.js +14 -0
- package/dist/js/modern/analyze/generateCode.js +166 -0
- package/dist/js/modern/analyze/getBundleEntry.js +72 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +187 -0
- package/dist/js/modern/analyze/index.js +144 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +85 -0
- package/dist/js/modern/analyze/utils.js +86 -0
- package/dist/js/modern/index.js +2 -2
- package/dist/js/modern/utils/language.js +1 -1
- package/dist/js/node/analyze/constants.js +34 -0
- package/dist/js/node/analyze/generateCode.js +192 -0
- package/dist/js/node/analyze/getBundleEntry.js +86 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +203 -0
- package/dist/js/node/analyze/index.js +173 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +103 -0
- package/dist/js/node/analyze/utils.js +107 -0
- package/dist/js/node/index.js +4 -4
- package/dist/js/node/utils/language.js +2 -2
- package/dist/types/analyze/constants.d.ts +14 -0
- package/dist/types/analyze/generateCode.d.ts +4 -0
- package/dist/types/analyze/getBundleEntry.d.ts +3 -0
- package/dist/types/analyze/getClientRoutes.d.ts +19 -0
- package/dist/types/analyze/getFileSystemEntry.d.ts +4 -0
- package/dist/types/analyze/getHtmlTemplate.d.ts +9 -0
- package/dist/types/analyze/getServerRoutes.d.ts +9 -0
- package/dist/types/analyze/index.d.ts +39 -0
- package/dist/types/analyze/isDefaultExportFunction.d.ts +1 -0
- package/dist/types/analyze/makeLegalIdentifier.d.ts +1 -0
- package/dist/types/analyze/templates.d.ts +32 -0
- package/dist/types/analyze/utils.d.ts +15 -0
- package/package.json +17 -15
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.walkDirectory = exports.isRouteComponentFile = exports.getDefaultImports = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const walkDirectory = dir => _fs.default.readdirSync(dir).reduce((previous, filename) => {
|
|
19
|
+
const filePath = _path.default.join(dir, filename);
|
|
20
|
+
|
|
21
|
+
if (_fs.default.statSync(filePath).isDirectory()) {
|
|
22
|
+
return [...previous, ...walkDirectory(filePath)];
|
|
23
|
+
} else {
|
|
24
|
+
return [...previous, filePath];
|
|
25
|
+
}
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
exports.walkDirectory = walkDirectory;
|
|
29
|
+
|
|
30
|
+
const getDefaultImports = ({
|
|
31
|
+
entrypoint,
|
|
32
|
+
srcDirectory,
|
|
33
|
+
internalSrcAlias,
|
|
34
|
+
internalDirAlias
|
|
35
|
+
}) => {
|
|
36
|
+
const {
|
|
37
|
+
entryName,
|
|
38
|
+
fileSystemRoutes,
|
|
39
|
+
customBootstrap,
|
|
40
|
+
entry
|
|
41
|
+
} = entrypoint;
|
|
42
|
+
const imports = [{
|
|
43
|
+
specifiers: [{
|
|
44
|
+
local: 'React'
|
|
45
|
+
}],
|
|
46
|
+
value: 'react'
|
|
47
|
+
}, {
|
|
48
|
+
specifiers: [{
|
|
49
|
+
imported: 'createApp'
|
|
50
|
+
}, {
|
|
51
|
+
imported: 'bootstrap'
|
|
52
|
+
}],
|
|
53
|
+
value: '@modern-js/runtime'
|
|
54
|
+
}, customBootstrap && {
|
|
55
|
+
specifiers: [{
|
|
56
|
+
local: 'customBootstrap'
|
|
57
|
+
}],
|
|
58
|
+
value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
59
|
+
}].filter(Boolean);
|
|
60
|
+
|
|
61
|
+
if (fileSystemRoutes) {
|
|
62
|
+
const route = {
|
|
63
|
+
specifiers: [{
|
|
64
|
+
imported: 'routes'
|
|
65
|
+
}],
|
|
66
|
+
value: (0, _utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (fileSystemRoutes.globalApp) {
|
|
70
|
+
imports.push({
|
|
71
|
+
specifiers: [{
|
|
72
|
+
local: 'App'
|
|
73
|
+
}],
|
|
74
|
+
value: (0, _utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
route.initialize = 'const App = false;';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
imports.push(route);
|
|
81
|
+
} else {
|
|
82
|
+
imports.push({
|
|
83
|
+
specifiers: [{
|
|
84
|
+
local: 'App'
|
|
85
|
+
}],
|
|
86
|
+
value: (0, _utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return imports;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
exports.getDefaultImports = getDefaultImports;
|
|
94
|
+
|
|
95
|
+
const isRouteComponentFile = filePath => {
|
|
96
|
+
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (['.js', '.jsx', '.ts', '.tsx'].includes(_path.default.extname(filePath))) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.isRouteComponentFile = isRouteComponentFile;
|
package/dist/js/node/index.js
CHANGED
|
@@ -15,12 +15,12 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
15
15
|
|
|
16
16
|
var _core = require("@modern-js/core");
|
|
17
17
|
|
|
18
|
-
var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
|
|
19
|
-
|
|
20
18
|
var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
|
|
21
19
|
|
|
22
20
|
var _utils = require("@modern-js/utils");
|
|
23
21
|
|
|
22
|
+
var _analyze = _interopRequireDefault(require("./analyze"));
|
|
23
|
+
|
|
24
24
|
var _hooks = require("./hooks");
|
|
25
25
|
|
|
26
26
|
var _locale = require("./locale");
|
|
@@ -43,7 +43,7 @@ var _default = () => ({
|
|
|
43
43
|
name: '@modern-js/app-tools',
|
|
44
44
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
|
45
45
|
registerHook: _hooks.hooks,
|
|
46
|
-
usePlugins: [(0,
|
|
46
|
+
usePlugins: [(0, _analyze.default)(), (0, _pluginJarvis.default)()],
|
|
47
47
|
setup: api => {
|
|
48
48
|
const locale = (0, _language.getLocaleLanguage)();
|
|
49
49
|
|
|
@@ -128,7 +128,7 @@ var _default = () => ({
|
|
|
128
128
|
},
|
|
129
129
|
|
|
130
130
|
async beforeRestart() {
|
|
131
|
-
(0, _utils.cleanRequireCache)([require.resolve(
|
|
131
|
+
(0, _utils.cleanRequireCache)([require.resolve("./analyze/cli")]);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
};
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getLocaleLanguage = getLocaleLanguage;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _languageDetector = require("@modern-js/plugin-i18n/language-detector");
|
|
9
9
|
|
|
10
10
|
function getLocaleLanguage() {
|
|
11
|
-
const detector = new
|
|
11
|
+
const detector = new _languageDetector.I18CLILanguageDetector();
|
|
12
12
|
return detector.detect();
|
|
13
13
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const JS_EXTENSIONS: string[];
|
|
2
|
+
export declare const INDEX_FILE_NAME = "index";
|
|
3
|
+
export declare const APP_FILE_NAME = "App";
|
|
4
|
+
export declare const PAGES_DIR_NAME = "pages";
|
|
5
|
+
export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
6
|
+
export declare const ENTRY_POINT_FILE_NAME = "index.js";
|
|
7
|
+
export declare const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: RegExp;
|
|
8
|
+
export declare const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
|
|
9
|
+
export declare const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
|
|
10
|
+
export declare const FILE_SYSTEM_ROUTES_INDEX = "index";
|
|
11
|
+
export declare const FILE_SYSTEM_ROUTES_IGNORED_REGEX: RegExp;
|
|
12
|
+
export declare const HTML_PARTIALS_FOLDER = "html";
|
|
13
|
+
export declare const HTML_PARTIALS_EXTENSIONS: string[];
|
|
14
|
+
export declare const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IAppContext, NormalizedConfig, PluginAPI, ImportStatement } from '@modern-js/core';
|
|
2
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
3
|
+
export declare const createImportStatements: (statements: ImportStatement[]) => string;
|
|
4
|
+
export declare const generateCode: (appContext: IAppContext, config: NormalizedConfig, entrypoints: Entrypoint[], api: PluginAPI) => Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Entrypoint, Route } from '@modern-js/types';
|
|
2
|
+
export type { Route };
|
|
3
|
+
export interface Identifier {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const getClientRoutes: ({
|
|
8
|
+
entrypoint,
|
|
9
|
+
srcDirectory,
|
|
10
|
+
srcAlias,
|
|
11
|
+
internalDirectory,
|
|
12
|
+
internalDirAlias
|
|
13
|
+
}: {
|
|
14
|
+
entrypoint: Entrypoint;
|
|
15
|
+
srcDirectory: string;
|
|
16
|
+
srcAlias: string;
|
|
17
|
+
internalDirectory: string;
|
|
18
|
+
internalDirAlias: string;
|
|
19
|
+
}) => Route[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAppContext, NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
2
|
+
import type { Entrypoint, HtmlTemplates } from '@modern-js/types';
|
|
3
|
+
export declare const getHtmlTemplate: (entrypoints: Entrypoint[], api: PluginAPI, {
|
|
4
|
+
appContext,
|
|
5
|
+
config
|
|
6
|
+
}: {
|
|
7
|
+
appContext: IAppContext;
|
|
8
|
+
config: NormalizedConfig;
|
|
9
|
+
}) => Promise<HtmlTemplates>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NormalizedConfig, IAppContext } from '@modern-js/core';
|
|
2
|
+
import type { Entrypoint, ServerRoute } from '@modern-js/types';
|
|
3
|
+
export declare const getServerRoutes: (entrypoints: Entrypoint[], {
|
|
4
|
+
appContext,
|
|
5
|
+
config
|
|
6
|
+
}: {
|
|
7
|
+
appContext: IAppContext;
|
|
8
|
+
config: NormalizedConfig;
|
|
9
|
+
}) => ServerRoute[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CliPlugin, RuntimePlugin, ImportStatement } from '@modern-js/core';
|
|
2
|
+
import type { Route, Entrypoint, ServerRoute, HtmlPartials } from '@modern-js/types';
|
|
3
|
+
export declare const modifyEntryImports: import("@modern-js/plugin").AsyncWaterfall<{
|
|
4
|
+
imports: ImportStatement[];
|
|
5
|
+
entrypoint: Entrypoint;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const modifyEntryExport: import("@modern-js/plugin").AsyncWaterfall<{
|
|
8
|
+
entrypoint: Entrypoint;
|
|
9
|
+
exportStatement: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
12
|
+
export declare const modifyEntryRuntimePlugins: import("@modern-js/plugin").AsyncWaterfall<{
|
|
13
|
+
entrypoint: Entrypoint;
|
|
14
|
+
plugins: RuntimePlugin[];
|
|
15
|
+
}>;
|
|
16
|
+
export declare const modifyEntryRenderFunction: import("@modern-js/plugin").AsyncWaterfall<{
|
|
17
|
+
entrypoint: Entrypoint;
|
|
18
|
+
code: string;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const modifyFileSystemRoutes: import("@modern-js/plugin").AsyncWaterfall<{
|
|
21
|
+
entrypoint: Entrypoint;
|
|
22
|
+
routes: Route[];
|
|
23
|
+
}>;
|
|
24
|
+
export declare const modifyServerRoutes: import("@modern-js/plugin").AsyncWaterfall<{
|
|
25
|
+
routes: ServerRoute[];
|
|
26
|
+
}>;
|
|
27
|
+
export declare const htmlPartials: import("@modern-js/plugin").AsyncWaterfall<{
|
|
28
|
+
entrypoint: Entrypoint;
|
|
29
|
+
partials: HtmlPartials;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const beforeGenerateRoutes: import("@modern-js/plugin").AsyncWaterfall<{
|
|
32
|
+
entrypoint: Entrypoint;
|
|
33
|
+
code: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const addDefineTypes: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
36
|
+
|
|
37
|
+
declare const _default: () => CliPlugin;
|
|
38
|
+
|
|
39
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDefaultExportFunction: (file: string | false) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeLegalIdentifier(str: string): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RuntimePlugin } from '@modern-js/core';
|
|
2
|
+
import type { Entrypoint, Route } from '@modern-js/types';
|
|
3
|
+
export declare const index: ({
|
|
4
|
+
mountId,
|
|
5
|
+
imports,
|
|
6
|
+
renderFunction,
|
|
7
|
+
exportStatement
|
|
8
|
+
}: {
|
|
9
|
+
mountId: string;
|
|
10
|
+
imports: string;
|
|
11
|
+
exportStatement: string;
|
|
12
|
+
renderFunction: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
export declare const renderFunction: ({
|
|
15
|
+
plugins,
|
|
16
|
+
customBootstrap,
|
|
17
|
+
fileSystemRoutes
|
|
18
|
+
}: {
|
|
19
|
+
plugins: RuntimePlugin[];
|
|
20
|
+
customBootstrap?: string | false | undefined;
|
|
21
|
+
fileSystemRoutes: Entrypoint['fileSystemRoutes'];
|
|
22
|
+
}) => string;
|
|
23
|
+
export declare const html: (partials: {
|
|
24
|
+
top: string[];
|
|
25
|
+
head: string[];
|
|
26
|
+
body: string[];
|
|
27
|
+
}) => string;
|
|
28
|
+
export declare const fileSystemRoutes: ({
|
|
29
|
+
routes
|
|
30
|
+
}: {
|
|
31
|
+
routes: Route[];
|
|
32
|
+
}) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
2
|
+
import type { ImportStatement } from '@modern-js/core';
|
|
3
|
+
export declare const walkDirectory: (dir: string) => string[];
|
|
4
|
+
export declare const getDefaultImports: ({
|
|
5
|
+
entrypoint,
|
|
6
|
+
srcDirectory,
|
|
7
|
+
internalSrcAlias,
|
|
8
|
+
internalDirAlias
|
|
9
|
+
}: {
|
|
10
|
+
entrypoint: Entrypoint;
|
|
11
|
+
srcDirectory: string;
|
|
12
|
+
internalSrcAlias: string;
|
|
13
|
+
internalDirAlias: string;
|
|
14
|
+
}) => ImportStatement[];
|
|
15
|
+
export declare const isRouteComponentFile: (filePath: string) => boolean;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.8.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -57,22 +57,24 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@babel/runtime": "^7.18.0",
|
|
60
|
-
"@modern-js/core": "^1.
|
|
61
|
-
"@modern-js/
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@modern-js/
|
|
64
|
-
"@modern-js/plugin": "^1.
|
|
65
|
-
"@modern-js/plugin-
|
|
66
|
-
"@modern-js/
|
|
67
|
-
"@modern-js/
|
|
68
|
-
"@modern-js/
|
|
69
|
-
"@modern-js/
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
60
|
+
"@modern-js/core": "^1.13.1",
|
|
61
|
+
"@modern-js/new-action": "^1.4.0",
|
|
62
|
+
"@modern-js/node-bundle-require": "^1.3.7",
|
|
63
|
+
"@modern-js/plugin": "^1.4.1",
|
|
64
|
+
"@modern-js/plugin-i18n": "^1.3.0",
|
|
65
|
+
"@modern-js/plugin-jarvis": "^1.2.14",
|
|
66
|
+
"@modern-js/prod-server": "^1.2.1",
|
|
67
|
+
"@modern-js/server": "^1.6.0",
|
|
68
|
+
"@modern-js/types": "^1.6.0",
|
|
69
|
+
"@modern-js/utils": "^1.8.0",
|
|
70
|
+
"@modern-js/webpack": "^1.12.2",
|
|
71
|
+
"@babel/parser": "^7.18.0",
|
|
72
|
+
"@babel/traverse": "^7.18.0",
|
|
73
|
+
"@babel/types": "^7.18.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@modern-js/server-core": "1.4.
|
|
76
|
+
"@modern-js/server-core": "1.4.1",
|
|
77
|
+
"@types/babel__traverse": "^7.14.2",
|
|
76
78
|
"@scripts/build": "0.0.0",
|
|
77
79
|
"@scripts/jest-config": "0.0.0",
|
|
78
80
|
"@types/jest": "^27",
|