lowdefy 4.0.0-alpha.6 → 4.0.0-alpha.7
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 +3 -2
- package/dist/commands/build/runLowdefyBuild.js +2 -1
- package/dist/commands/dev/dev.js +4 -3
- package/dist/commands/dev/installServer.js +1 -1
- package/dist/commands/dev/runDevServer.js +7 -2
- package/dist/commands/init/init.js +5 -11
- package/dist/commands/init/lowdefyFile.js +1 -1
- package/dist/commands/start/runStart.js +6 -1
- package/dist/index.js +19 -18
- package/dist/utils/{print.js → createPrint.js} +0 -0
- package/dist/utils/errorHandler.js +1 -1
- package/dist/utils/getCliJson.js +5 -8
- package/dist/utils/getDirectories.js +5 -5
- package/dist/utils/getLowdefyYaml.js +6 -6
- package/dist/{commands/build → utils}/getServer.js +7 -4
- package/dist/utils/runCommand.js +22 -23
- package/dist/utils/startUp.js +2 -2
- package/package.json +13 -12
- package/dist/commands/dev/getServer.js +0 -42
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import getServer from '
|
|
15
|
+
*/ import getServer from '../../utils/getServer.js';
|
|
16
16
|
import installServer from './installServer.js';
|
|
17
17
|
import runLowdefyBuild from './runLowdefyBuild.js';
|
|
18
18
|
import runNextBuild from './runNextBuild.js';
|
|
19
19
|
async function build({ context }) {
|
|
20
20
|
context.print.info('Starting build.');
|
|
21
21
|
await getServer({
|
|
22
|
-
context
|
|
22
|
+
context,
|
|
23
|
+
packageName: '@lowdefy/server'
|
|
23
24
|
});
|
|
24
25
|
await installServer({
|
|
25
26
|
context
|
|
@@ -27,8 +27,9 @@ async function runLowdefyBuild({ context }) {
|
|
|
27
27
|
cwd: context.directories.server,
|
|
28
28
|
env: {
|
|
29
29
|
...process.env,
|
|
30
|
+
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
30
31
|
LOWDEFY_DIRECTORY_BUILD: context.directories.build,
|
|
31
|
-
LOWDEFY_DIRECTORY_CONFIG: context.directories.
|
|
32
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
32
33
|
LOWDEFY_DIRECTORY_SERVER: context.directories.server
|
|
33
34
|
}
|
|
34
35
|
},
|
package/dist/commands/dev/dev.js
CHANGED
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import
|
|
16
|
-
import installServer from './installServer.js';
|
|
15
|
+
*/ import installServer from './installServer.js';
|
|
17
16
|
import runDevServer from './runDevServer.js';
|
|
17
|
+
import getServer from '../../utils/getServer.js';
|
|
18
18
|
async function dev({ context }) {
|
|
19
19
|
context.print.info('Starting development server.');
|
|
20
20
|
await getServer({
|
|
21
|
-
context
|
|
21
|
+
context,
|
|
22
|
+
packageName: '@lowdefy/server-dev'
|
|
22
23
|
});
|
|
23
24
|
await installServer({
|
|
24
25
|
context
|
|
@@ -22,10 +22,15 @@ async function runDevServer({ context }) {
|
|
|
22
22
|
],
|
|
23
23
|
command: context.packageManager,
|
|
24
24
|
processOptions: {
|
|
25
|
-
cwd: context.directories.
|
|
25
|
+
cwd: context.directories.dev,
|
|
26
26
|
env: {
|
|
27
27
|
...process.env,
|
|
28
|
-
|
|
28
|
+
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
29
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
30
|
+
LOWDEFY_PACKAGE_MANAGER: context.packageManager,
|
|
31
|
+
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
32
|
+
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
|
33
|
+
PORT: context.options.port
|
|
29
34
|
}
|
|
30
35
|
},
|
|
31
36
|
silent: false
|
|
@@ -23,18 +23,12 @@ async function init({ context }) {
|
|
|
23
23
|
throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');
|
|
24
24
|
}
|
|
25
25
|
context.print.log(`Initializing Lowdefy project`);
|
|
26
|
-
await writeFile({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
version: context.cliVersion
|
|
30
|
-
})
|
|
31
|
-
});
|
|
26
|
+
await writeFile(lowdefyFilePath, lowdefyFile({
|
|
27
|
+
version: context.cliVersion
|
|
28
|
+
}));
|
|
32
29
|
context.print.log(`Created 'lowdefy.yaml'.`);
|
|
33
|
-
await writeFile(
|
|
34
|
-
|
|
35
|
-
content: `.lowdefy/**
|
|
36
|
-
.env`
|
|
37
|
-
});
|
|
30
|
+
await writeFile(path.resolve('./.gitignore'), `.lowdefy/**
|
|
31
|
+
.env`);
|
|
38
32
|
context.print.log(`Created '.gitignore'.`);
|
|
39
33
|
await context.sendTelemetry();
|
|
40
34
|
context.print.succeed(`Project initialized.`);
|
|
@@ -23,7 +23,12 @@ async function runStart({ context }) {
|
|
|
23
23
|
],
|
|
24
24
|
command: context.packageManager,
|
|
25
25
|
processOptions: {
|
|
26
|
-
cwd: context.directories.server
|
|
26
|
+
cwd: context.directories.server,
|
|
27
|
+
env: {
|
|
28
|
+
...process.env,
|
|
29
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
30
|
+
PORT: context.options.port
|
|
31
|
+
}
|
|
27
32
|
},
|
|
28
33
|
silent: false
|
|
29
34
|
});
|
package/dist/index.js
CHANGED
|
@@ -14,29 +14,30 @@
|
|
|
14
14
|
See the License for the specific language governing permissions and
|
|
15
15
|
limitations under the License.
|
|
16
16
|
*/ import { readFile } from '@lowdefy/node-utils';
|
|
17
|
-
import
|
|
17
|
+
import { Command } from 'commander';
|
|
18
18
|
import build from './commands/build/build.js';
|
|
19
19
|
import dev from './commands/dev/dev.js';
|
|
20
20
|
import init from './commands/init/init.js';
|
|
21
21
|
import start from './commands/start/start.js';
|
|
22
22
|
import runCommand from './utils/runCommand.js';
|
|
23
23
|
const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url).pathname));
|
|
24
|
-
const { description , version } = packageJson;
|
|
25
|
-
program
|
|
26
|
-
program.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.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.')
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})(dev));
|
|
24
|
+
const { description , version: cliVersion } = packageJson;
|
|
25
|
+
const program = new Command();
|
|
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
|
+
}));
|
|
36
35
|
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
37
|
-
cliVersion
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}));
|
|
42
43
|
program.parse(process.argv);
|
|
File without changes
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import axios from 'axios';
|
|
16
|
-
import createPrint from './
|
|
16
|
+
import createPrint from './createPrint.js';
|
|
17
17
|
async function logError({ error , context ={} }) {
|
|
18
18
|
try {
|
|
19
19
|
await axios.request({
|
package/dist/utils/getCliJson.js
CHANGED
|
@@ -15,17 +15,14 @@
|
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
17
17
|
import { v4 as uuid } from 'uuid';
|
|
18
|
-
async function getCliJson({
|
|
19
|
-
const filePath = path.resolve(
|
|
18
|
+
async function getCliJson({ configDirectory }) {
|
|
19
|
+
const filePath = path.resolve(configDirectory, './.lowdefy/cli.json');
|
|
20
20
|
const cliJson = await readFile(filePath);
|
|
21
21
|
if (!cliJson) {
|
|
22
22
|
const appId = uuid();
|
|
23
|
-
await writeFile({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
appId
|
|
27
|
-
}, null, 2)
|
|
28
|
-
});
|
|
23
|
+
await writeFile(filePath, JSON.stringify({
|
|
24
|
+
appId
|
|
25
|
+
}, null, 2));
|
|
29
26
|
return {
|
|
30
27
|
appId
|
|
31
28
|
};
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
|
-
function getDirectories({
|
|
16
|
+
function getDirectories({ configDirectory , options }) {
|
|
17
17
|
let dotLowdefy;
|
|
18
18
|
if (options.outputDirectory) {
|
|
19
19
|
dotLowdefy = path.resolve(options.outputDirectory);
|
|
20
20
|
} else {
|
|
21
|
-
dotLowdefy = path.resolve(
|
|
21
|
+
dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
|
-
|
|
24
|
+
config: configDirectory,
|
|
25
25
|
build: path.join(dotLowdefy, 'server', 'build'),
|
|
26
26
|
dotLowdefy,
|
|
27
|
-
server: path.join(dotLowdefy, 'server'),
|
|
28
|
-
|
|
27
|
+
server: options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server'),
|
|
28
|
+
dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev')
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
export default getDirectories;
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import { get, type } from '@lowdefy/helpers';
|
|
17
17
|
import { readFile } from '@lowdefy/node-utils';
|
|
18
|
-
import YAML from '
|
|
19
|
-
async function getLowdefyYaml({
|
|
20
|
-
let lowdefyYaml = await readFile(path.resolve(
|
|
18
|
+
import YAML from 'yaml';
|
|
19
|
+
async function getLowdefyYaml({ configDirectory , command }) {
|
|
20
|
+
let lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yaml'));
|
|
21
21
|
if (!lowdefyYaml) {
|
|
22
|
-
lowdefyYaml = await readFile(path.resolve(
|
|
22
|
+
lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yml'));
|
|
23
23
|
}
|
|
24
24
|
if (!lowdefyYaml) {
|
|
25
25
|
if (![
|
|
26
26
|
'init'
|
|
27
27
|
].includes(command)) {
|
|
28
|
-
throw new Error(`Could not find "lowdefy.yaml" file in specified
|
|
28
|
+
throw new Error(`Could not find "lowdefy.yaml" file in specified config directory ${configDirectory}.`);
|
|
29
29
|
}
|
|
30
30
|
return {
|
|
31
31
|
cliConfig: {}
|
|
@@ -33,7 +33,7 @@ async function getLowdefyYaml({ baseDirectory , command }) {
|
|
|
33
33
|
}
|
|
34
34
|
let lowdefy;
|
|
35
35
|
try {
|
|
36
|
-
lowdefy = YAML.
|
|
36
|
+
lowdefy = YAML.parse(lowdefyYaml);
|
|
37
37
|
} catch (error) {
|
|
38
38
|
throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${error.message}.`);
|
|
39
39
|
}
|
|
@@ -15,8 +15,12 @@
|
|
|
15
15
|
*/ import fs from 'fs';
|
|
16
16
|
import path from 'path';
|
|
17
17
|
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
|
|
18
|
-
import fetchNpmTarball from '
|
|
19
|
-
async function getServer({ context }) {
|
|
18
|
+
import fetchNpmTarball from './fetchNpmTarball.js';
|
|
19
|
+
async function getServer({ context , packageName }) {
|
|
20
|
+
if (context.lowdefyVersion === 'local') {
|
|
21
|
+
context.print.warn(`Running local ${packageName}.`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
20
24
|
let fetchServer = false;
|
|
21
25
|
const serverExists = fs.existsSync(path.join(context.directories.server, 'package.json'));
|
|
22
26
|
if (!serverExists) fetchServer = true;
|
|
@@ -31,12 +35,11 @@ async function getServer({ context }) {
|
|
|
31
35
|
if (fetchServer) {
|
|
32
36
|
context.print.spin('Fetching @lowdefy/server from npm.');
|
|
33
37
|
await fetchNpmTarball({
|
|
34
|
-
packageName
|
|
38
|
+
packageName,
|
|
35
39
|
version: context.lowdefyVersion,
|
|
36
40
|
directory: context.directories.server
|
|
37
41
|
});
|
|
38
42
|
context.print.log('Fetched @lowdefy/server from npm.');
|
|
39
|
-
return;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
export default getServer;
|
package/dist/utils/runCommand.js
CHANGED
|
@@ -14,29 +14,28 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import errorHandler from './errorHandler.js';
|
|
16
16
|
import startUp from './startUp.js';
|
|
17
|
-
const runCommand = ({ cliVersion })=>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
17
|
+
const runCommand = ({ cliVersion , handler })=>{
|
|
18
|
+
async function run(options, command) {
|
|
19
|
+
const context = {
|
|
20
|
+
cliVersion
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
await startUp({
|
|
24
|
+
context,
|
|
25
|
+
options,
|
|
26
|
+
command
|
|
27
|
+
});
|
|
28
|
+
const res = await handler({
|
|
29
|
+
context
|
|
30
|
+
});
|
|
31
|
+
return res;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
await errorHandler({
|
|
34
|
+
context,
|
|
35
|
+
error
|
|
36
|
+
});
|
|
38
37
|
}
|
|
39
|
-
return run;
|
|
40
38
|
}
|
|
41
|
-
;
|
|
39
|
+
return run;
|
|
40
|
+
};
|
|
42
41
|
export default runCommand;
|
package/dist/utils/startUp.js
CHANGED
|
@@ -21,12 +21,12 @@ import getLowdefyYaml from './getLowdefyYaml.js';
|
|
|
21
21
|
import getOptions from './getOptions.js';
|
|
22
22
|
import getPackageManager from './getPackageManager.js';
|
|
23
23
|
import getSendTelemetry from './getSendTelemetry.js';
|
|
24
|
-
import createPrint from './
|
|
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
28
|
context.print = createPrint();
|
|
29
|
-
context.
|
|
29
|
+
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
|
|
30
30
|
const { cliConfig , lowdefyVersion } = await getLowdefyYaml(context);
|
|
31
31
|
context.cliConfig = cliConfig;
|
|
32
32
|
context.lowdefyVersion = lowdefyVersion;
|
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.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy CLI",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -37,28 +37,29 @@
|
|
|
37
37
|
"start": "yarn node ./dist/index.js",
|
|
38
38
|
"prepare": "yarn build",
|
|
39
39
|
"swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
40
|
-
"test": "FORCE_COLOR=3
|
|
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.
|
|
45
|
-
"axios": "0.
|
|
43
|
+
"@lowdefy/helpers": "4.0.0-alpha.7",
|
|
44
|
+
"@lowdefy/node-utils": "4.0.0-alpha.7",
|
|
45
|
+
"axios": "0.25.0",
|
|
46
46
|
"chalk": "4.1.2",
|
|
47
|
-
"commander": "
|
|
47
|
+
"commander": "9.0.0",
|
|
48
48
|
"decompress": "4.2.1",
|
|
49
49
|
"decompress-targz": "4.1.1",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"ora": "5.4.1",
|
|
51
|
+
"uuid": "8.3.2",
|
|
52
|
+
"yaml": "2.0.0-10"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@jest/globals": "27.5.1",
|
|
55
56
|
"@swc/cli": "0.1.55",
|
|
56
|
-
"@swc/core": "1.2.
|
|
57
|
+
"@swc/core": "1.2.135",
|
|
57
58
|
"@swc/jest": "0.2.17",
|
|
58
|
-
"jest": "27.
|
|
59
|
+
"jest": "27.5.1"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
|
|
64
65
|
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2021 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 fs from 'fs';
|
|
16
|
-
import path from 'path';
|
|
17
|
-
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
|
|
18
|
-
import fetchNpmTarball from '../../utils/fetchNpmTarball.js';
|
|
19
|
-
async function getServer({ context }) {
|
|
20
|
-
let fetchServer = false;
|
|
21
|
-
const serverExists = fs.existsSync(path.join(context.directories.devServer, 'package.json'));
|
|
22
|
-
if (!serverExists) fetchServer = true;
|
|
23
|
-
if (serverExists) {
|
|
24
|
-
const serverPackageConfig = JSON.parse(await readFile(path.join(context.directories.devServer, 'package.json')));
|
|
25
|
-
if (serverPackageConfig.version !== context.lowdefyVersion) {
|
|
26
|
-
fetchServer = true;
|
|
27
|
-
context.print.warn(`Removing @lowdefy/server-dev with version ${serverPackageConfig.version}`);
|
|
28
|
-
await cleanDirectory(context.directories.devServer);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (fetchServer) {
|
|
32
|
-
context.print.spin('Fetching @lowdefy/server-dev from npm.');
|
|
33
|
-
await fetchNpmTarball({
|
|
34
|
-
packageName: '@lowdefy/server-dev',
|
|
35
|
-
version: context.lowdefyVersion,
|
|
36
|
-
directory: context.directories.devServer
|
|
37
|
-
});
|
|
38
|
-
context.print.log('Fetched @lowdefy/server-dev from npm.');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export default getServer;
|