lwr 0.11.4 → 0.12.0-alpha.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.
|
@@ -36,7 +36,7 @@ var import_tools = __toModule(require("@lwrjs/tools"));
|
|
|
36
36
|
var RUNTIME_CONFIG_SRC_DIR = "config";
|
|
37
37
|
function createBuildCommand() {
|
|
38
38
|
return new import_commander.Command("build").description("Build an LWR application").addOption((0, import_utils.getTargetOption)()).addOption((0, import_utils.getModeOption)().choices(["prod", "prod-compat"])).option("-o, --output <directory>", `[string] output directory`).option("--clean", `[boolean] delete the output directory`, false).option("-r, --routes <routes...>", `routes`).option("-m, --modules <modules...>", `modules`).option("-l, --locales <locales...>", `locales`).option("--minify", "[boolean] minifies build output", false).action(async (options, cmd) => {
|
|
39
|
-
import_diagnostics.logger.info(
|
|
39
|
+
import_diagnostics.logger.info({label: `build`, message: `Building lwr application`});
|
|
40
40
|
const {
|
|
41
41
|
rootDir,
|
|
42
42
|
config,
|
|
@@ -58,11 +58,14 @@ function createBuildCommand() {
|
|
|
58
58
|
ssrFunctionNodeVersion = getSuggestedNodeVersion();
|
|
59
59
|
}
|
|
60
60
|
if (clean) {
|
|
61
|
-
import_diagnostics.logger.info(`
|
|
61
|
+
import_diagnostics.logger.info({label: `build`, message: `Clearing output directory: ${outputDir}`});
|
|
62
62
|
import_fs_extra.default.rmSync(outputDir, {recursive: true, force: true});
|
|
63
63
|
} else {
|
|
64
64
|
if (import_fs_extra.default.existsSync(`${outputDir}`)) {
|
|
65
|
-
import_diagnostics.logger.warn(
|
|
65
|
+
import_diagnostics.logger.warn({
|
|
66
|
+
label: `build`,
|
|
67
|
+
message: `Output directory already exists. Previously generated files will not be deleted. If you did not intend to do this, re-run with --clean true`
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
const generatedSitePath = target === "mrt" ? import_path.default.join(outputDir, "site") : outputDir;
|
|
@@ -101,7 +104,7 @@ function createBuildCommand() {
|
|
|
101
104
|
const rootDir2 = config2.rootDir;
|
|
102
105
|
try {
|
|
103
106
|
process.env.SSR_STATIC_BUNDLES = "true";
|
|
104
|
-
import_diagnostics.logger.info(
|
|
107
|
+
import_diagnostics.logger.info({label: `build`, message: `Generating ssr.js`});
|
|
105
108
|
const {buildServer} = await Promise.resolve().then(() => __toModule(require("@lwrjs/tools")));
|
|
106
109
|
const castMinify = minify == "false" ? false : !!minify;
|
|
107
110
|
await buildServer({rootDir: rootDir2, serverMode: mode, staticSiteGenerator: {outputDir: "site"}}, {outputDir, minify: castMinify});
|
|
@@ -116,7 +119,7 @@ function createBuildCommand() {
|
|
|
116
119
|
name: packageJson.name ? packageJson.name : "lwr-app",
|
|
117
120
|
version: packageJson.version ? packageJson.version : "1.0.0"
|
|
118
121
|
}, null, 4));
|
|
119
|
-
import_diagnostics.logger.info(
|
|
122
|
+
import_diagnostics.logger.info({label: `build`, message: `copying source files`});
|
|
120
123
|
const contentDir = config2.contentDir;
|
|
121
124
|
if (import_fs_extra.default.existsSync(contentDir)) {
|
|
122
125
|
const relPath = contentDir.substring(rootDir2.length);
|
|
@@ -141,13 +144,16 @@ function createBuildCommand() {
|
|
|
141
144
|
} catch (e) {
|
|
142
145
|
import_diagnostics.logger.error(e);
|
|
143
146
|
}
|
|
144
|
-
import_diagnostics.logger.info(
|
|
147
|
+
import_diagnostics.logger.info({label: `build`, message: `generating default.json`});
|
|
145
148
|
try {
|
|
146
149
|
const configFile = import_path.default.join(rootDir2, RUNTIME_CONFIG_SRC_DIR, "default.json");
|
|
147
150
|
const outputConfigFile = import_path.default.join(outputDir, RUNTIME_CONFIG_SRC_DIR, "default.json");
|
|
148
151
|
import_fs_extra.default.ensureDirSync(import_path.default.join(outputDir, RUNTIME_CONFIG_SRC_DIR));
|
|
149
152
|
if (import_fs_extra.default.existsSync(configFile)) {
|
|
150
|
-
import_diagnostics.logger.warn(
|
|
153
|
+
import_diagnostics.logger.warn({
|
|
154
|
+
label: `build`,
|
|
155
|
+
message: `You have a config file already defined, using that rather than generating one.`
|
|
156
|
+
});
|
|
151
157
|
import_fs_extra.default.copyFileSync(configFile, outputConfigFile);
|
|
152
158
|
} else {
|
|
153
159
|
const defaultConfigContent = {
|
|
@@ -172,7 +178,7 @@ function createBuildCommand() {
|
|
|
172
178
|
} catch (e) {
|
|
173
179
|
import_diagnostics.logger.error(e);
|
|
174
180
|
}
|
|
175
|
-
import_diagnostics.logger.info(
|
|
181
|
+
import_diagnostics.logger.info({label: `build`, message: `complete`});
|
|
176
182
|
}
|
|
177
183
|
});
|
|
178
184
|
}
|
|
@@ -191,7 +197,7 @@ function stageProxyConfig(rootDir, outputDir) {
|
|
|
191
197
|
const configFile = import_path.default.join(rootDir, RUNTIME_CONFIG_SRC_DIR, "_proxy");
|
|
192
198
|
const outputConfigFile = import_path.default.join(outputDir, RUNTIME_CONFIG_SRC_DIR, "_proxy");
|
|
193
199
|
if (import_fs_extra.default.existsSync(configFile)) {
|
|
194
|
-
import_diagnostics.logger.info(
|
|
200
|
+
import_diagnostics.logger.info({label: `build`, message: `staging proxy configuration`});
|
|
195
201
|
import_fs_extra.default.ensureDirSync(import_path.default.join(outputDir, RUNTIME_CONFIG_SRC_DIR));
|
|
196
202
|
import_fs_extra.default.copyFileSync(configFile, outputConfigFile);
|
|
197
203
|
}
|
|
@@ -36,7 +36,7 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
|
36
36
|
var import_utils = __toModule(require("../utils.cjs"));
|
|
37
37
|
var import_dev_proxy_server = __toModule(require("@lwrjs/dev-proxy-server"));
|
|
38
38
|
function createPreviewCommand() {
|
|
39
|
-
return new import_commander.Command("preview").aliases(["start"]).description("Preview your built server on the specified target environment").addOption((0, import_utils.getPortOption)()).addOption((0, import_utils.getModeOption)()).addOption((0, import_utils.getTargetOption)()).option("-b, --buildDir <string>", "[string] The prebuilt directory for your site").option("-o, --open", `[boolean] open browser on startup`, false).action(async (
|
|
39
|
+
return new import_commander.Command("preview").aliases(["start"]).description("Preview your built server on the specified target environment").addOption((0, import_utils.getPortOption)()).addOption((0, import_utils.getModeOption)()).addOption((0, import_utils.getTargetOption)()).option("-b, --buildDir <string>", "[string] The prebuilt directory for your site").option("-o, --open", `[boolean] open browser on startup`, false).action(async (_options, cmd) => {
|
|
40
40
|
try {
|
|
41
41
|
const {rootDir, config, port, target, mode, buildDir, open, logLevel} = cmd.optsWithGlobals();
|
|
42
42
|
process.env.LWR_LOG_LEVEL = logLevel;
|
|
@@ -84,7 +84,10 @@ function createPreviewCommand() {
|
|
|
84
84
|
});
|
|
85
85
|
const internalServer = server.getInternalServer();
|
|
86
86
|
if (import_fs_extra.default.existsSync(dir)) {
|
|
87
|
-
import_diagnostics.logger.info(
|
|
87
|
+
import_diagnostics.logger.info({
|
|
88
|
+
label: `cli`,
|
|
89
|
+
message: `Using prebuilt content from directory: ${dir}`
|
|
90
|
+
});
|
|
88
91
|
internalServer.use(import_express.default.static(dir));
|
|
89
92
|
}
|
|
90
93
|
await server.listen(async ({serverMode: serverMode2, port: appPort}) => {
|
|
@@ -18,7 +18,7 @@ export function createBuildCommand() {
|
|
|
18
18
|
.option('-l, --locales <locales...>', `locales`)
|
|
19
19
|
.option('--minify', '[boolean] minifies build output', false)
|
|
20
20
|
.action(async (options, cmd) => {
|
|
21
|
-
logger.info(
|
|
21
|
+
logger.info({ label: `build`, message: `Building lwr application` });
|
|
22
22
|
const { rootDir, config, output, mode, clean, target, minify, routes, modules, locales, logLevel, } = cmd.optsWithGlobals();
|
|
23
23
|
process.env.LWR_LOG_LEVEL = logLevel; // Set the log level
|
|
24
24
|
const outputDir = output ? output : getDefaultBuildDirectory(rootDir, config, target);
|
|
@@ -29,12 +29,15 @@ export function createBuildCommand() {
|
|
|
29
29
|
ssrFunctionNodeVersion = getSuggestedNodeVersion();
|
|
30
30
|
}
|
|
31
31
|
if (clean) {
|
|
32
|
-
logger.info(`
|
|
32
|
+
logger.info({ label: `build`, message: `Clearing output directory: ${outputDir}` });
|
|
33
33
|
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
if (fs.existsSync(`${outputDir}`)) {
|
|
37
|
-
logger.warn(
|
|
37
|
+
logger.warn({
|
|
38
|
+
label: `build`,
|
|
39
|
+
message: `Output directory already exists. Previously generated files will not be deleted. If you did not intend to do this, re-run with --clean true`,
|
|
40
|
+
});
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
const generatedSitePath = target === 'mrt' ? path.join(outputDir, 'site') : outputDir;
|
|
@@ -82,7 +85,7 @@ export function createBuildCommand() {
|
|
|
82
85
|
try {
|
|
83
86
|
// copy over source files we need on the server
|
|
84
87
|
process.env.SSR_STATIC_BUNDLES = 'true';
|
|
85
|
-
logger.info(
|
|
88
|
+
logger.info({ label: `build`, message: `Generating ssr.js` });
|
|
86
89
|
const { buildServer } = await import('@lwrjs/tools');
|
|
87
90
|
// Catch minify flag is the literal 'false'
|
|
88
91
|
const castMinify = minify == 'false' ? false : !!minify;
|
|
@@ -107,7 +110,7 @@ export function createBuildCommand() {
|
|
|
107
110
|
version: packageJson.version ? packageJson.version : '1.0.0',
|
|
108
111
|
}, null, 4));
|
|
109
112
|
// Copy needed source files
|
|
110
|
-
logger.info(
|
|
113
|
+
logger.info({ label: `build`, message: `copying source files` });
|
|
111
114
|
// Content
|
|
112
115
|
const contentDir = config.contentDir;
|
|
113
116
|
if (fs.existsSync(contentDir)) {
|
|
@@ -137,7 +140,7 @@ export function createBuildCommand() {
|
|
|
137
140
|
logger.error(e);
|
|
138
141
|
}
|
|
139
142
|
// generate config/default.js/json
|
|
140
|
-
logger.info(
|
|
143
|
+
logger.info({ label: `build`, message: `generating default.json` });
|
|
141
144
|
try {
|
|
142
145
|
// TODO we could add some kind of merging later, but I think its too complex and not really worth it
|
|
143
146
|
const configFile = path.join(rootDir, RUNTIME_CONFIG_SRC_DIR, 'default.json');
|
|
@@ -145,7 +148,10 @@ export function createBuildCommand() {
|
|
|
145
148
|
fs.ensureDirSync(path.join(outputDir, RUNTIME_CONFIG_SRC_DIR));
|
|
146
149
|
if (fs.existsSync(configFile)) {
|
|
147
150
|
// If they have defined their own config, use that, but display a warning
|
|
148
|
-
logger.warn(
|
|
151
|
+
logger.warn({
|
|
152
|
+
label: `build`,
|
|
153
|
+
message: `You have a config file already defined, using that rather than generating one.`,
|
|
154
|
+
});
|
|
149
155
|
fs.copyFileSync(configFile, outputConfigFile);
|
|
150
156
|
}
|
|
151
157
|
else {
|
|
@@ -185,7 +191,7 @@ export function createBuildCommand() {
|
|
|
185
191
|
catch (e) {
|
|
186
192
|
logger.error(e);
|
|
187
193
|
}
|
|
188
|
-
logger.info(
|
|
194
|
+
logger.info({ label: `build`, message: `complete` });
|
|
189
195
|
}
|
|
190
196
|
});
|
|
191
197
|
}
|
|
@@ -205,7 +211,7 @@ function stageProxyConfig(rootDir, outputDir) {
|
|
|
205
211
|
const configFile = path.join(rootDir, RUNTIME_CONFIG_SRC_DIR, '_proxy');
|
|
206
212
|
const outputConfigFile = path.join(outputDir, RUNTIME_CONFIG_SRC_DIR, '_proxy');
|
|
207
213
|
if (fs.existsSync(configFile)) {
|
|
208
|
-
logger.info(
|
|
214
|
+
logger.info({ label: `build`, message: `staging proxy configuration` });
|
|
209
215
|
fs.ensureDirSync(path.join(outputDir, RUNTIME_CONFIG_SRC_DIR));
|
|
210
216
|
fs.copyFileSync(configFile, outputConfigFile);
|
|
211
217
|
}
|
|
@@ -16,7 +16,7 @@ export function createPreviewCommand() {
|
|
|
16
16
|
.addOption(getTargetOption())
|
|
17
17
|
.option('-b, --buildDir <string>', '[string] The prebuilt directory for your site')
|
|
18
18
|
.option('-o, --open', `[boolean] open browser on startup`, false)
|
|
19
|
-
.action(async (
|
|
19
|
+
.action(async (_options, cmd) => {
|
|
20
20
|
try {
|
|
21
21
|
const { rootDir, config, port, target, mode, buildDir, open, logLevel } = cmd.optsWithGlobals();
|
|
22
22
|
process.env.LWR_LOG_LEVEL = logLevel; // Set the log level
|
|
@@ -81,7 +81,10 @@ export function createPreviewCommand() {
|
|
|
81
81
|
// TODO we could just run a static server vs running LWR services here
|
|
82
82
|
if (fs.existsSync(dir)) {
|
|
83
83
|
// Use static directory if it exists
|
|
84
|
-
logger.info(
|
|
84
|
+
logger.info({
|
|
85
|
+
label: `cli`,
|
|
86
|
+
message: `Using prebuilt content from directory: ${dir}`,
|
|
87
|
+
});
|
|
85
88
|
internalServer.use(express.static(dir));
|
|
86
89
|
}
|
|
87
90
|
await server.listen(async ({ serverMode, port: appPort }) => {
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"types": "build/es/index.d.ts",
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.12.0-alpha.0",
|
|
22
22
|
"module": "build/es/index.js",
|
|
23
23
|
"main": "build/cjs/index.cjs",
|
|
24
24
|
"files": [
|
|
@@ -41,22 +41,22 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@lwrjs/config": "0.
|
|
45
|
-
"@lwrjs/core": "0.
|
|
46
|
-
"@lwrjs/dev-proxy-server": "0.
|
|
47
|
-
"@lwrjs/diagnostics": "0.
|
|
48
|
-
"@lwrjs/shared-utils": "0.
|
|
49
|
-
"@lwrjs/tools": "0.
|
|
44
|
+
"@lwrjs/config": "0.12.0-alpha.0",
|
|
45
|
+
"@lwrjs/core": "0.12.0-alpha.0",
|
|
46
|
+
"@lwrjs/dev-proxy-server": "0.12.0-alpha.0",
|
|
47
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.0",
|
|
48
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.0",
|
|
49
|
+
"@lwrjs/tools": "0.12.0-alpha.0",
|
|
50
50
|
"chalk": "^4.1.0",
|
|
51
51
|
"commander": "^10.0.0",
|
|
52
52
|
"fs-extra": "^11.1.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@commander-js/extra-typings": "^10.0.2",
|
|
56
|
-
"@lwrjs/types": "0.
|
|
56
|
+
"@lwrjs/types": "0.12.0-alpha.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=16.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e79862bc238ededc3cf61f0d2c7d8120d1105a6b"
|
|
62
62
|
}
|