lowdefy 4.0.0-alpha.9 → 4.0.0-rc.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/dist/commands/build/build.js +8 -4
- package/dist/commands/dev/runDevServer.js +7 -3
- package/dist/commands/init/lowdefyFile.js +1 -2
- package/dist/commands/start/runStart.js +7 -6
- package/dist/commands/start/start.js +5 -2
- package/dist/index.js +10 -28
- package/dist/program.js +59 -0
- package/dist/utils/addCustomPluginsAsDeps.js +5 -5
- package/dist/utils/checkPnpmIsInstalled.js +32 -0
- package/dist/utils/copyPluginsFolder.js +6 -3
- package/dist/utils/createPrint.js +63 -31
- package/dist/utils/createStdOutLineHandler.js +26 -0
- package/dist/utils/errorHandler.js +3 -1
- package/dist/utils/getDirectories.js +6 -9
- package/dist/utils/installServer.js +10 -17
- package/dist/utils/readDotEnv.js +23 -0
- package/dist/utils/runLowdefyBuild.js +8 -7
- package/dist/utils/runNextBuild.js +17 -5
- package/dist/utils/startUp.js +6 -3
- package/package.json +17 -18
- package/dist/utils/BatchChanges.js +0 -61
- package/dist/utils/getPackageManager.js +0 -54
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
|
17
17
|
import getServer from '../../utils/getServer.js';
|
|
18
18
|
import installServer from '../../utils/installServer.js';
|
|
19
|
+
import readDotEnv from '../../utils/readDotEnv.js';
|
|
19
20
|
import runLowdefyBuild from '../../utils/runLowdefyBuild.js';
|
|
20
21
|
import runNextBuild from '../../utils/runNextBuild.js';
|
|
21
22
|
async function build({ context }) {
|
|
22
23
|
context.print.info('Starting build.');
|
|
24
|
+
readDotEnv(context);
|
|
23
25
|
const directory = context.directories.server;
|
|
24
26
|
await getServer({
|
|
25
27
|
context,
|
|
@@ -46,10 +48,12 @@ async function build({ context }) {
|
|
|
46
48
|
context,
|
|
47
49
|
directory
|
|
48
50
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (context.options.nextBuild !== false) {
|
|
52
|
+
await runNextBuild({
|
|
53
|
+
context,
|
|
54
|
+
directory
|
|
55
|
+
});
|
|
56
|
+
}
|
|
53
57
|
await context.sendTelemetry({
|
|
54
58
|
sendTypes: true
|
|
55
59
|
});
|
|
@@ -13,21 +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 runDevServer({ context , directory }) {
|
|
17
18
|
await spawnProcess({
|
|
18
|
-
logger: context.print,
|
|
19
19
|
args: [
|
|
20
20
|
'run',
|
|
21
21
|
'start'
|
|
22
22
|
],
|
|
23
|
-
command: context.
|
|
23
|
+
command: context.pnpmCmd,
|
|
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,
|
|
30
|
-
|
|
33
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
34
|
+
LOWDEFY_SERVER_DEV_OPEN_BROWSER: !!context.options.open,
|
|
31
35
|
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
32
36
|
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
|
33
37
|
PORT: context.options.port
|
|
@@ -13,24 +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
|
-
command: context.
|
|
23
|
+
command: context.pnpmCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
25
27
|
processOptions: {
|
|
26
28
|
cwd: directory,
|
|
27
29
|
env: {
|
|
28
30
|
...process.env,
|
|
29
|
-
|
|
31
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
30
32
|
PORT: context.options.port
|
|
31
33
|
}
|
|
32
|
-
}
|
|
33
|
-
silent: false
|
|
34
|
+
}
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
export default runStart;
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import runStart from './runStart.js';
|
|
16
|
+
import readDotEnv from '../../utils/readDotEnv.js';
|
|
16
17
|
// TODO: Handle "spawn yarn ENOENT" error if no built server exists.
|
|
17
18
|
async function build({ context }) {
|
|
18
|
-
context.print.info('Starting server.');
|
|
19
19
|
context.sendTelemetry({
|
|
20
20
|
sendTypes: true
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
readDotEnv(context);
|
|
23
|
+
const serverProcess = runStart({
|
|
23
24
|
context,
|
|
24
25
|
directory: context.directories.server
|
|
25
26
|
});
|
|
27
|
+
context.print.succeed('Started server.');
|
|
28
|
+
await serverProcess;
|
|
26
29
|
}
|
|
27
30
|
export default build;
|
package/dist/index.js
CHANGED
|
@@ -13,31 +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
|
-
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
27
|
-
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('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".').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({
|
|
28
|
-
cliVersion,
|
|
29
|
-
handler: build
|
|
30
|
-
}));
|
|
31
|
-
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('--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({
|
|
32
|
-
cliVersion,
|
|
33
|
-
handler: dev
|
|
34
|
-
}));
|
|
35
|
-
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
36
|
-
cliVersion,
|
|
37
|
-
handler: init
|
|
38
|
-
}));
|
|
39
|
-
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('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".').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({
|
|
40
|
-
cliVersion,
|
|
41
|
-
handler: start
|
|
42
|
-
}));
|
|
43
|
-
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,59 @@
|
|
|
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
|
+
port: new Option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').env('PORT'),
|
|
38
|
+
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.'),
|
|
39
|
+
serverDirectory: new Option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').env('LOWDEFY_DIRECTORY_SERVER'),
|
|
40
|
+
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.'),
|
|
41
|
+
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.')
|
|
42
|
+
};
|
|
43
|
+
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.refResolver).addOption(options.serverDirectory).action(runCommand({
|
|
44
|
+
cliVersion,
|
|
45
|
+
handler: build
|
|
46
|
+
}));
|
|
47
|
+
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.port).addOption(options.refResolver).addOption(options.watch).addOption(options.watchIgnore).action(runCommand({
|
|
48
|
+
cliVersion,
|
|
49
|
+
handler: dev
|
|
50
|
+
}));
|
|
51
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
52
|
+
cliVersion,
|
|
53
|
+
handler: init
|
|
54
|
+
}));
|
|
55
|
+
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).addOption(options.port).addOption(options.serverDirectory).action(runCommand({
|
|
56
|
+
cliVersion,
|
|
57
|
+
handler: start
|
|
58
|
+
}));
|
|
59
|
+
export default program;
|
|
@@ -17,14 +17,14 @@ import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
|
17
17
|
async function addCustomPluginsAsDeps({ context , directory }) {
|
|
18
18
|
const packageJsonPath = path.join(directory, 'package.json');
|
|
19
19
|
const packageJson = JSON.parse(await readFile(packageJsonPath));
|
|
20
|
-
const
|
|
20
|
+
const dependencies = packageJson.dependencies;
|
|
21
21
|
Object.values(context.plugins).forEach((plugin)=>{
|
|
22
|
-
|
|
22
|
+
dependencies[plugin.name] = plugin.version;
|
|
23
23
|
});
|
|
24
24
|
// Sort dependencies
|
|
25
|
-
packageJson.
|
|
26
|
-
Object.keys(
|
|
27
|
-
packageJson.
|
|
25
|
+
packageJson.dependencies = {};
|
|
26
|
+
Object.keys(dependencies).sort().forEach((name)=>{
|
|
27
|
+
packageJson.dependencies[name] = dependencies[name];
|
|
28
28
|
});
|
|
29
29
|
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
|
|
30
30
|
await writeFile(packageJsonPath, newPackageJsonContent);
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { execSync } from 'child_process';
|
|
16
|
+
function checkPnpmIsInstalled({ print , pnpmCmd }) {
|
|
17
|
+
try {
|
|
18
|
+
execSync(`${pnpmCmd} --version`, {
|
|
19
|
+
stdio: 'ignore'
|
|
20
|
+
});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
print.error(`
|
|
23
|
+
-------------------------------------------------------------
|
|
24
|
+
The package manager "pnpm" is required to run Lowdefy.
|
|
25
|
+
Install pnpm as describe here:
|
|
26
|
+
https://pnpm.io/installation
|
|
27
|
+
or run 'corepack enable'.
|
|
28
|
+
-------------------------------------------------------------`);
|
|
29
|
+
throw new Error('The package manager "pnpm" is required to run Lowdefy.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export default checkPnpmIsInstalled;
|
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import fs from 'fs';
|
|
17
|
-
import { copyDirectory } from '@lowdefy/node-utils';
|
|
17
|
+
import { cleanDirectory, copyDirectory } from '@lowdefy/node-utils';
|
|
18
18
|
async function copyPluginsFolder({ context , directory }) {
|
|
19
19
|
if (context.directories.config === directory) return;
|
|
20
|
-
if (!fs.existsSync(path.
|
|
21
|
-
await
|
|
20
|
+
if (!fs.existsSync(path.join(context.directories.config, 'plugins'))) return;
|
|
21
|
+
await cleanDirectory(path.join(directory, 'plugins'));
|
|
22
|
+
await copyDirectory(path.join(context.directories.config, 'plugins'), path.join(directory, 'plugins'), {
|
|
23
|
+
filter: (path1)=>!path1.includes('node_modules')
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
export default copyPluginsFolder;
|
|
@@ -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,52 +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: ()=>
|
|
28
|
-
,
|
|
51
|
+
prefixText: ()=>dim(getTime()),
|
|
29
52
|
color: 'blue'
|
|
30
53
|
});
|
|
31
|
-
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
60
|
+
}),
|
|
61
|
+
spin: (text)=>spinner.start(text),
|
|
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);
|
|
47
76
|
}
|
|
48
|
-
function createBasicPrint() {
|
|
49
|
-
const { error , info , log , warn } = console;
|
|
50
|
-
return {
|
|
51
|
-
type: 'basic',
|
|
77
|
+
function createBasicPrint({ logLevel ='info' }) {
|
|
78
|
+
const { error , info , log , warn , debug } = console;
|
|
79
|
+
return filterLevels({
|
|
52
80
|
error,
|
|
53
81
|
info,
|
|
54
82
|
log,
|
|
55
83
|
spin: log,
|
|
56
84
|
succeed: log,
|
|
57
|
-
warn
|
|
58
|
-
|
|
85
|
+
warn,
|
|
86
|
+
debug
|
|
87
|
+
}, logLevel);
|
|
59
88
|
}
|
|
60
89
|
// Memoise print so that error handler can get the same spinner object
|
|
61
90
|
let print;
|
|
62
|
-
function createPrint() {
|
|
63
|
-
// TODO: Add debug
|
|
91
|
+
function createPrint({ logLevel }) {
|
|
64
92
|
if (print) return print;
|
|
65
|
-
if (process.env.CI === 'true') {
|
|
66
|
-
print = createBasicPrint(
|
|
93
|
+
if (process.env.CI === 'true' || process.env.CI === '1') {
|
|
94
|
+
print = createBasicPrint({
|
|
95
|
+
logLevel
|
|
96
|
+
});
|
|
67
97
|
return print;
|
|
68
98
|
}
|
|
69
|
-
print = createOraPrint(
|
|
99
|
+
print = createOraPrint({
|
|
100
|
+
logLevel
|
|
101
|
+
});
|
|
70
102
|
return print;
|
|
71
103
|
}
|
|
72
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({
|
|
@@ -14,17 +14,14 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
function getDirectories({ configDirectory , options }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
22
|
-
}
|
|
17
|
+
const dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
18
|
+
const server = options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server');
|
|
19
|
+
// TODO: Read server directory from env var
|
|
20
|
+
// Priority should be CLI arguments, env var, CLI options in Lowdefy config
|
|
23
21
|
return {
|
|
24
22
|
config: configDirectory,
|
|
25
|
-
build: path.join(
|
|
26
|
-
|
|
27
|
-
server: options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server'),
|
|
23
|
+
build: path.join(server, 'build'),
|
|
24
|
+
server,
|
|
28
25
|
dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev')
|
|
29
26
|
};
|
|
30
27
|
}
|
|
@@ -13,31 +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
|
-
const args = {
|
|
17
|
-
npm: [
|
|
18
|
-
'install',
|
|
19
|
-
'--legacy-peer-deps'
|
|
20
|
-
],
|
|
21
|
-
yarn: [
|
|
22
|
-
'install'
|
|
23
|
-
]
|
|
24
|
-
};
|
|
25
16
|
async function installServer({ context , directory }) {
|
|
26
|
-
context.print.spin(
|
|
17
|
+
context.print.spin('Installing dependencies.');
|
|
27
18
|
try {
|
|
28
19
|
await spawnProcess({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
command: context.pnpmCmd,
|
|
21
|
+
args: [
|
|
22
|
+
'install',
|
|
23
|
+
'--no-frozen-lockfile'
|
|
24
|
+
],
|
|
25
|
+
stdOutLineHandler: (line)=>context.print.debug(line),
|
|
32
26
|
processOptions: {
|
|
33
27
|
cwd: directory
|
|
34
|
-
}
|
|
35
|
-
silent: false
|
|
28
|
+
}
|
|
36
29
|
});
|
|
37
30
|
} catch (error) {
|
|
38
31
|
console.log(error);
|
|
39
|
-
throw new Error(
|
|
32
|
+
throw new Error('Dependency installation failed.');
|
|
40
33
|
}
|
|
41
|
-
context.print.log(
|
|
34
|
+
context.print.log('Dependencies install successfully.');
|
|
42
35
|
}
|
|
43
36
|
export default installServer;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 path from 'path';
|
|
16
|
+
import dotenv from 'dotenv';
|
|
17
|
+
function readDotEnv(context) {
|
|
18
|
+
dotenv.config({
|
|
19
|
+
path: path.join(context.directories.config, '.env'),
|
|
20
|
+
silent: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export default readDotEnv;
|
|
@@ -13,27 +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
|
-
command: context.packageManager,
|
|
22
21
|
args: [
|
|
23
22
|
'run',
|
|
24
23
|
'build:lowdefy'
|
|
25
24
|
],
|
|
25
|
+
command: context.pnpmCmd,
|
|
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_BUILD: context.directories.build,
|
|
32
34
|
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
33
|
-
|
|
35
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel
|
|
34
36
|
}
|
|
35
|
-
}
|
|
36
|
-
silent: false
|
|
37
|
+
}
|
|
37
38
|
});
|
|
38
39
|
} catch (error) {
|
|
39
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
|
-
|
|
21
|
-
command: context.packageManager,
|
|
31
|
+
command: context.pnpmCmd,
|
|
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
|
@@ -15,17 +15,16 @@
|
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import { type } from '@lowdefy/helpers';
|
|
17
17
|
import checkForUpdatedVersions from './checkForUpdatedVersions.js';
|
|
18
|
+
import checkPnpmIsInstalled from './checkPnpmIsInstalled.js';
|
|
18
19
|
import getCliJson from './getCliJson.js';
|
|
19
20
|
import getDirectories from './getDirectories.js';
|
|
20
21
|
import getLowdefyYaml from './getLowdefyYaml.js';
|
|
21
22
|
import getOptions from './getOptions.js';
|
|
22
|
-
import getPackageManager from './getPackageManager.js';
|
|
23
23
|
import getSendTelemetry from './getSendTelemetry.js';
|
|
24
24
|
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.print = createPrint();
|
|
29
28
|
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
|
|
30
29
|
const { cliConfig , lowdefyVersion , plugins } = await getLowdefyYaml(context);
|
|
31
30
|
context.cliConfig = cliConfig;
|
|
@@ -34,8 +33,12 @@ 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
|
-
context.
|
|
40
|
+
context.pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';
|
|
41
|
+
checkPnpmIsInstalled(context);
|
|
39
42
|
await checkForUpdatedVersions(context);
|
|
40
43
|
context.sendTelemetry = getSendTelemetry(context);
|
|
41
44
|
if (type.isNone(lowdefyVersion)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lowdefy",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy CLI",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -32,34 +32,33 @@
|
|
|
32
32
|
],
|
|
33
33
|
"exports": "./dist/index.js",
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "
|
|
35
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
36
36
|
"clean": "rm -rf dist && rm -rf .lowdefy",
|
|
37
|
-
"start": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"test": "FORCE_COLOR=3 yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
37
|
+
"start": "node ./dist/index.js",
|
|
38
|
+
"prepublishOnly": "pnpm build",
|
|
39
|
+
"test": "FORCE_COLOR=3 node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
41
40
|
},
|
|
42
41
|
"dependencies": {
|
|
43
|
-
"@lowdefy/helpers": "4.0.0-
|
|
44
|
-
"@lowdefy/node-utils": "4.0.0-
|
|
45
|
-
"axios": "0.
|
|
46
|
-
"
|
|
47
|
-
"commander": "9.0.0",
|
|
42
|
+
"@lowdefy/helpers": "4.0.0-rc.0",
|
|
43
|
+
"@lowdefy/node-utils": "4.0.0-rc.0",
|
|
44
|
+
"axios": "0.27.2",
|
|
45
|
+
"commander": "9.4.0",
|
|
48
46
|
"decompress": "4.2.1",
|
|
49
47
|
"decompress-targz": "4.1.1",
|
|
48
|
+
"dotenv": "16.0.1",
|
|
50
49
|
"ora": "5.4.1",
|
|
51
50
|
"uuid": "8.3.2",
|
|
52
|
-
"yaml": "2.
|
|
51
|
+
"yaml": "2.1.1"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
|
-
"@jest/globals": "
|
|
56
|
-
"@swc/cli": "0.1.
|
|
57
|
-
"@swc/core": "1.2.
|
|
58
|
-
"@swc/jest": "0.2.
|
|
59
|
-
"jest": "
|
|
54
|
+
"@jest/globals": "28.1.0",
|
|
55
|
+
"@swc/cli": "0.1.57",
|
|
56
|
+
"@swc/core": "1.2.194",
|
|
57
|
+
"@swc/jest": "0.2.21",
|
|
58
|
+
"jest": "28.1.0"
|
|
60
59
|
},
|
|
61
60
|
"publishConfig": {
|
|
62
61
|
"access": "public"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
|
|
65
64
|
}
|
|
@@ -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;
|
|
@@ -1,54 +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
|
-
*/ // Source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/should-use-yarn.ts
|
|
16
|
-
/*
|
|
17
|
-
The MIT License (MIT)
|
|
18
|
-
|
|
19
|
-
Copyright (c) 2021 Vercel, Inc.
|
|
20
|
-
|
|
21
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
-
in the Software without restriction, including without limitation the rights
|
|
24
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
-
furnished to do so, subject to the following conditions:
|
|
27
|
-
|
|
28
|
-
The above copyright notice and this permission notice shall be included in all
|
|
29
|
-
copies or substantial portions of the Software.
|
|
30
|
-
|
|
31
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
-
SOFTWARE.
|
|
38
|
-
*/ import { execSync } from 'child_process';
|
|
39
|
-
function getPackageManager({ options }) {
|
|
40
|
-
if (options.packageManager) return options.packageManager;
|
|
41
|
-
try {
|
|
42
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
43
|
-
if (userAgent && userAgent.startsWith('yarn')) {
|
|
44
|
-
return 'yarn';
|
|
45
|
-
}
|
|
46
|
-
execSync('yarnpkg --version', {
|
|
47
|
-
stdio: 'ignore'
|
|
48
|
-
});
|
|
49
|
-
return 'yarn';
|
|
50
|
-
} catch (e) {
|
|
51
|
-
return 'npm';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export default getPackageManager;
|