lowdefy 4.0.0-alpha.1 → 4.0.0-alpha.4

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.
@@ -12,29 +12,28 @@
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 path from 'path';
16
- import fse from 'fs-extra';
17
- import getFederatedModule from '../../utils/getFederatedModule';
15
+ */ import getServer from './getServer.js';
16
+ import installServer from './installServer.js';
17
+ import runLowdefyBuild from './runLowdefyBuild.js';
18
+ import runNextBuild from './runNextBuild.js';
18
19
  async function build({ context }) {
19
- const { default: buildScript } = await getFederatedModule({
20
- module: 'build',
21
- packageName: '@lowdefy/build',
22
- version: context.lowdefyVersion,
20
+ context.print.info('Starting build.');
21
+ await getServer({
23
22
  context
24
23
  });
25
- context.print.log(`Cleaning block meta cache at "${path.resolve(context.cacheDirectory, './meta')}".`);
26
- await fse.emptyDir(path.resolve(context.cacheDirectory, './meta'));
27
- context.print.info('Starting build.');
28
- await buildScript({
29
- blocksServerUrl: context.options.blocksServerUrl,
30
- buildDirectory: context.buildDirectory,
31
- cacheDirectory: context.cacheDirectory,
32
- configDirectory: context.baseDirectory,
33
- logger: context.print,
34
- refResolver: context.options.refResolver
24
+ await installServer({
25
+ context
26
+ });
27
+ await runLowdefyBuild({
28
+ context
29
+ });
30
+ await installServer({
31
+ context
32
+ });
33
+ await runNextBuild({
34
+ context
35
35
  });
36
36
  await context.sendTelemetry();
37
- context.print.log(`Build artifacts saved at ${context.buildDirectory}.`);
38
37
  context.print.succeed(`Build successful.`);
39
38
  }
40
39
  export default build;
@@ -0,0 +1,42 @@
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.server, 'package.json'));
22
+ if (!serverExists) fetchServer = true;
23
+ if (serverExists) {
24
+ const serverPackageConfig = JSON.parse(await readFile(path.join(context.directories.server, 'package.json')));
25
+ if (serverPackageConfig.version !== context.lowdefyVersion) {
26
+ fetchServer = true;
27
+ context.print.warn(`Removing @lowdefy/server with version ${serverPackageConfig.version}`);
28
+ await cleanDirectory(context.directories.server);
29
+ }
30
+ }
31
+ if (fetchServer) {
32
+ context.print.spin('Fetching @lowdefy/server from npm.');
33
+ await fetchNpmTarball({
34
+ packageName: '@lowdefy/server',
35
+ version: context.lowdefyVersion,
36
+ directory: context.directories.server
37
+ });
38
+ context.print.log('Fetched @lowdefy/server from npm.');
39
+ return;
40
+ }
41
+ }
42
+ export default getServer;
@@ -0,0 +1,43 @@
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 spawnProcess from '../../utils/spawnProcess.js';
16
+ const args = {
17
+ npm: [
18
+ 'install',
19
+ '--legacy-peer-deps'
20
+ ],
21
+ yarn: [
22
+ 'install'
23
+ ]
24
+ };
25
+ async function installServer({ context }) {
26
+ context.print.spin(`Running ${context.packageManager} install.`);
27
+ try {
28
+ await spawnProcess({
29
+ context,
30
+ command: context.packageManager,
31
+ args: args[context.packageManager],
32
+ processOptions: {
33
+ cwd: context.directories.server
34
+ },
35
+ silent: false
36
+ });
37
+ } catch (error) {
38
+ console.log(error);
39
+ throw new Error(`${context.packageManager} install failed.`);
40
+ }
41
+ context.print.log(`${context.packageManager} install successful.`);
42
+ }
43
+ export default installServer;
@@ -0,0 +1,41 @@
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 spawnProcess from '../../utils/spawnProcess.js';
16
+ async function runLowdefyBuild({ context }) {
17
+ context.print.log('Running Lowdefy build.');
18
+ try {
19
+ await spawnProcess({
20
+ context,
21
+ command: context.packageManager,
22
+ args: [
23
+ 'run',
24
+ 'build:lowdefy'
25
+ ],
26
+ processOptions: {
27
+ cwd: context.directories.server,
28
+ env: {
29
+ ...process.env,
30
+ LOWDEFY_BUILD_DIRECTORY: context.directories.build,
31
+ LOWDEFY_CONFIG_DIRECTORY: context.directories.base
32
+ }
33
+ },
34
+ silent: false
35
+ });
36
+ } catch (error) {
37
+ throw new Error('Lowdefy build failed.');
38
+ }
39
+ context.print.log('Lowdefy build successful.');
40
+ }
41
+ export default runLowdefyBuild;
@@ -0,0 +1,36 @@
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 spawnProcess from '../../utils/spawnProcess.js';
16
+ async function runNextBuild({ context }) {
17
+ context.print.log('Running Next build.');
18
+ try {
19
+ await spawnProcess({
20
+ context,
21
+ command: context.packageManager,
22
+ args: [
23
+ 'run',
24
+ 'build:next'
25
+ ],
26
+ processOptions: {
27
+ cwd: context.directories.server
28
+ },
29
+ silent: false
30
+ });
31
+ } catch (error) {
32
+ throw new Error('Next build failed.');
33
+ }
34
+ context.print.log('Next build successful.');
35
+ }
36
+ export default runNextBuild;
package/dist/index.js CHANGED
@@ -14,35 +14,16 @@
14
14
  limitations under the License.
15
15
  */ import { readFile } from '@lowdefy/node-utils';
16
16
  import program from 'commander';
17
- // import build from './commands/build/build.js';
17
+ import build from './commands/build/build.js';
18
18
  // import dev from './commands/dev/dev.js';
19
19
  import init from './commands/init/init.js';
20
20
  import runCommand from './utils/runCommand.js';
21
21
  const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url).pathname));
22
22
  const { description , version } = packageJson;
23
23
  program.name('lowdefy').description(description).version(version, '-v, --version');
24
- // program
25
- // .command('build')
26
- // .description('Build a Lowdefy deployment.')
27
- // .usage(`[options]`)
28
- // .option(
29
- // '--base-directory <base-directory>',
30
- // 'Change base directory. Default is the current working directory.'
31
- // )
32
- // .option(
33
- // '--blocks-server-url <blocks-server-url>',
34
- // 'The URL from where Lowdefy blocks will be served.'
35
- // )
36
- // .option('--disable-telemetry', 'Disable telemetry.')
37
- // .option(
38
- // '--output-directory <output-directory>',
39
- // 'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".'
40
- // )
41
- // .option(
42
- // '--ref-resolver <ref-resolver-function-path>',
43
- // 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'
44
- // )
45
- // .action(runCommand(build));
24
+ program.command('build').description('Build a Lowdefy deployment.').usage(`[options]`).option('--base-directory <base-directory>', 'Change base directory. Default is the current working directory.').option('--blocks-server-url <blocks-server-url>', 'The URL from where Lowdefy blocks will be served.').option('--disable-telemetry', 'Disable telemetry.').option('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".').option('--package-manager <package-manager>', 'The package manager to user. 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.').action(runCommand({
25
+ cliVersion: version
26
+ })(build));
46
27
  // program
47
28
  // .command('dev')
48
29
  // .description('Start a Lowdefy development server.')
@@ -69,7 +50,7 @@ program.name('lowdefy').description(description).version(version, '-v, --version
69
50
  // '--watch-ignore <paths...>',
70
51
  // 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.'
71
52
  // )
72
- // .action(runCommand(dev));
53
+ // .action(runCommand({ cliVersion: version })(dev));
73
54
  program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
74
55
  cliVersion: version
75
56
  })(init));
@@ -14,6 +14,14 @@
14
14
  limitations under the License.
15
15
  */ import axios from 'axios';
16
16
  async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print }) {
17
+ if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) {
18
+ print.warn(`
19
+ ---------------------------------------------------
20
+ You are using an experimental version of Lowdefy.
21
+ Features may change at any time.
22
+ ---------------------------------------------------`);
23
+ return;
24
+ }
17
25
  const registryUrl = 'https://registry.npmjs.org/lowdefy';
18
26
  try {
19
27
  const packageInfo = await axios.get(registryUrl);
@@ -39,4 +47,7 @@ async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print })
39
47
  print.warn('Failed to check for latest Lowdefy version.');
40
48
  }
41
49
  }
50
+ function isExperimentalVersion(version) {
51
+ return version.includes('alpha') || version.includes('beta') || version.includes('rc');
52
+ }
42
53
  export default checkForUpdatedVersions;
@@ -49,7 +49,8 @@ async function fetchNpmTarball({ packageName , version , directory }) {
49
49
  await decompress(tarball.data, directory, {
50
50
  plugins: [
51
51
  decompressTargz()
52
- ]
52
+ ],
53
+ strip: 1
53
54
  });
54
55
  }
55
56
  export default fetchNpmTarball;
@@ -14,14 +14,17 @@
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
16
  function getDirectories({ baseDirectory , options }) {
17
- let buildDirectory;
17
+ let dotLowdefy;
18
18
  if (options.outputDirectory) {
19
- buildDirectory = path.resolve(options.outputDirectory);
19
+ dotLowdefy = path.resolve(options.outputDirectory);
20
20
  } else {
21
- buildDirectory = path.resolve(baseDirectory, './.lowdefy/build');
21
+ dotLowdefy = path.resolve(baseDirectory, '.lowdefy');
22
22
  }
23
23
  return {
24
- buildDirectory
24
+ base: baseDirectory,
25
+ build: path.join(dotLowdefy, 'server', 'build'),
26
+ dotLowdefy,
27
+ server: path.join(dotLowdefy, 'server')
25
28
  };
26
29
  }
27
30
  export default getDirectories;
@@ -41,8 +41,8 @@ async function getLowdefyYaml({ baseDirectory , command }) {
41
41
  if (!lowdefy.lowdefy) {
42
42
  throw new Error(`No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.`);
43
43
  }
44
- if (!type.isString(lowdefy.lowdefy) || !lowdefy.lowdefy.match(/\d+\.\d+\.\d+(-\w+\.\d+)?/)) {
45
- throw new Error(`Version number specified in "lowdefy.yaml" file is not valid. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
44
+ if (!type.isString(lowdefy.lowdefy)) {
45
+ throw new Error(`Version number specified in "lowdefy.yaml" file should be a string. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
46
46
  }
47
47
  return {
48
48
  lowdefyVersion: lowdefy.lowdefy,
@@ -0,0 +1,54 @@
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
+ */ // 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;
@@ -60,6 +60,7 @@ function createBasicPrint() {
60
60
  // Memoise print so that error handler can get the same spinner object
61
61
  let print;
62
62
  function createPrint() {
63
+ // TODO: Add debug
63
64
  if (print) return print;
64
65
  if (process.env.CI === 'true') {
65
66
  print = createBasicPrint();
@@ -0,0 +1,49 @@
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 { spawn } from 'child_process';
16
+ async function spawnProcess({ context , command , args , processOptions , silent }) {
17
+ return new Promise((resolve, reject)=>{
18
+ const process = spawn(command, args, processOptions);
19
+ process.stdout.on('data', (data)=>{
20
+ if (!silent) {
21
+ data.toString('utf8').split('\n').forEach((line)=>{
22
+ if (line) {
23
+ context.print.log(line);
24
+ }
25
+ });
26
+ }
27
+ });
28
+ process.stderr.on('data', (data)=>{
29
+ if (!silent) {
30
+ data.toString('utf8').split('\n').forEach((line)=>{
31
+ if (line) {
32
+ context.print.warn(line);
33
+ }
34
+ });
35
+ }
36
+ });
37
+ process.on('error', (error)=>{
38
+ console.log(error);
39
+ reject(error);
40
+ });
41
+ process.on('exit', (code)=>{
42
+ if (code !== 0) {
43
+ reject(new Error(`${command} exited with code ${code}`));
44
+ }
45
+ resolve();
46
+ });
47
+ });
48
+ }
49
+ export default spawnProcess;
@@ -19,6 +19,7 @@ import getCliJson from './getCliJson.js';
19
19
  import getDirectories from './getDirectories.js';
20
20
  import getLowdefyYaml from './getLowdefyYaml.js';
21
21
  import getOptions from './getOptions.js';
22
+ import getPackageManager from './getPackageManager.js';
22
23
  import getSendTelemetry from './getSendTelemetry.js';
23
24
  import createPrint from './print.js';
24
25
  async function startUp({ context , options ={
@@ -33,8 +34,8 @@ async function startUp({ context , options ={
33
34
  const { appId } = await getCliJson(context);
34
35
  context.appId = appId;
35
36
  context.options = getOptions(context);
36
- const { buildDirectory } = getDirectories(context);
37
- context.buildDirectory = buildDirectory;
37
+ context.directories = getDirectories(context);
38
+ context.packageManager = getPackageManager(context);
38
39
  await checkForUpdatedVersions(context);
39
40
  context.sendTelemetry = getSendTelemetry(context);
40
41
  if (type.isNone(lowdefyVersion)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lowdefy",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.4",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy CLI",
6
6
  "homepage": "https://lowdefy.com",
@@ -40,8 +40,8 @@
40
40
  "test": "FORCE_COLOR=3 jest --coverage"
41
41
  },
42
42
  "dependencies": {
43
- "@lowdefy/helpers": "4.0.0-alpha.1",
44
- "@lowdefy/node-utils": "4.0.0-alpha.1",
43
+ "@lowdefy/helpers": "4.0.0-alpha.4",
44
+ "@lowdefy/node-utils": "4.0.0-alpha.4",
45
45
  "axios": "0.24.0",
46
46
  "chalk": "4.1.2",
47
47
  "chokidar": "3.5.2",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
67
+ "gitHead": "537d166ba3f6e017b8a61c2a7e5c12fd0a48bf67"
68
68
  }
@@ -1,21 +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
- */ function checkChildProcessError({ context , processOutput , message }) {
16
- if (processOutput.status === 1) {
17
- context.print.error(processOutput.stderr.toString('utf8'));
18
- throw new Error(message);
19
- }
20
- }
21
- export default checkChildProcessError;