2
0
mirror of https://github.com/lowdefy/lowdefy.git synced 2025-03-19 15:01:06 +08:00

feat(cli): Rename base-directory to config-directory.

BREAKING CHANGE: Rename base-directory to config-directory.
This commit is contained in:
Gervwyk 2022-01-21 18:29:33 +02:00
parent cd2b9ad395
commit f09c569f0e
12 changed files with 74 additions and 72 deletions

@ -36,13 +36,13 @@ program
.description('Build a Lowdefy production app.')
.usage(`[options]`)
.option(
'--base-directory <base-directory>',
'--config-directory <config-directory>',
'Change base 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 "<base-directory>/.lowdefy".'
'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".'
)
.option(
'--package-manager <package-manager>',
@ -59,7 +59,7 @@ program
.description('Start a Lowdefy development server.')
.usage(`[options]`)
.option(
'--base-directory <base-directory>',
'--config-directory <config-directory>',
'Change base directory. Default is the current working directory.'
)
.option('--disable-telemetry', 'Disable telemetry.')
@ -97,13 +97,13 @@ program
.description('Start a Lowdefy production app.')
.usage(`[options]`)
.option(
'--base-directory <base-directory>',
'--config-directory <config-directory>',
'Change base 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 "<base-directory>/.lowdefy".'
'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".'
)
.option(
'--package-manager <package-manager>',

@ -27,7 +27,7 @@ async function mockStartUpImp({ context, options = {} }) {
log: jest.fn(),
};
context.baseDirectory = options.baseDirectory || 'baseDirectory';
context.configDirectory = options.configDirectory || 'configDirectory';
context.cliConfig = {};
context.lowdefyVersion = 'lowdefyVersion';
@ -35,8 +35,8 @@ async function mockStartUpImp({ context, options = {} }) {
context.appId = 'appId';
context.options = options;
context.cacheDirectory = `${context.baseDirectory}/cacheDirectory`;
context.buildDirectory = `${context.baseDirectory}/buildDirectory`;
context.cacheDirectory = `${context.configDirectory}/cacheDirectory`;
context.buildDirectory = `${context.configDirectory}/buildDirectory`;
context.sendTelemetry = jest.fn();

@ -18,8 +18,8 @@ import path from 'path';
import { readFile, writeFile } from '@lowdefy/node-utils';
import { v4 as uuid } from 'uuid';
async function getCliJson({ baseDirectory }) {
const filePath = path.resolve(baseDirectory, './.lowdefy/cli.json');
async function getCliJson({ configDirectory }) {
const filePath = path.resolve(configDirectory, './.lowdefy/cli.json');
const cliJson = await readFile(filePath);
if (!cliJson) {
const appId = uuid();

@ -35,13 +35,13 @@ jest.mock('uuid', () => ({
v4: () => 'uuidv4',
}));
const baseDirectory = process.cwd();
const configDirectory = process.cwd();
test('getCliJson, no file exists', async () => {
readFile.mockImplementation(() => {
return null;
});
const res = await getCliJson({ baseDirectory });
const res = await getCliJson({ configDirectory });
expect(res).toEqual({ appId: 'uuidv4' });
expect(writeFile.mock.calls).toEqual([
[
@ -59,7 +59,7 @@ test('getCliJson, no file exists', async () => {
return `{"appId": "appId"}`;
}
});
const res = await getCliJson({ baseDirectory });
const res = await getCliJson({ configDirectory });
expect(res).toEqual({ appId: 'appId' });
expect(writeFile.mock.calls).toEqual([]);
});

@ -16,15 +16,15 @@
import path from 'path';
function getDirectories({ baseDirectory, options }) {
function getDirectories({ configDirectory, options }) {
let dotLowdefy;
if (options.outputDirectory) {
dotLowdefy = path.resolve(options.outputDirectory);
} else {
dotLowdefy = path.resolve(baseDirectory, '.lowdefy');
dotLowdefy = path.resolve(configDirectory, '.lowdefy');
}
return {
base: baseDirectory,
base: configDirectory,
build: path.join(dotLowdefy, 'server', 'build'),
dotLowdefy,
server: path.join(dotLowdefy, 'server'),

@ -18,7 +18,7 @@ import getDirectories from './getDirectories.js';
test('default directories', () => {
const { cacheDirectory, buildDirectory } = getDirectories({
baseDirectory: '/test/base',
configDirectory: '/test/base',
options: {},
});
@ -28,7 +28,7 @@ test('default directories', () => {
test('specify outputDirectory in options', () => {
const { cacheDirectory, buildDirectory } = getDirectories({
baseDirectory: '/test/base',
configDirectory: '/test/base',
options: {
outputDirectory: '/test/build',
},

@ -19,15 +19,15 @@ import { get, type } from '@lowdefy/helpers';
import { readFile } from '@lowdefy/node-utils';
import YAML from 'js-yaml';
async function getLowdefyYaml({ baseDirectory, command }) {
let lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yaml'));
async function getLowdefyYaml({ configDirectory, command }) {
let lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yaml'));
if (!lowdefyYaml) {
lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yml'));
lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yml'));
}
if (!lowdefyYaml) {
if (!['init'].includes(command)) {
throw new Error(
`Could not find "lowdefy.yaml" file in specified base directory ${baseDirectory}.`
`Could not find "lowdefy.yaml" file in specified base directory ${configDirectory}.`
);
}
return { cliConfig: {} };

@ -31,7 +31,7 @@ beforeEach(() => {
readFile.mockReset();
});
const baseDirectory = process.cwd();
const configDirectory = process.cwd();
test('get version from yaml file', async () => {
readFile.mockImplementation((filePath) => {
@ -42,7 +42,7 @@ test('get version from yaml file', async () => {
}
return null;
});
const config = await getLowdefyYaml({ baseDirectory });
const config = await getLowdefyYaml({ configDirectory });
expect(config).toEqual({ lowdefyVersion: '1.0.0', cliConfig: {} });
});
@ -55,7 +55,9 @@ test('get version from yaml file, base dir specified', async () => {
}
return null;
});
const config = await getLowdefyYaml({ baseDirectory: path.resolve(process.cwd(), './baseDir') });
const config = await getLowdefyYaml({
configDirectory: path.resolve(process.cwd(), './baseDir'),
});
expect(config).toEqual({ lowdefyVersion: '1.0.0', cliConfig: {} });
});
@ -71,7 +73,7 @@ test('could not find lowdefy.yaml in cwd', async () => {
lowdefy: 1.0.0
`;
});
await expect(getLowdefyYaml({ baseDirectory })).rejects.toThrow(
await expect(getLowdefyYaml({ configDirectory })).rejects.toThrow(
'Could not find "lowdefy.yaml" file in specified base directory'
);
});
@ -89,7 +91,7 @@ test('could not find lowdefy.yaml in base dir', async () => {
`;
});
await expect(
getLowdefyYaml({ baseDirectory: path.resolve(process.cwd(), './baseDir') })
getLowdefyYaml({ configDirectory: path.resolve(process.cwd(), './baseDir') })
).rejects.toThrow('Could not find "lowdefy.yaml" file in specified base directory');
});
@ -104,7 +106,7 @@ test('lowdefy.yaml is invalid yaml', async () => {
}
return null;
});
await expect(getLowdefyYaml({ baseDirectory })).rejects.toThrow(
await expect(getLowdefyYaml({ configDirectory })).rejects.toThrow(
'Could not parse "lowdefy.yaml" file. Received error '
);
});
@ -120,7 +122,7 @@ test('No version specified', async () => {
}
return null;
});
await expect(getLowdefyYaml({ baseDirectory })).rejects.toThrow(
await expect(getLowdefyYaml({ configDirectory })).rejects.toThrow(
'No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.'
);
});
@ -134,7 +136,7 @@ test('Version is not a string', async () => {
}
return null;
});
await expect(getLowdefyYaml({ baseDirectory })).rejects.toThrow(
await expect(getLowdefyYaml({ configDirectory })).rejects.toThrow(
'Version number specified in "lowdefy.yaml" file is not valid. Received 1.'
);
});
@ -148,7 +150,7 @@ test('Version is not a valid version number', async () => {
}
return null;
});
await expect(getLowdefyYaml({ baseDirectory })).rejects.toThrow(
await expect(getLowdefyYaml({ configDirectory })).rejects.toThrow(
'Version number specified in "lowdefy.yaml" file is not valid. Received "v1-0-3".'
);
});
@ -166,7 +168,7 @@ test('get cliConfig', async () => {
}
return null;
});
const config = await getLowdefyYaml({ baseDirectory });
const config = await getLowdefyYaml({ configDirectory });
expect(config).toEqual({
lowdefyVersion: '1.0.0',
cliConfig: { disableTelemetry: true, watch: ['a'] },
@ -175,11 +177,11 @@ test('get cliConfig', async () => {
test('could not find lowdefy.yaml in base dir, command is "init" or "clean-cache"', async () => {
readFile.mockImplementation(() => null);
let config = await getLowdefyYaml({ command: 'init', baseDirectory });
let config = await getLowdefyYaml({ command: 'init', configDirectory });
expect(config).toEqual({
cliConfig: {},
});
config = await getLowdefyYaml({ command: 'clean-cache', baseDirectory });
config = await getLowdefyYaml({ command: 'clean-cache', configDirectory });
expect(config).toEqual({
cliConfig: {},
});
@ -194,6 +196,6 @@ test('support yml extension', async () => {
}
return null;
});
const config = await getLowdefyYaml({ baseDirectory });
const config = await getLowdefyYaml({ configDirectory });
expect(config).toEqual({ lowdefyVersion: '1.0.0', cliConfig: {} });
});

@ -59,9 +59,9 @@ test('runCommand calls startUp', async () => {
Object {
"context": Object {
"appId": "appId",
"baseDirectory": "baseDirectory",
"buildDirectory": "baseDirectory/buildDirectory",
"cacheDirectory": "baseDirectory/cacheDirectory",
"configDirectory": "configDirectory",
"buildDirectory": "configDirectory/buildDirectory",
"cacheDirectory": "configDirectory/cacheDirectory",
"cliConfig": Object {},
"cliVersion": "cliVersion",
"command": "test",
@ -91,9 +91,9 @@ test('runCommand calls startUp', async () => {
},
"context": Object {
"appId": "appId",
"baseDirectory": "baseDirectory",
"buildDirectory": "baseDirectory/buildDirectory",
"cacheDirectory": "baseDirectory/cacheDirectory",
"configDirectory": "configDirectory",
"buildDirectory": "configDirectory/buildDirectory",
"cacheDirectory": "configDirectory/cacheDirectory",
"cliConfig": Object {},
"cliVersion": "cliVersion",
"command": "test",
@ -133,9 +133,9 @@ test('Catch error synchronous function', async () => {
Object {
"context": Object {
"appId": "appId",
"baseDirectory": "baseDirectory",
"buildDirectory": "baseDirectory/buildDirectory",
"cacheDirectory": "baseDirectory/cacheDirectory",
"configDirectory": "configDirectory",
"buildDirectory": "configDirectory/buildDirectory",
"cacheDirectory": "configDirectory/cacheDirectory",
"cliConfig": Object {},
"cliVersion": "cliVersion",
"command": "test",
@ -174,9 +174,9 @@ test('Catch error asynchronous function', async () => {
Object {
"context": Object {
"appId": "appId",
"baseDirectory": "baseDirectory",
"buildDirectory": "baseDirectory/buildDirectory",
"cacheDirectory": "baseDirectory/cacheDirectory",
"configDirectory": "configDirectory",
"buildDirectory": "configDirectory/buildDirectory",
"cacheDirectory": "configDirectory/cacheDirectory",
"cliConfig": Object {},
"cliVersion": "cliVersion",
"command": "test",

@ -31,7 +31,7 @@ async function startUp({ context, options = {}, command }) {
context.commandLineOptions = options;
context.print = createPrint();
context.baseDirectory = path.resolve(options.baseDirectory || process.cwd());
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
const { cliConfig, lowdefyVersion } = await getLowdefyYaml(context);
context.cliConfig = cliConfig;
context.lowdefyVersion = lowdefyVersion;

@ -56,7 +56,7 @@ test('startUp, options empty', async () => {
await startUp({ context, options: {}, command });
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd()),
configDirectory: path.resolve(process.cwd()),
cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'),
cliConfig: { cliConfig: true },
cliVersion: 'cliVersion',
@ -79,7 +79,7 @@ test('startUp, options undefined', async () => {
await startUp({ context, command });
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd()),
configDirectory: path.resolve(process.cwd()),
cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'),
cliConfig: { cliConfig: true },
cliVersion: 'cliVersion',
@ -93,23 +93,23 @@ test('startUp, options undefined', async () => {
});
});
test('startUp, options baseDirectory', async () => {
test('startUp, options configDirectory', async () => {
const context = {};
await startUp({ context, options: { baseDirectory: './baseDirectory' }, command });
await startUp({ context, options: { configDirectory: './configDirectory' }, command });
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd(), 'baseDirectory'),
cacheDirectory: path.resolve(process.cwd(), 'baseDirectory/.lowdefy/.cache'),
configDirectory: path.resolve(process.cwd(), 'configDirectory'),
cacheDirectory: path.resolve(process.cwd(), 'configDirectory/.lowdefy/.cache'),
cliConfig: { cliConfig: true },
cliVersion: 'cliVersion',
command: 'test',
commandLineOptions: { baseDirectory: './baseDirectory' },
commandLineOptions: { configDirectory: './configDirectory' },
lowdefyVersion: 'lowdefyVersion',
options: {
cliConfig: true,
baseDirectory: './baseDirectory',
configDirectory: './configDirectory',
},
buildDirectory: path.resolve(process.cwd(), 'baseDirectory/.lowdefy/build'),
buildDirectory: path.resolve(process.cwd(), 'configDirectory/.lowdefy/build'),
sendTelemetry: 'sendTelemetry',
print,
});
@ -120,7 +120,7 @@ test('startUp, options outputDirectory', async () => {
await startUp({ context, options: { outputDirectory: './outputDirectory' }, command });
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd()),
configDirectory: path.resolve(process.cwd()),
cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'),
cliConfig: { cliConfig: true },
cliVersion: 'cliVersion',
@ -137,12 +137,12 @@ test('startUp, options outputDirectory', async () => {
});
});
test('startUp, options baseDirectory and outputDirectory', async () => {
test('startUp, options configDirectory and outputDirectory', async () => {
const context = {};
await startUp({
context,
options: {
baseDirectory: './baseDirectory',
configDirectory: './configDirectory',
outputDirectory: './outputDirectory',
},
command,
@ -150,18 +150,18 @@ test('startUp, options baseDirectory and outputDirectory', async () => {
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd(), 'baseDirectory'),
cacheDirectory: path.resolve(process.cwd(), 'baseDirectory/.lowdefy/.cache'),
configDirectory: path.resolve(process.cwd(), 'configDirectory'),
cacheDirectory: path.resolve(process.cwd(), 'configDirectory/.lowdefy/.cache'),
cliConfig: { cliConfig: true },
cliVersion: 'cliVersion',
command: 'test',
commandLineOptions: {
baseDirectory: './baseDirectory',
configDirectory: './configDirectory',
outputDirectory: './outputDirectory',
},
lowdefyVersion: 'lowdefyVersion',
options: {
baseDirectory: './baseDirectory',
configDirectory: './configDirectory',
cliConfig: true,
outputDirectory: './outputDirectory',
},
@ -177,7 +177,7 @@ test('startUp, no lowdefyVersion returned', async () => {
await startUp({ context, options: {}, command });
expect(context).toEqual({
appId: 'appId',
baseDirectory: path.resolve(process.cwd()),
configDirectory: path.resolve(process.cwd()),
cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'),
cliConfig: {},
cliVersion: 'cliVersion',

@ -58,10 +58,10 @@ _ref:
The `build` command runs a Lowdefy build. The options are:
- `--base-directory <base-directory>`: Change base directory. The default is the current working directory.
- `--config-directory <config-directory>`: Change base directory. The default is the current working directory.
- `--blocks-server-url <blocks-server-url>`: The URL from where Lowdefy blocks will be served. See below for more information.
- `--disable-telemetry`: Disable telemetry.
- `--output-directory <output-directory>`: Change the directory to which build artifacts are saved. The default is `<base-directory>/.lowdefy/build`.
- `--output-directory <output-directory>`: Change the directory to which build artifacts are saved. The default is `<config-directory>/.lowdefy/build`.
- `--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.
## build-netlify
@ -69,7 +69,7 @@ _ref:
We recommend setting the build command to `npx lowdefy@latest build-netlify`. The Netlify publish directory should be set to `.lowdefy/publish`, and the functions directory set to `.lowdefy/functions`.
- `--base-directory <base-directory>`: Change base directory. The default is the current working directory (The base directory should rather be configured in the Netlify build settings).
- `--config-directory <config-directory>`: Change base directory. The default is the current working directory (The base directory should rather be configured in the Netlify build settings).
- `--blocks-server-url <blocks-server-url>`: The URL from where Lowdefy blocks will be served. See below for more information.
- `--disable-telemetry`: Disable telemetry.
- `--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.
@ -78,14 +78,14 @@ _ref:
The Lowdefy CLI caches block metadata, and build and server scripts in the `.lowdefy/cache` directory. These cached files can be removed using the `clean-cache` command.
- `--base-directory <base-directory>`: Change base directory. The default is the current working directory.
- `--config-directory <config-directory>`: Change base directory. The default is the current working directory.
- `--disable-telemetry`: Disable telemetry.
## dev
The `dev` command starts a Lowdefy development server, running locally. It can be accessed in a browser at [http://localhost:3000](http://localhost:3000). The CLI watches the file system, and rebuilds the app and reloads served pages every time a change is made to any of the files in the project directory.
- `--base-directory <base-directory>`: Change base directory. The default is the current working directory.
- `--config-directory <config-directory>`: Change base directory. The default is the current working directory.
- `--blocks-server-url <blocks-server-url>`: The URL from where Lowdefy blocks will be served. See below for more information.
- `--disable-telemetry`: Disable telemetry.
- `--port <port>`: Change the port the server is hosted at. The default is `3000`.
@ -113,13 +113,13 @@ _ref:
Options set in the `lowdefy.yaml` should be defined in camelCase. The options that can be set are:
- `blocksServerUrl: string`: The URL from where Lowdefy blocks will be served. See below for more information.
- `disableTelemetry: boolean`: Disable telemetry.
- `outputDirectory: string`: Change the directory to which build artifacts are saved. The default is `<base-directory>/.lowdefy/build`.
- `outputDirectory: string`: Change the directory to which build artifacts are saved. The default is `<config-directory>/.lowdefy/build`.
- `refResolver: string`: Path to a JavaScript file containing a `_ref` resolver function to be used as the app default `_ref` resolver.
- `port: number`: Change the port the server is hosted at. The default is `3000`.
- `watch: string[]`: A list of paths to files or directories that should be watched for changes.
- `watchIgnore: string[]`: A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.
The `--base-directory` option cannot be set from the `lowdefy.yaml` file.
The `--config-directory` option cannot be set from the `lowdefy.yaml` file.
# Telemetry