mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
feat(cli): Add config option for server-dev and server directories.
This commit is contained in:
parent
5bc113b18c
commit
07902b0e06
17
package.json
17
package.json
@ -41,10 +41,19 @@
|
||||
"lerna:publish": "lerna publish from-git",
|
||||
"postversion": "yarn install",
|
||||
"prettier": "prettier --config .prettierrc --write **/*.js",
|
||||
"start:server-dev": "yarn workspace @lowdefy/server-dev start --package-manager yarn --config-directory ../../app",
|
||||
"start": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../../app && yarn && yarn workspace @lowdefy/server build:next && yarn workspace @lowdefy/server start",
|
||||
"start:dev": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../../app && yarn && yarn workspace @lowdefy/server dev",
|
||||
"start:dev-docs": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../docs && yarn && yarn workspace @lowdefy/server dev",
|
||||
"start": "yarn start:server:app",
|
||||
"start:cli:build:app": "yarn workspace lowdefy start build --config-directory ../../app --server-directory ../server --output-directory ../",
|
||||
"start:cli:build:docs": "yarn workspace lowdefy start build --config-directory ../docs --server-directory ../server --output-directory ../",
|
||||
"start:cli:dev:app": "yarn workspace lowdefy start dev --config-directory ../../app --dev-directory ../server-dev",
|
||||
"start:cli:dev:docs": "yarn workspace lowdefy start dev --config-directory ../docs --dev-directory ../server-dev",
|
||||
"start:cli:start:app": "yarn workspace lowdefy start start --config-directory ../../app --server-directory ../server --output-directory ../",
|
||||
"start:cli:start:docs": "yarn workspace lowdefy start start --config-directory ../docs --server-directory ../server --output-directory ../",
|
||||
"start:server-dev:app": "yarn workspace @lowdefy/server-dev start --package-manager yarn --config-directory ../../app",
|
||||
"start:server-dev:docs": "yarn workspace @lowdefy/server-dev start --package-manager yarn --config-directory ../docs",
|
||||
"start:server:app": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../../app && yarn && yarn workspace @lowdefy/server build:next && yarn workspace @lowdefy/server start",
|
||||
"start:server:docs": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../docs && yarn && yarn workspace @lowdefy/server build:next && yarn workspace @lowdefy/server start",
|
||||
"start:server:next-dev:app": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../../app && yarn && yarn workspace @lowdefy/server dev",
|
||||
"start:server:next-dev:docs": "yarn workspace @lowdefy/server build:lowdefy --config-directory ../docs && yarn && yarn workspace @lowdefy/server dev",
|
||||
"test": "lerna run test"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -14,14 +14,14 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import getServer from './getServer.js';
|
||||
import getServer from '../../utils/getServer.js';
|
||||
import installServer from './installServer.js';
|
||||
import runLowdefyBuild from './runLowdefyBuild.js';
|
||||
import runNextBuild from './runNextBuild.js';
|
||||
|
||||
async function build({ context }) {
|
||||
context.print.info('Starting build.');
|
||||
await getServer({ context });
|
||||
await getServer({ context, packageName: '@lowdefy/server' });
|
||||
await installServer({ context });
|
||||
await runLowdefyBuild({ context });
|
||||
await installServer({ context });
|
||||
|
@ -14,13 +14,13 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import getServer from './getServer.js';
|
||||
import installServer from './installServer.js';
|
||||
import runDevServer from './runDevServer.js';
|
||||
import getServer from '../../utils/getServer.js';
|
||||
|
||||
async function dev({ context }) {
|
||||
context.print.info('Starting development server.');
|
||||
await getServer({ context });
|
||||
await getServer({ context, packageName: '@lowdefy/server-dev' });
|
||||
await installServer({ context });
|
||||
context.sendTelemetry();
|
||||
await runDevServer({ context });
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
|
||||
import fetchNpmTarball from '../../utils/fetchNpmTarball.js';
|
||||
|
||||
async function getServer({ context }) {
|
||||
let fetchServer = false;
|
||||
|
||||
const serverExists = fs.existsSync(path.join(context.directories.devServer, 'package.json'));
|
||||
if (!serverExists) fetchServer = true;
|
||||
|
||||
if (serverExists) {
|
||||
const serverPackageConfig = JSON.parse(
|
||||
await readFile(path.join(context.directories.devServer, 'package.json'))
|
||||
);
|
||||
if (serverPackageConfig.version !== context.lowdefyVersion) {
|
||||
fetchServer = true;
|
||||
context.print.warn(
|
||||
`Removing @lowdefy/server-dev with version ${serverPackageConfig.version}`
|
||||
);
|
||||
await cleanDirectory(context.directories.devServer);
|
||||
}
|
||||
}
|
||||
|
||||
if (fetchServer) {
|
||||
context.print.spin('Fetching @lowdefy/server-dev from npm.');
|
||||
await fetchNpmTarball({
|
||||
packageName: '@lowdefy/server-dev',
|
||||
version: context.lowdefyVersion,
|
||||
directory: context.directories.devServer,
|
||||
});
|
||||
context.print.log('Fetched @lowdefy/server-dev from npm.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export default getServer;
|
@ -29,7 +29,7 @@ async function installServer({ context }) {
|
||||
command: context.packageManager, // npm or yarn
|
||||
args: args[context.packageManager],
|
||||
processOptions: {
|
||||
cwd: context.directories.devServer,
|
||||
cwd: context.directories.dev,
|
||||
},
|
||||
silent: false,
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ async function runDevServer({ context }) {
|
||||
args: ['run', 'start'],
|
||||
command: context.packageManager, // npm or yarn
|
||||
processOptions: {
|
||||
cwd: context.directories.devServer,
|
||||
cwd: context.directories.dev,
|
||||
env: {
|
||||
...process.env,
|
||||
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
||||
|
@ -55,6 +55,10 @@ program
|
||||
'--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({ cliVersion, handler: build }));
|
||||
|
||||
program
|
||||
@ -83,6 +87,10 @@ program
|
||||
'--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({ cliVersion, handler: dev }));
|
||||
|
||||
program
|
||||
@ -109,6 +117,10 @@ program
|
||||
'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({ cliVersion, handler: start }));
|
||||
|
||||
program.parse(process.argv);
|
||||
|
@ -27,8 +27,10 @@ function getDirectories({ configDirectory, options }) {
|
||||
config: configDirectory,
|
||||
build: path.join(dotLowdefy, 'server', 'build'),
|
||||
dotLowdefy,
|
||||
server: path.join(dotLowdefy, 'server'),
|
||||
devServer: path.join(dotLowdefy, 'dev'),
|
||||
server: options.serverDirectory
|
||||
? path.resolve(options.serverDirectory)
|
||||
: path.join(dotLowdefy, 'server'),
|
||||
dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ test('default directories', () => {
|
||||
expect(directories).toEqual({
|
||||
build: '/test/config/.lowdefy/server/build',
|
||||
config: '/test/config',
|
||||
devServer: '/test/config/.lowdefy/dev',
|
||||
dev: '/test/config/.lowdefy/dev',
|
||||
dotLowdefy: '/test/config/.lowdefy',
|
||||
server: '/test/config/.lowdefy/server',
|
||||
});
|
||||
@ -42,8 +42,42 @@ test('specify outputDirectory in options', () => {
|
||||
expect(directories).toEqual({
|
||||
build: '/test/out/server/build',
|
||||
config: '/test/config',
|
||||
devServer: '/test/out/dev',
|
||||
dev: '/test/out/dev',
|
||||
dotLowdefy: '/test/out',
|
||||
server: '/test/out/server',
|
||||
});
|
||||
});
|
||||
|
||||
test('specify serverDirectory in options', () => {
|
||||
const directories = getDirectories({
|
||||
configDirectory: '/test/config',
|
||||
options: {
|
||||
serverDirectory: '/test/server',
|
||||
},
|
||||
});
|
||||
|
||||
expect(directories).toEqual({
|
||||
build: '/test/config/.lowdefy/server/build',
|
||||
config: '/test/config',
|
||||
dev: '/test/config/.lowdefy/dev',
|
||||
dotLowdefy: '/test/config/.lowdefy',
|
||||
server: '/test/server',
|
||||
});
|
||||
});
|
||||
|
||||
test('specify devDirectory in options', () => {
|
||||
const directories = getDirectories({
|
||||
configDirectory: '/test/config',
|
||||
options: {
|
||||
devDirectory: '/test/dev',
|
||||
},
|
||||
});
|
||||
|
||||
expect(directories).toEqual({
|
||||
build: '/test/config/.lowdefy/server/build',
|
||||
config: '/test/config',
|
||||
dev: '/test/dev',
|
||||
dotLowdefy: '/test/config/.lowdefy',
|
||||
server: '/test/config/.lowdefy/server',
|
||||
});
|
||||
});
|
||||
|
@ -17,9 +17,14 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
|
||||
import fetchNpmTarball from '../../utils/fetchNpmTarball.js';
|
||||
import fetchNpmTarball from './fetchNpmTarball.js';
|
||||
|
||||
async function getServer({ context, packageName }) {
|
||||
if (context.lowdefyVersion === 'local') {
|
||||
context.print.warn(`Running local ${packageName}.`);
|
||||
return;
|
||||
}
|
||||
|
||||
async function getServer({ context }) {
|
||||
let fetchServer = false;
|
||||
|
||||
const serverExists = fs.existsSync(path.join(context.directories.server, 'package.json'));
|
||||
@ -39,12 +44,11 @@ async function getServer({ context }) {
|
||||
if (fetchServer) {
|
||||
context.print.spin('Fetching @lowdefy/server from npm.');
|
||||
await fetchNpmTarball({
|
||||
packageName: '@lowdefy/server',
|
||||
packageName,
|
||||
version: context.lowdefyVersion,
|
||||
directory: context.directories.server,
|
||||
});
|
||||
context.print.log('Fetched @lowdefy/server from npm.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ test('startUp, options empty', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './.lowdefy/server/build'),
|
||||
config: path.resolve(process.cwd()),
|
||||
devServer: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dev: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './.lowdefy'),
|
||||
server: path.resolve(process.cwd(), './.lowdefy/server'),
|
||||
},
|
||||
@ -104,7 +104,7 @@ test('startUp, options undefined', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './.lowdefy/server/build'),
|
||||
config: path.resolve(process.cwd()),
|
||||
devServer: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dev: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './.lowdefy'),
|
||||
server: path.resolve(process.cwd(), './.lowdefy/server'),
|
||||
},
|
||||
@ -150,7 +150,7 @@ test('startUp, options configDirectory', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './configDirectory/.lowdefy/server/build'),
|
||||
config: path.resolve(process.cwd(), './configDirectory'),
|
||||
devServer: path.resolve(process.cwd(), './configDirectory/.lowdefy/dev'),
|
||||
dev: path.resolve(process.cwd(), './configDirectory/.lowdefy/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './configDirectory/.lowdefy'),
|
||||
server: path.resolve(process.cwd(), './configDirectory/.lowdefy/server'),
|
||||
},
|
||||
@ -180,7 +180,7 @@ test('startUp, options outputDirectory', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './outputDirectory/server/build'),
|
||||
config: path.resolve(process.cwd()),
|
||||
devServer: path.resolve(process.cwd(), './outputDirectory/dev'),
|
||||
dev: path.resolve(process.cwd(), './outputDirectory/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './outputDirectory'),
|
||||
server: path.resolve(process.cwd(), './outputDirectory/server'),
|
||||
},
|
||||
@ -220,7 +220,7 @@ test('startUp, options configDirectory and outputDirectory', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './outputDirectory/server/build'),
|
||||
config: path.resolve(process.cwd(), './configDirectory'),
|
||||
devServer: path.resolve(process.cwd(), './outputDirectory/dev'),
|
||||
dev: path.resolve(process.cwd(), './outputDirectory/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './outputDirectory'),
|
||||
server: path.resolve(process.cwd(), './outputDirectory/server'),
|
||||
},
|
||||
@ -254,7 +254,7 @@ test('startUp, no lowdefyVersion returned', async () => {
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './.lowdefy/server/build'),
|
||||
config: path.resolve(process.cwd()),
|
||||
devServer: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dev: path.resolve(process.cwd(), './.lowdefy/dev'),
|
||||
dotLowdefy: path.resolve(process.cwd(), './.lowdefy'),
|
||||
server: path.resolve(process.cwd(), './.lowdefy/server'),
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user