@modern-js/app-tools 2.63.0 → 2.63.1
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/dist/cjs/commands/dev.js +1 -1
- package/dist/cjs/commands/serve.js +1 -1
- package/dist/cjs/new/compat/hooks.js +11 -4
- package/dist/cjs/new/compat/utils.js +10 -1
- package/dist/cjs/new/context.js +0 -1
- package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
- package/dist/cjs/plugins/analyze/index.js +128 -130
- package/dist/cjs/plugins/deploy/index.js +12 -14
- package/dist/cjs/plugins/initialize/index.js +1 -1
- package/dist/cjs/utils/printInstructions.js +12 -3
- package/dist/cjs/utils/restart.js +2 -1
- package/dist/esm/commands/dev.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/new/compat/hooks.js +27 -17
- package/dist/esm/new/compat/utils.js +10 -1
- package/dist/esm/new/context.js +0 -1
- package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
- package/dist/esm/plugins/analyze/index.js +328 -331
- package/dist/esm/plugins/deploy/index.js +84 -88
- package/dist/esm/plugins/initialize/index.js +1 -1
- package/dist/esm/utils/printInstructions.js +29 -2
- package/dist/esm/utils/restart.js +2 -1
- package/dist/esm-node/commands/dev.js +2 -2
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/new/compat/hooks.js +11 -4
- package/dist/esm-node/new/compat/utils.js +10 -1
- package/dist/esm-node/new/context.js +0 -1
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
- package/dist/esm-node/plugins/analyze/index.js +128 -130
- package/dist/esm-node/plugins/deploy/index.js +12 -14
- package/dist/esm-node/plugins/initialize/index.js +1 -1
- package/dist/esm-node/utils/printInstructions.js +10 -2
- package/dist/esm-node/utils/restart.js +2 -1
- package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
- package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
- package/dist/types/builder/shared/types.d.ts +3 -2
- package/dist/types/config/initialize/index.d.ts +3 -2
- package/dist/types/config/initialize/inits.d.ts +4 -3
- package/dist/types/new/context.d.ts +0 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +2 -3
- package/dist/types/plugins/deploy/index.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
- package/dist/types/plugins/deploy/utils.d.ts +2 -2
- package/dist/types/types/new.d.ts +38 -21
- package/dist/types/utils/printInstructions.d.ts +3 -1
- package/dist/types/utils/routes.d.ts +2 -1
- package/package.json +20 -20
@@ -37,95 +37,91 @@ function deploy_default() {
|
|
37
37
|
name: "@modern-js/plugin-deploy",
|
38
38
|
setup: function(api) {
|
39
39
|
var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
2
|
52
|
-
];
|
53
|
-
}
|
54
|
-
modernConfig = api.useResolvedConfigContext();
|
55
|
-
return [
|
56
|
-
4,
|
57
|
-
getDeployPreset(appContext, modernConfig, deployTarget)
|
58
|
-
];
|
59
|
-
case 1:
|
60
|
-
deployPreset = _state.sent();
|
61
|
-
_tmp = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare;
|
62
|
-
if (!_tmp)
|
63
|
-
return [
|
64
|
-
3,
|
65
|
-
3
|
66
|
-
];
|
67
|
-
return [
|
68
|
-
4,
|
69
|
-
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
|
70
|
-
];
|
71
|
-
case 2:
|
72
|
-
_tmp = _state.sent();
|
73
|
-
_state.label = 3;
|
74
|
-
case 3:
|
75
|
-
_tmp;
|
76
|
-
_tmp1 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput;
|
77
|
-
if (!_tmp1)
|
78
|
-
return [
|
79
|
-
3,
|
80
|
-
5
|
81
|
-
];
|
82
|
-
return [
|
83
|
-
4,
|
84
|
-
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
|
85
|
-
];
|
86
|
-
case 4:
|
87
|
-
_tmp1 = _state.sent();
|
88
|
-
_state.label = 5;
|
89
|
-
case 5:
|
90
|
-
_tmp1;
|
91
|
-
_tmp2 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry;
|
92
|
-
if (!_tmp2)
|
93
|
-
return [
|
94
|
-
3,
|
95
|
-
7
|
96
|
-
];
|
97
|
-
return [
|
98
|
-
4,
|
99
|
-
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
|
100
|
-
];
|
101
|
-
case 6:
|
102
|
-
_tmp2 = _state.sent();
|
103
|
-
_state.label = 7;
|
104
|
-
case 7:
|
105
|
-
_tmp2;
|
106
|
-
_tmp3 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end;
|
107
|
-
if (!_tmp3)
|
108
|
-
return [
|
109
|
-
3,
|
110
|
-
9
|
111
|
-
];
|
112
|
-
return [
|
113
|
-
4,
|
114
|
-
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end()
|
115
|
-
];
|
116
|
-
case 8:
|
117
|
-
_tmp3 = _state.sent();
|
118
|
-
_state.label = 9;
|
119
|
-
case 9:
|
120
|
-
_tmp3;
|
121
|
-
return [
|
122
|
-
2
|
123
|
-
];
|
40
|
+
api.deploy(/* @__PURE__ */ _async_to_generator(function() {
|
41
|
+
var appContext, metaName, modernConfig, deployPreset, _tmp, _tmp1, _tmp2, _tmp3;
|
42
|
+
return _ts_generator(this, function(_state) {
|
43
|
+
switch (_state.label) {
|
44
|
+
case 0:
|
45
|
+
appContext = api.getAppContext();
|
46
|
+
metaName = appContext.metaName;
|
47
|
+
if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
|
48
|
+
return [
|
49
|
+
2
|
50
|
+
];
|
124
51
|
}
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
52
|
+
modernConfig = api.getNormalizedConfig();
|
53
|
+
return [
|
54
|
+
4,
|
55
|
+
getDeployPreset(appContext, modernConfig, deployTarget)
|
56
|
+
];
|
57
|
+
case 1:
|
58
|
+
deployPreset = _state.sent();
|
59
|
+
_tmp = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare;
|
60
|
+
if (!_tmp)
|
61
|
+
return [
|
62
|
+
3,
|
63
|
+
3
|
64
|
+
];
|
65
|
+
return [
|
66
|
+
4,
|
67
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
|
68
|
+
];
|
69
|
+
case 2:
|
70
|
+
_tmp = _state.sent();
|
71
|
+
_state.label = 3;
|
72
|
+
case 3:
|
73
|
+
_tmp;
|
74
|
+
_tmp1 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput;
|
75
|
+
if (!_tmp1)
|
76
|
+
return [
|
77
|
+
3,
|
78
|
+
5
|
79
|
+
];
|
80
|
+
return [
|
81
|
+
4,
|
82
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
|
83
|
+
];
|
84
|
+
case 4:
|
85
|
+
_tmp1 = _state.sent();
|
86
|
+
_state.label = 5;
|
87
|
+
case 5:
|
88
|
+
_tmp1;
|
89
|
+
_tmp2 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry;
|
90
|
+
if (!_tmp2)
|
91
|
+
return [
|
92
|
+
3,
|
93
|
+
7
|
94
|
+
];
|
95
|
+
return [
|
96
|
+
4,
|
97
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
|
98
|
+
];
|
99
|
+
case 6:
|
100
|
+
_tmp2 = _state.sent();
|
101
|
+
_state.label = 7;
|
102
|
+
case 7:
|
103
|
+
_tmp2;
|
104
|
+
_tmp3 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end;
|
105
|
+
if (!_tmp3)
|
106
|
+
return [
|
107
|
+
3,
|
108
|
+
9
|
109
|
+
];
|
110
|
+
return [
|
111
|
+
4,
|
112
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end()
|
113
|
+
];
|
114
|
+
case 8:
|
115
|
+
_tmp3 = _state.sent();
|
116
|
+
_state.label = 9;
|
117
|
+
case 9:
|
118
|
+
_tmp3;
|
119
|
+
return [
|
120
|
+
2
|
121
|
+
];
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}));
|
129
125
|
}
|
130
126
|
};
|
131
127
|
}
|
@@ -41,7 +41,7 @@ function initialize_default(param) {
|
|
41
41
|
port = _state.sent();
|
42
42
|
appContext = _object_spread_props(_object_spread({}, appContext), {
|
43
43
|
port,
|
44
|
-
distDirectory: ensureAbsolutePath(appContext.
|
44
|
+
distDirectory: ensureAbsolutePath(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
45
45
|
});
|
46
46
|
api.updateAppContext(appContext);
|
47
47
|
normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
@@ -2,6 +2,32 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { logger, prettyInstructions } from "@modern-js/utils";
|
4
4
|
var printInstructions = function() {
|
5
|
+
var _ref = _async_to_generator(function(hooks, appContext, config) {
|
6
|
+
var message, instructions;
|
7
|
+
return _ts_generator(this, function(_state) {
|
8
|
+
switch (_state.label) {
|
9
|
+
case 0:
|
10
|
+
message = prettyInstructions(appContext, config);
|
11
|
+
return [
|
12
|
+
4,
|
13
|
+
hooks.onBeforePrintInstructions.call({
|
14
|
+
instructions: message
|
15
|
+
})
|
16
|
+
];
|
17
|
+
case 1:
|
18
|
+
instructions = _state.sent().instructions;
|
19
|
+
logger.log(instructions);
|
20
|
+
return [
|
21
|
+
2
|
22
|
+
];
|
23
|
+
}
|
24
|
+
});
|
25
|
+
});
|
26
|
+
return function printInstructions2(hooks, appContext, config) {
|
27
|
+
return _ref.apply(this, arguments);
|
28
|
+
};
|
29
|
+
}();
|
30
|
+
var printInstructionsCompat = function() {
|
5
31
|
var _ref = _async_to_generator(function(hookRunners, appContext, config) {
|
6
32
|
var message, instructions;
|
7
33
|
return _ts_generator(this, function(_state) {
|
@@ -23,10 +49,11 @@ var printInstructions = function() {
|
|
23
49
|
}
|
24
50
|
});
|
25
51
|
});
|
26
|
-
return function
|
52
|
+
return function printInstructionsCompat2(hookRunners, appContext, config) {
|
27
53
|
return _ref.apply(this, arguments);
|
28
54
|
};
|
29
55
|
}();
|
30
56
|
export {
|
31
|
-
printInstructions
|
57
|
+
printInstructions,
|
58
|
+
printInstructionsCompat
|
32
59
|
};
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { cli } from "@modern-js/plugin-v2/cli";
|
4
|
-
import { chalk, clearConsole, getFullArgv, logger
|
4
|
+
import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
|
5
|
+
import { program } from "@modern-js/utils/commander";
|
5
6
|
function restart(hooksRunner, filename) {
|
6
7
|
return _restart.apply(this, arguments);
|
7
8
|
}
|
@@ -6,7 +6,7 @@ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils"
|
|
6
6
|
import { buildServerConfig } from "../utils/config";
|
7
7
|
import { setServer } from "../utils/createServer";
|
8
8
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
9
|
-
import {
|
9
|
+
import { printInstructionsCompat } from "../utils/printInstructions";
|
10
10
|
import { registerCompiler } from "../utils/register";
|
11
11
|
import { generateRoutes } from "../utils/routes";
|
12
12
|
const dev = async (api, options, devServerOptions) => {
|
@@ -80,7 +80,7 @@ const dev = async (api, options, devServerOptions) => {
|
|
80
80
|
port,
|
81
81
|
host
|
82
82
|
}, () => {
|
83
|
-
|
83
|
+
printInstructionsCompat(hookRunners, appContext, normalizedConfig);
|
84
84
|
});
|
85
85
|
} else {
|
86
86
|
const { server, afterListen } = await createDevServer({
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
2
2
|
import { createProdServer } from "@modern-js/prod-server";
|
3
3
|
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
4
4
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
5
|
-
import {
|
5
|
+
import { printInstructionsCompat } from "../utils/printInstructions";
|
6
6
|
const start = async (api) => {
|
7
7
|
var _userConfig_source, _userConfig_output_distPath;
|
8
8
|
const appContext = api.useAppContext();
|
@@ -44,7 +44,7 @@ const start = async (api) => {
|
|
44
44
|
runMode
|
45
45
|
});
|
46
46
|
app.listen(port, async () => {
|
47
|
-
await
|
47
|
+
await printInstructionsCompat(hookRunners, appContext, userConfig);
|
48
48
|
});
|
49
49
|
};
|
50
50
|
export {
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { getModifyHtmlPartials } from "../../plugins/analyze/getHtmlTemplate";
|
1
2
|
import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
|
2
3
|
function getHookRunners(context) {
|
3
4
|
const { hooks } = context;
|
@@ -56,7 +57,13 @@ function getHookRunners(context) {
|
|
56
57
|
return hooks.modifyResolvedConfig.call(params);
|
57
58
|
},
|
58
59
|
htmlPartials: async (params) => {
|
59
|
-
|
60
|
+
await hooks.modifyHtmlPartials.call({
|
61
|
+
entrypoint: params.entrypoint,
|
62
|
+
partials: getModifyHtmlPartials(params.partials)
|
63
|
+
});
|
64
|
+
return {
|
65
|
+
partials: params.partials
|
66
|
+
};
|
60
67
|
},
|
61
68
|
commands: async (params) => {
|
62
69
|
return hooks.addCommand.call(params);
|
@@ -67,7 +74,7 @@ function getHookRunners(context) {
|
|
67
74
|
prepare: async () => {
|
68
75
|
return hooks.onPrepare.call();
|
69
76
|
},
|
70
|
-
|
77
|
+
fileChange: async (params) => {
|
71
78
|
return hooks.onFileChanged.call(params);
|
72
79
|
},
|
73
80
|
beforeCreateCompiler: async (params) => {
|
@@ -115,8 +122,8 @@ function getHookRunners(context) {
|
|
115
122
|
/**
|
116
123
|
* @deprecated
|
117
124
|
*/
|
118
|
-
addRuntimeExports: async (
|
119
|
-
return hooks.addRuntimeExports.call(
|
125
|
+
addRuntimeExports: async () => {
|
126
|
+
return hooks.addRuntimeExports.call();
|
120
127
|
}
|
121
128
|
};
|
122
129
|
}
|
@@ -16,7 +16,7 @@ function transformHookRunner(hookRunnerName) {
|
|
16
16
|
return "addCommand";
|
17
17
|
case "watchFiles":
|
18
18
|
return "addWatchFiles";
|
19
|
-
case "
|
19
|
+
case "fileChange":
|
20
20
|
return "onFileChanged";
|
21
21
|
case "beforeCreateCompiler":
|
22
22
|
return "onBeforeCreateCompiler";
|
@@ -50,6 +50,15 @@ function transformHookParams(hookRunnerName, params) {
|
|
50
50
|
return {
|
51
51
|
resolved: params
|
52
52
|
};
|
53
|
+
case "htmlPartials":
|
54
|
+
return {
|
55
|
+
partials: {
|
56
|
+
top: params.partials.top.current,
|
57
|
+
head: params.partials.head.current,
|
58
|
+
body: params.partials.body.current
|
59
|
+
},
|
60
|
+
entrypoint: params.entrypoint
|
61
|
+
};
|
53
62
|
default:
|
54
63
|
return params;
|
55
64
|
}
|
@@ -13,7 +13,6 @@ const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfig
|
|
13
13
|
apiDirectory: path.resolve(appDirectory, apiDir),
|
14
14
|
lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
|
15
15
|
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
16
|
-
distDirectory: distDir,
|
17
16
|
serverPlugins: [],
|
18
17
|
internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
|
19
18
|
htmlTemplates: {},
|
@@ -22,10 +22,10 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
|
|
22
22
|
}
|
23
23
|
return false;
|
24
24
|
});
|
25
|
-
const getBundleEntry = async (
|
25
|
+
const getBundleEntry = async (hooks, appContext, config) => {
|
26
26
|
const { appDirectory, packageName } = appContext;
|
27
27
|
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
28
|
-
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(
|
28
|
+
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(hooks, appContext, config);
|
29
29
|
if (entries) {
|
30
30
|
Object.keys(entries).forEach((name) => {
|
31
31
|
const value = entries[name];
|
@@ -6,8 +6,8 @@ import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
|
6
6
|
const hasIndex = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
7
7
|
const hasEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}${ext}`)));
|
8
8
|
const hasServerEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}.server${ext}`)));
|
9
|
-
const isBundleEntry = async (
|
10
|
-
const { entry } = await
|
9
|
+
const isBundleEntry = async (hooks, dir, enableCustomEntry) => {
|
10
|
+
const { entry } = await hooks.checkEntryPoint.call({
|
11
11
|
path: dir,
|
12
12
|
entry: false
|
13
13
|
});
|
@@ -20,7 +20,7 @@ const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
|
|
20
20
|
}
|
21
21
|
return hasIndex(dir);
|
22
22
|
};
|
23
|
-
const scanDir = async (
|
23
|
+
const scanDir = async (hooks, dirs, enableCustomEntry) => {
|
24
24
|
const entries = await Promise.all(dirs.map(async (dir) => {
|
25
25
|
const indexFile = hasIndex(dir);
|
26
26
|
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
@@ -37,7 +37,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
37
37
|
customBootstrap
|
38
38
|
};
|
39
39
|
}
|
40
|
-
const entryFile = (await
|
40
|
+
const entryFile = (await hooks.checkEntryPoint.call({
|
41
41
|
path: dir,
|
42
42
|
entry: false
|
43
43
|
})).entry;
|
@@ -71,7 +71,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
|
71
71
|
}
|
72
72
|
return entries;
|
73
73
|
};
|
74
|
-
const getFileSystemEntry = async (
|
74
|
+
const getFileSystemEntry = async (hooks, appContext, config) => {
|
75
75
|
const { appDirectory } = appContext;
|
76
76
|
const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
|
77
77
|
let disabledDirs = [];
|
@@ -81,19 +81,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
|
81
81
|
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
82
82
|
if (fs.existsSync(src)) {
|
83
83
|
if (fs.statSync(src).isDirectory()) {
|
84
|
-
if (await isBundleEntry(
|
85
|
-
return scanDir(
|
84
|
+
if (await isBundleEntry(hooks, src, enableCustomEntry)) {
|
85
|
+
return scanDir(hooks, [
|
86
86
|
src
|
87
87
|
], enableCustomEntry);
|
88
88
|
}
|
89
89
|
const dirs = [];
|
90
90
|
await Promise.all(fs.readdirSync(src).map(async (filename) => {
|
91
91
|
const file = path.join(src, filename);
|
92
|
-
if (fs.statSync(file).isDirectory() && await isBundleEntry(
|
92
|
+
if (fs.statSync(file).isDirectory() && await isBundleEntry(hooks, file, enableCustomEntry) && !disabledDirs.includes(file)) {
|
93
93
|
dirs.push(file);
|
94
94
|
}
|
95
95
|
}));
|
96
|
-
return scanDir(
|
96
|
+
return scanDir(hooks, dirs, enableCustomEntry);
|
97
97
|
} else {
|
98
98
|
throw Error(`source.entriesDir accept a directory.`);
|
99
99
|
}
|
@@ -21,7 +21,36 @@ const findPartials = (dir, entryName, position) => {
|
|
21
21
|
}
|
22
22
|
return null;
|
23
23
|
};
|
24
|
-
const
|
24
|
+
const getModifyHtmlPartials = (partials) => {
|
25
|
+
const append = (type, ...script) => {
|
26
|
+
script.forEach((item) => {
|
27
|
+
partials[type].push(item);
|
28
|
+
});
|
29
|
+
};
|
30
|
+
const prepend = (type, ...script) => {
|
31
|
+
script.forEach((item) => {
|
32
|
+
partials[type].unshift(item);
|
33
|
+
});
|
34
|
+
};
|
35
|
+
return {
|
36
|
+
top: {
|
37
|
+
append: (...script) => append("top", ...script),
|
38
|
+
prepend: (...script) => prepend("top", ...script),
|
39
|
+
current: partials.top
|
40
|
+
},
|
41
|
+
head: {
|
42
|
+
append: (...script) => append("head", ...script),
|
43
|
+
prepend: (...script) => prepend("head", ...script),
|
44
|
+
current: partials.head
|
45
|
+
},
|
46
|
+
body: {
|
47
|
+
append: (...script) => append("body", ...script),
|
48
|
+
prepend: (...script) => prepend("body", ...script),
|
49
|
+
current: partials.body
|
50
|
+
}
|
51
|
+
};
|
52
|
+
};
|
53
|
+
const getHtmlTemplate = async (entrypoints, hooks, { appContext, config }) => {
|
25
54
|
const { appDirectory, internalDirectory } = appContext;
|
26
55
|
const { source: { configDir } } = config;
|
27
56
|
const htmlDir = path.resolve(appDirectory, configDir || "", HTML_PARTIALS_FOLDER);
|
@@ -34,24 +63,20 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
34
63
|
if (customIndexTemplate) {
|
35
64
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
36
65
|
} else {
|
37
|
-
const
|
38
|
-
|
66
|
+
const getPartialInitValue = (position) => {
|
67
|
+
const partial = findPartials(htmlDir, name, position);
|
68
|
+
return partial ? [
|
69
|
+
partial.content
|
70
|
+
] : [];
|
71
|
+
};
|
72
|
+
const partials = {
|
73
|
+
top: getPartialInitValue("top"),
|
74
|
+
head: getPartialInitValue("head"),
|
75
|
+
body: getPartialInitValue("body")
|
76
|
+
};
|
77
|
+
await hooks.modifyHtmlPartials.call({
|
39
78
|
entrypoint,
|
40
|
-
partials:
|
41
|
-
"top",
|
42
|
-
"head",
|
43
|
-
"body"
|
44
|
-
].reduce((previous, position) => {
|
45
|
-
const found = findPartials(htmlDir, name, position);
|
46
|
-
previous[position] = found ? [
|
47
|
-
found.content
|
48
|
-
] : [];
|
49
|
-
return previous;
|
50
|
-
}, {
|
51
|
-
top: [],
|
52
|
-
head: [],
|
53
|
-
body: []
|
54
|
-
})
|
79
|
+
partials: getModifyHtmlPartials(partials)
|
55
80
|
});
|
56
81
|
const templatePath = path.resolve(internalDirectory, entryName, "index.html");
|
57
82
|
fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
@@ -63,12 +88,12 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
63
88
|
}
|
64
89
|
}
|
65
90
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
return htmlTemplates;
|
91
|
+
return {
|
92
|
+
partialsByEntrypoint,
|
93
|
+
htmlTemplates
|
94
|
+
};
|
71
95
|
};
|
72
96
|
export {
|
73
|
-
getHtmlTemplate
|
97
|
+
getHtmlTemplate,
|
98
|
+
getModifyHtmlPartials
|
74
99
|
};
|