lowdefy 4.0.0-alpha.24 → 4.0.0-alpha.27
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/commands/dev/runDevServer.js +5 -1
- package/dist/commands/start/runStart.js +6 -4
- package/dist/commands/start/start.js +3 -2
- package/dist/index.js +10 -29
- package/dist/program.js +63 -0
- package/dist/utils/createPrint.js +60 -22
- package/dist/utils/createStdOutLineHandler.js +26 -0
- package/dist/utils/errorHandler.js +3 -1
- package/dist/utils/installServer.js +2 -3
- package/dist/utils/runLowdefyBuild.js +8 -5
- package/dist/utils/runNextBuild.js +16 -4
- package/dist/utils/startUp.js +4 -2
- package/package.json +5 -6
- package/dist/utils/BatchChanges.js +0 -61
|
@@ -13,20 +13,24 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
16
17
|
async function runDevServer({ context , directory }) {
|
|
17
18
|
await spawnProcess({
|
|
18
|
-
logger: context.print,
|
|
19
19
|
args: [
|
|
20
20
|
'run',
|
|
21
21
|
'start'
|
|
22
22
|
],
|
|
23
23
|
command: context.packageManagerCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
24
27
|
processOptions: {
|
|
25
28
|
cwd: directory,
|
|
26
29
|
env: {
|
|
27
30
|
...process.env,
|
|
28
31
|
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
29
32
|
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
33
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
30
34
|
LOWDEFY_PACKAGE_MANAGER: context.packageManager,
|
|
31
35
|
LOWDEFY_SERVER_DEV_OPEN_BROWSER: !!context.options.open,
|
|
32
36
|
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
@@ -13,23 +13,25 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
16
17
|
async function runStart({ context , directory }) {
|
|
17
|
-
context.print.spin(`Running "${context.packageManager} run start".`);
|
|
18
18
|
await spawnProcess({
|
|
19
|
-
logger: context.print,
|
|
20
19
|
args: [
|
|
21
20
|
'run',
|
|
22
21
|
'start'
|
|
23
22
|
],
|
|
24
23
|
command: context.packageManagerCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
25
27
|
processOptions: {
|
|
26
28
|
cwd: directory,
|
|
27
29
|
env: {
|
|
28
30
|
...process.env,
|
|
31
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
29
32
|
PORT: context.options.port
|
|
30
33
|
}
|
|
31
|
-
}
|
|
32
|
-
silent: false
|
|
34
|
+
}
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
export default runStart;
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
import readDotEnv from '../../utils/readDotEnv.js';
|
|
17
17
|
// TODO: Handle "spawn yarn ENOENT" error if no built server exists.
|
|
18
18
|
async function build({ context }) {
|
|
19
|
-
context.print.info('Starting server.');
|
|
20
19
|
context.sendTelemetry({
|
|
21
20
|
sendTypes: true
|
|
22
21
|
});
|
|
23
22
|
readDotEnv(context);
|
|
24
|
-
|
|
23
|
+
const serverProcess = runStart({
|
|
25
24
|
context,
|
|
26
25
|
directory: context.directories.server
|
|
27
26
|
});
|
|
27
|
+
context.print.succeed('Started server.');
|
|
28
|
+
await serverProcess;
|
|
28
29
|
}
|
|
29
30
|
export default build;
|
package/dist/index.js
CHANGED
|
@@ -13,32 +13,13 @@
|
|
|
13
13
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
|
15
15
|
limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const program = new Command();
|
|
27
|
-
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
28
|
-
program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--no-next-build', 'Do not build the Next.js server.').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
29
|
-
cliVersion,
|
|
30
|
-
handler: build
|
|
31
|
-
}));
|
|
32
|
-
program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--no-open', 'Do not open a new tab in the default browser.').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').option('--watch <paths...>', 'A list of paths to files or directories that should be watched for changes. Globs are supported. Specify each path to watch separated by spaces.').option('--watch-ignore <paths...>', 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported. Specify each path to watch separated by spaces.').option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').action(runCommand({
|
|
33
|
-
cliVersion,
|
|
34
|
-
handler: dev
|
|
35
|
-
}));
|
|
36
|
-
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
37
|
-
cliVersion,
|
|
38
|
-
handler: init
|
|
39
|
-
}));
|
|
40
|
-
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--port <port>', 'Change the port the server is hosted at. Default is 3000.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
41
|
-
cliVersion,
|
|
42
|
-
handler: start
|
|
43
|
-
}));
|
|
44
|
-
program.parse(process.argv);
|
|
16
|
+
*/ const nodeMajorVersion = process.version.split(/^v(\d+)/)[1];
|
|
17
|
+
if (Number(nodeMajorVersion) < 14) {
|
|
18
|
+
// TODO: This error handled with telemetry.
|
|
19
|
+
throw new Error(`Nodejs versions below v14 are not supported. You are using ${process.version}. Update Nodejs to the latest LTS version to use Lowdefy.`);
|
|
20
|
+
}
|
|
21
|
+
async function run() {
|
|
22
|
+
const { default: program } = await import('./program.js');
|
|
23
|
+
program.parse(process.argv);
|
|
24
|
+
}
|
|
25
|
+
run().then(()=>{});
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { createRequire } from 'module';
|
|
16
|
+
import { Command, Option } from 'commander';
|
|
17
|
+
import build from './commands/build/build.js';
|
|
18
|
+
import dev from './commands/dev/dev.js';
|
|
19
|
+
import init from './commands/init/init.js';
|
|
20
|
+
import start from './commands/start/start.js';
|
|
21
|
+
import runCommand from './utils/runCommand.js';
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const packageJson = require('../package.json');
|
|
24
|
+
const { description , version: cliVersion } = packageJson;
|
|
25
|
+
const program = new Command();
|
|
26
|
+
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
27
|
+
const options = {
|
|
28
|
+
configDirectory: new Option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').env('LOWDEFY_DIRECTORY_CONFIG'),
|
|
29
|
+
devDirectory: new Option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').env('LOWDEFY_DIRECTORY_DEV'),
|
|
30
|
+
disableTelemetry: new Option('--disable-telemetry', 'Disable telemetry.').env('LOWDEFY_DISABLE_TELEMETRY'),
|
|
31
|
+
logLevel: new Option('--log-level <level>', 'The minimum severity of logs to show in the CLI output.').choices([
|
|
32
|
+
'error',
|
|
33
|
+
'warn',
|
|
34
|
+
'info',
|
|
35
|
+
'debug'
|
|
36
|
+
]).default('info').env('LOWDEFY_LOG_LEVEL'),
|
|
37
|
+
packageManager: new Option('--package-manager <package-manager>', 'The package manager to use.').env('LOWDEFY_PACKAGE_MANAGER').choices([
|
|
38
|
+
'npm',
|
|
39
|
+
'yarn'
|
|
40
|
+
]),
|
|
41
|
+
port: new Option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').env('PORT'),
|
|
42
|
+
refResolver: new Option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'),
|
|
43
|
+
serverDirectory: new Option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').env('LOWDEFY_DIRECTORY_SERVER'),
|
|
44
|
+
watch: new Option('--watch <paths...>', 'A list of paths to files or directories that should be watched for changes. Globs are supported. Specify each path to watch separated by spaces.'),
|
|
45
|
+
watchIgnore: new Option('--watch-ignore <paths...>', 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported. Specify each path to watch separated by spaces.')
|
|
46
|
+
};
|
|
47
|
+
program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).option('--no-next-build', 'Do not build the Next.js server.').addOption(options.packageManager).addOption(options.refResolver).addOption(options.serverDirectory).action(runCommand({
|
|
48
|
+
cliVersion,
|
|
49
|
+
handler: build
|
|
50
|
+
}));
|
|
51
|
+
program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).addOption(options.configDirectory).addOption(options.devDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).option('--no-open', 'Do not open a new tab in the default browser.').addOption(options.packageManager).addOption(options.port).addOption(options.refResolver).addOption(options.watch).addOption(options.watchIgnore).action(runCommand({
|
|
52
|
+
cliVersion,
|
|
53
|
+
handler: dev
|
|
54
|
+
}));
|
|
55
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
56
|
+
cliVersion,
|
|
57
|
+
handler: init
|
|
58
|
+
}));
|
|
59
|
+
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).addOption(options.packageManager).addOption(options.port).addOption(options.serverDirectory).action(runCommand({
|
|
60
|
+
cliVersion,
|
|
61
|
+
handler: start
|
|
62
|
+
}));
|
|
63
|
+
export default program;
|
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import ora from 'ora';
|
|
16
|
-
|
|
16
|
+
const reset = '\x1b[0m';
|
|
17
|
+
const red = (text)=>`\x1b[31m${text}${reset}`;
|
|
18
|
+
const green = (text)=>`\x1b[32m${text}${reset}`;
|
|
19
|
+
const yellow = (text)=>`\x1b[33m${text}${reset}`;
|
|
20
|
+
const blue = (text)=>`\x1b[34m${text}${reset}`;
|
|
21
|
+
const dim = (text)=>`\x1b[2m${text}${reset}`;
|
|
17
22
|
function getTime() {
|
|
18
23
|
const time = new Date(Date.now());
|
|
19
24
|
const h = time.getHours();
|
|
@@ -21,46 +26,79 @@ function getTime() {
|
|
|
21
26
|
const s = time.getSeconds();
|
|
22
27
|
return `${h > 9 ? '' : '0'}${h}:${m > 9 ? '' : '0'}${m}:${s > 9 ? '' : '0'}${s}`;
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
// Same levels as pino with added custom levels
|
|
30
|
+
const logLevelValues = {
|
|
31
|
+
error: 50,
|
|
32
|
+
warn: 40,
|
|
33
|
+
succeed: 33,
|
|
34
|
+
spin: 32,
|
|
35
|
+
log: 31,
|
|
36
|
+
info: 30,
|
|
37
|
+
debug: 20
|
|
38
|
+
};
|
|
39
|
+
function filterLevels(logger, level) {
|
|
40
|
+
const levelValue = logLevelValues[level];
|
|
41
|
+
Object.keys(logger).forEach((key)=>{
|
|
42
|
+
if (logLevelValues[key] < levelValue) {
|
|
43
|
+
logger[key] = ()=>{};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return logger;
|
|
47
|
+
}
|
|
48
|
+
function createOraPrint({ logLevel }) {
|
|
25
49
|
const spinner = ora({
|
|
26
50
|
spinner: 'random',
|
|
27
|
-
prefixText: ()=>
|
|
51
|
+
prefixText: ()=>dim(getTime()),
|
|
28
52
|
color: 'blue'
|
|
29
53
|
});
|
|
30
|
-
return {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
return filterLevels({
|
|
55
|
+
error: (text)=>spinner.fail(red(text)),
|
|
56
|
+
info: (text)=>spinner.info(blue(text)),
|
|
57
|
+
log: (text)=>spinner.stopAndPersist({
|
|
58
|
+
symbol: '∙',
|
|
59
|
+
text
|
|
36
60
|
}),
|
|
37
61
|
spin: (text)=>spinner.start(text),
|
|
38
|
-
succeed: (text)=>spinner.succeed(
|
|
39
|
-
warn: (text)=>spinner.warn(
|
|
40
|
-
|
|
62
|
+
succeed: (text)=>spinner.succeed(green(text)),
|
|
63
|
+
warn: (text)=>spinner.warn(yellow(text)),
|
|
64
|
+
debug: (text)=>{
|
|
65
|
+
if (spinner.isSpinning) {
|
|
66
|
+
spinner.stopAndPersist({
|
|
67
|
+
symbol: '∙'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
spinner.stopAndPersist({
|
|
71
|
+
symbol: dim('+'),
|
|
72
|
+
text: dim(text)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, logLevel);
|
|
41
76
|
}
|
|
42
|
-
function createBasicPrint() {
|
|
43
|
-
const { error , info , log , warn } = console;
|
|
44
|
-
return {
|
|
45
|
-
type: 'basic',
|
|
77
|
+
function createBasicPrint({ logLevel ='info' }) {
|
|
78
|
+
const { error , info , log , warn , debug } = console;
|
|
79
|
+
return filterLevels({
|
|
46
80
|
error,
|
|
47
81
|
info,
|
|
48
82
|
log,
|
|
49
83
|
spin: log,
|
|
50
84
|
succeed: log,
|
|
51
|
-
warn
|
|
52
|
-
|
|
85
|
+
warn,
|
|
86
|
+
debug
|
|
87
|
+
}, logLevel);
|
|
53
88
|
}
|
|
54
89
|
// Memoise print so that error handler can get the same spinner object
|
|
55
90
|
let print;
|
|
56
|
-
function createPrint() {
|
|
57
|
-
// TODO: Add debug
|
|
91
|
+
function createPrint({ logLevel }) {
|
|
58
92
|
if (print) return print;
|
|
59
93
|
if (process.env.CI === 'true' || process.env.CI === '1') {
|
|
60
|
-
print = createBasicPrint(
|
|
94
|
+
print = createBasicPrint({
|
|
95
|
+
logLevel
|
|
96
|
+
});
|
|
61
97
|
return print;
|
|
62
98
|
}
|
|
63
|
-
print = createOraPrint(
|
|
99
|
+
print = createOraPrint({
|
|
100
|
+
logLevel
|
|
101
|
+
});
|
|
64
102
|
return print;
|
|
65
103
|
}
|
|
66
104
|
export { createOraPrint, createBasicPrint };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function createStdOutLineHandler({ context }) {
|
|
16
|
+
function stdOutLineHandler(line) {
|
|
17
|
+
try {
|
|
18
|
+
const { print , msg } = JSON.parse(line);
|
|
19
|
+
context.print[print](msg);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
context.print.log(line);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return stdOutLineHandler;
|
|
25
|
+
}
|
|
26
|
+
export default createStdOutLineHandler;
|
|
@@ -37,7 +37,9 @@ async function logError({ error , context ={} }) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
async function errorHandler({ context , error }) {
|
|
40
|
-
const print = createPrint(
|
|
40
|
+
const print = createPrint({
|
|
41
|
+
logLevel: 'info'
|
|
42
|
+
});
|
|
41
43
|
print.error(error.message);
|
|
42
44
|
if (!context.disableTelemetry) {
|
|
43
45
|
await logError({
|
|
@@ -26,13 +26,12 @@ async function installServer({ context , directory }) {
|
|
|
26
26
|
context.print.spin(`Running ${context.packageManager} install.`);
|
|
27
27
|
try {
|
|
28
28
|
await spawnProcess({
|
|
29
|
-
logger: context.print,
|
|
30
29
|
command: context.packageManagerCmd,
|
|
31
30
|
args: args[context.packageManager],
|
|
31
|
+
stdOutLineHandler: (line)=>context.print.debug(line),
|
|
32
32
|
processOptions: {
|
|
33
33
|
cwd: directory
|
|
34
|
-
}
|
|
35
|
-
silent: false
|
|
34
|
+
}
|
|
36
35
|
});
|
|
37
36
|
} catch (error) {
|
|
38
37
|
console.log(error);
|
|
@@ -13,25 +13,28 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from './createStdOutLineHandler.js';
|
|
16
17
|
async function runLowdefyBuild({ context , directory }) {
|
|
17
|
-
context.print.
|
|
18
|
+
context.print.spin('Running Lowdefy build.');
|
|
18
19
|
try {
|
|
19
20
|
await spawnProcess({
|
|
20
|
-
logger: context.print,
|
|
21
21
|
command: context.packageManagerCmd,
|
|
22
22
|
args: [
|
|
23
23
|
'run',
|
|
24
24
|
'build:lowdefy'
|
|
25
25
|
],
|
|
26
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
27
|
+
context
|
|
28
|
+
}),
|
|
26
29
|
processOptions: {
|
|
27
30
|
cwd: directory,
|
|
28
31
|
env: {
|
|
29
32
|
...process.env,
|
|
30
33
|
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
31
|
-
LOWDEFY_DIRECTORY_CONFIG: context.directories.config
|
|
34
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
35
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel
|
|
32
36
|
}
|
|
33
|
-
}
|
|
34
|
-
silent: false
|
|
37
|
+
}
|
|
35
38
|
});
|
|
36
39
|
} catch (error) {
|
|
37
40
|
throw new Error('Lowdefy build failed.');
|
|
@@ -13,20 +13,32 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
function createStdOutLineHandler({ context }) {
|
|
17
|
+
function stdOutLineHandler(line) {
|
|
18
|
+
// Matches next build output of form: ┌ λ / 261 B 403 kB
|
|
19
|
+
const match = line.match(/┌ λ \/\s*\d* [a-zA-Z]*\s*(\d* [a-zA-Z]*)/);
|
|
20
|
+
if (match) {
|
|
21
|
+
context.print.info(`Home page first load JS size: ${match[1]}.`);
|
|
22
|
+
}
|
|
23
|
+
context.print.debug(line);
|
|
24
|
+
}
|
|
25
|
+
return stdOutLineHandler;
|
|
26
|
+
}
|
|
16
27
|
async function runNextBuild({ context , directory }) {
|
|
17
|
-
context.print.
|
|
28
|
+
context.print.spin('Running Next build.');
|
|
18
29
|
try {
|
|
19
30
|
await spawnProcess({
|
|
20
|
-
logger: context.print,
|
|
21
31
|
command: context.packageManagerCmd,
|
|
22
32
|
args: [
|
|
23
33
|
'run',
|
|
24
34
|
'build:next'
|
|
25
35
|
],
|
|
36
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
37
|
+
context
|
|
38
|
+
}),
|
|
26
39
|
processOptions: {
|
|
27
40
|
cwd: directory
|
|
28
|
-
}
|
|
29
|
-
silent: false
|
|
41
|
+
}
|
|
30
42
|
});
|
|
31
43
|
} catch (error) {
|
|
32
44
|
throw new Error('Next build failed.');
|
package/dist/utils/startUp.js
CHANGED
|
@@ -25,8 +25,7 @@ import createPrint from './createPrint.js';
|
|
|
25
25
|
async function startUp({ context , options ={} , command }) {
|
|
26
26
|
context.command = command.name();
|
|
27
27
|
context.commandLineOptions = options;
|
|
28
|
-
context.
|
|
29
|
-
context.configDirectory = path.resolve(options.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd());
|
|
28
|
+
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
|
|
30
29
|
const { cliConfig , lowdefyVersion , plugins } = await getLowdefyYaml(context);
|
|
31
30
|
context.cliConfig = cliConfig;
|
|
32
31
|
context.lowdefyVersion = lowdefyVersion;
|
|
@@ -34,6 +33,9 @@ async function startUp({ context , options ={} , command }) {
|
|
|
34
33
|
const { appId } = await getCliJson(context);
|
|
35
34
|
context.appId = appId;
|
|
36
35
|
context.options = getOptions(context);
|
|
36
|
+
context.print = createPrint({
|
|
37
|
+
logLevel: context.options.logLevel
|
|
38
|
+
});
|
|
37
39
|
context.directories = getDirectories(context);
|
|
38
40
|
context.packageManager = getPackageManager(context);
|
|
39
41
|
context.packageManagerCmd = process.platform === 'win32' ? `${context.packageManager}.cmd` : context.packageManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lowdefy",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.27",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy CLI",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -40,11 +40,10 @@
|
|
|
40
40
|
"test": "FORCE_COLOR=3 yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
44
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
43
|
+
"@lowdefy/helpers": "4.0.0-alpha.27",
|
|
44
|
+
"@lowdefy/node-utils": "4.0.0-alpha.27",
|
|
45
45
|
"axios": "0.27.2",
|
|
46
|
-
"
|
|
47
|
-
"commander": "9.0.0",
|
|
46
|
+
"commander": "9.4.0",
|
|
48
47
|
"decompress": "4.2.1",
|
|
49
48
|
"decompress-targz": "4.1.1",
|
|
50
49
|
"dotenv": "16.0.1",
|
|
@@ -62,5 +61,5 @@
|
|
|
62
61
|
"publishConfig": {
|
|
63
62
|
"access": "public"
|
|
64
63
|
},
|
|
65
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "02010edcce0f218c54cdbd08f28a60a08c36edfa"
|
|
66
65
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ let BatchChanges = class BatchChanges {
|
|
16
|
-
newChange(...args) {
|
|
17
|
-
this.args.push(args);
|
|
18
|
-
this.delay = this.minDelay;
|
|
19
|
-
this._startTimer();
|
|
20
|
-
}
|
|
21
|
-
_startTimer() {
|
|
22
|
-
if (this.timer) {
|
|
23
|
-
clearTimeout(this.timer);
|
|
24
|
-
}
|
|
25
|
-
if (this.running) {
|
|
26
|
-
this.repeat = true;
|
|
27
|
-
} else {
|
|
28
|
-
this.timer = setTimeout(this._call, this.delay);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async _call() {
|
|
32
|
-
this.running = true;
|
|
33
|
-
try {
|
|
34
|
-
const args = this.args;
|
|
35
|
-
this.args = [];
|
|
36
|
-
await this.fn(args);
|
|
37
|
-
this.running = false;
|
|
38
|
-
if (this.repeat) {
|
|
39
|
-
this.repeat = false;
|
|
40
|
-
this._call();
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
this.running = false;
|
|
44
|
-
this.context.print.error(error.message);
|
|
45
|
-
this.delay *= 2;
|
|
46
|
-
this.context.print.warn(`Retrying in ${this.delay / 1000}s.`);
|
|
47
|
-
this._startTimer();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
constructor({ fn , context , minDelay }){
|
|
51
|
-
this._call = this._call.bind(this);
|
|
52
|
-
this.args = [];
|
|
53
|
-
this.context = context;
|
|
54
|
-
this.delay = minDelay || 500;
|
|
55
|
-
this.fn = fn;
|
|
56
|
-
this.minDelay = minDelay || 500;
|
|
57
|
-
this.repeat = false;
|
|
58
|
-
this.running = false;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
export default BatchChanges;
|