mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
Merge branch 'develop' into link-component
This commit is contained in:
commit
0ab9013754
@ -26,6 +26,7 @@ const argv = yargs(hideBin(process.argv)).argv;
|
||||
async function run() {
|
||||
await build({
|
||||
logger: console,
|
||||
refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
|
||||
directories: {
|
||||
build: path.resolve(
|
||||
argv.buildDirectory ||
|
||||
|
@ -27,6 +27,7 @@ async function runLowdefyBuild({ context }) {
|
||||
cwd: context.directories.server,
|
||||
env: {
|
||||
...process.env,
|
||||
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
||||
LOWDEFY_DIRECTORY_BUILD: context.directories.build,
|
||||
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
||||
LOWDEFY_DIRECTORY_SERVER: context.directories.server,
|
||||
|
@ -17,7 +17,6 @@
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
|
||||
async function runDevServer({ context }) {
|
||||
// TODO: Pass packageManager as option
|
||||
await spawnProcess({
|
||||
logger: context.print,
|
||||
args: ['run', 'start'],
|
||||
@ -26,8 +25,11 @@ async function runDevServer({ context }) {
|
||||
cwd: context.directories.devServer,
|
||||
env: {
|
||||
...process.env,
|
||||
LOWDEFY_PACKAGE_MANAGER: context.packageManager,
|
||||
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
||||
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
||||
LOWDEFY_PACKAGE_MANAGER: context.packageManager,
|
||||
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
||||
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
||||
PORT: context.options.port,
|
||||
},
|
||||
},
|
||||
|
@ -71,20 +71,17 @@ program
|
||||
'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.')
|
||||
// TODO:
|
||||
.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.'
|
||||
)
|
||||
// TODO:
|
||||
.option(
|
||||
'--watch <paths...>',
|
||||
'A list of paths to files or directories that should be watched for changes.'
|
||||
'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.'
|
||||
)
|
||||
// TODO:
|
||||
.option(
|
||||
'--watch-ignore <paths...>',
|
||||
'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.'
|
||||
'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.'
|
||||
)
|
||||
.action(runCommand({ cliVersion: version })(dev));
|
||||
|
||||
|
@ -30,11 +30,12 @@ import restartServer from './processes/restartServer.mjs';
|
||||
import shutdownServer from './processes/shutdownServer.mjs';
|
||||
import startWatchers from './processes/startWatchers.mjs';
|
||||
|
||||
const argv = yargs(hideBin(process.argv)).argv;
|
||||
const argv = yargs(hideBin(process.argv)).array('watch').array('watchIgnore').argv;
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
async function getContext() {
|
||||
const { verbose = false } = argv;
|
||||
const env = process.env;
|
||||
|
||||
const context = {
|
||||
bin: {
|
||||
// TODO: The string replace is a little hacky and will fail if the location of the bin changes,
|
||||
@ -43,15 +44,23 @@ async function getContext() {
|
||||
},
|
||||
directories: {
|
||||
build: path.resolve(process.cwd(), './build'),
|
||||
config: path.resolve(
|
||||
argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()
|
||||
),
|
||||
config: path.resolve(argv.configDirectory || env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
|
||||
server: process.cwd(),
|
||||
},
|
||||
packageManager: argv.packageManager || process.env.LOWDEFY_PACKAGE_MANAGER || 'npm',
|
||||
port: argv.port || process.env.PORT || 3000,
|
||||
verbose,
|
||||
version: process.env.npm_package_version,
|
||||
options: {
|
||||
port: argv.port || env.PORT || 3000,
|
||||
refResolver: argv.refResolver || env.LOWDEFY_BUILD_REF_RESOLVER,
|
||||
watch:
|
||||
argv.watch || env.LOWDEFY_SERVER_DEV_WATCH ? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH) : [],
|
||||
watchIgnore:
|
||||
argv.watchIgnore || env.LOWDEFY_SERVER_DEV_WATCH_IGNORE
|
||||
? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH_IGNORE)
|
||||
: [],
|
||||
// TODO: read option from from env
|
||||
verbose: argv.verbose || false,
|
||||
},
|
||||
packageManager: argv.packageManager || env.LOWDEFY_PACKAGE_MANAGER || 'npm',
|
||||
version: env.npm_package_version,
|
||||
};
|
||||
|
||||
context.initialBuild = initialBuild(context);
|
||||
|
@ -21,14 +21,14 @@ const args = {
|
||||
yarn: ['install'],
|
||||
};
|
||||
|
||||
function installPlugins({ packageManager, verbose }) {
|
||||
function installPlugins({ packageManager, options }) {
|
||||
return async () => {
|
||||
console.log('Installing plugins...');
|
||||
await spawnProcess({
|
||||
logger: console,
|
||||
command: packageManager, // npm or yarn
|
||||
args: args[packageManager],
|
||||
silent: !verbose,
|
||||
silent: !options.verbose,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
|
||||
function lowdefyBuild({ bin, directories }) {
|
||||
function lowdefyBuild({ bin, directories, options }) {
|
||||
return async () => {
|
||||
await spawnProcess({
|
||||
command: 'node',
|
||||
@ -25,6 +25,7 @@ function lowdefyBuild({ bin, directories }) {
|
||||
processOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
LOWDEFY_BUILD_REF_RESOLVER: options.refResolver,
|
||||
LOWDEFY_DIRECTORY_BUILD: directories.build,
|
||||
LOWDEFY_DIRECTORY_CONFIG: directories.config,
|
||||
LOWDEFY_DIRECTORY_SERVER: process.cwd(),
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
|
||||
function nextBuild(context) {
|
||||
function nextBuild({ bin, options }) {
|
||||
return async () => {
|
||||
console.log('Building app...');
|
||||
await spawnProcess({
|
||||
logger: console,
|
||||
command: 'node',
|
||||
args: [context.bin.next, 'build'],
|
||||
silent: !context.verbose,
|
||||
args: [bin.next, 'build'],
|
||||
silent: !options.verbose,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ function startServerProcess(context) {
|
||||
env: {
|
||||
...process.env,
|
||||
...context.serverEnv,
|
||||
PORT: context.port,
|
||||
PORT: context.options.port,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -80,7 +80,7 @@ async function run() {
|
||||
try {
|
||||
const serverPromise = startServer(context);
|
||||
await wait(800);
|
||||
opener(`http://localhost:${context.port}`);
|
||||
opener(`http://localhost:${context.options.port}`);
|
||||
await serverPromise;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
@ -35,10 +35,10 @@ function lowdefyBuildWatcher(context) {
|
||||
await context.lowdefyBuild();
|
||||
context.reloadClients();
|
||||
};
|
||||
// TODO: Add ignored and watch paths
|
||||
return setupWatcher({
|
||||
callback,
|
||||
watchPaths: [context.directories.config],
|
||||
ignorePaths: context.options.watchIgnore,
|
||||
watchPaths: [context.directories.config, ...context.options.watch],
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user