Merge branch 'develop' into init-page

This commit is contained in:
Gerrie van Wyk 2021-11-05 14:10:17 +02:00 committed by GitHub
commit 32d951e454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -20,7 +20,10 @@ import { readFile } from '@lowdefy/node-utils';
import YAML from 'js-yaml';
async function getLowdefyYaml({ baseDirectory, command }) {
const lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yaml'));
let lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yaml'));
if (!lowdefyYaml) {
lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yml'));
}
if (!lowdefyYaml) {
if (!['init', 'clean-cache'].includes(command)) {
throw new Error(

View File

@ -61,7 +61,10 @@ test('get version from yaml file, base dir specified', async () => {
test('could not find lowdefy.yaml in cwd', async () => {
readFile.mockImplementation((filePath) => {
if (filePath === path.resolve(process.cwd(), 'lowdefy.yaml')) {
if (
filePath === path.resolve(process.cwd(), 'lowdefy.yaml') ||
filePath === path.resolve(process.cwd(), 'lowdefy.yml')
) {
return null;
}
return `
@ -75,7 +78,10 @@ test('could not find lowdefy.yaml in cwd', async () => {
test('could not find lowdefy.yaml in base dir', async () => {
readFile.mockImplementation((filePath) => {
if (filePath === path.resolve(process.cwd(), 'baseDir/lowdefy.yaml')) {
if (
filePath === path.resolve(process.cwd(), 'baseDir/lowdefy.yaml') ||
filePath === path.resolve(process.cwd(), 'baseDir/lowdefy.yml')
) {
return null;
}
return `
@ -178,3 +184,16 @@ test('could not find lowdefy.yaml in base dir, command is "init" or "clean-cache
cliConfig: {},
});
});
test('support yml extension', async () => {
readFile.mockImplementation((filePath) => {
if (filePath === path.resolve(process.cwd(), 'lowdefy.yml')) {
return `
lowdefy: 1.0.0
`;
}
return null;
});
const config = await getLowdefyYaml({ baseDirectory });
expect(config).toEqual({ lowdefyVersion: '1.0.0', cliConfig: {} });
});

View File

@ -201,6 +201,10 @@ _ref:
The `_ref` operator can also be extended with custom JavaScript functions. A `resolver` function can be specified, which can overwrite the default way configuration files are read from the filesystem. A `transformer` function can be used to transform the value returned by the `_ref` operator.
## YAML file extensions
Both files with the `.yaml` and `.yml` file extensions are supported as YAML files.
## JSON instead of YAML
Since you can reference JSON files, you can build your app using JSON instead of YAML files. The `lowdefy.yaml` file needs to be a YAML file, but all other configuration can be in referenced JSON files. It also makes sense to use JSON instead of YAML if you are generating configuration using code.