Merge remote-tracking branch 'origin/v4' into dev-server-file-watchers

This commit is contained in:
Sam Tolmay 2022-01-21 12:32:54 +02:00
commit 87163d1f0e
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
21 changed files with 154 additions and 50 deletions

3
.gitignore vendored
View File

@ -27,3 +27,6 @@ packages/build/build/**
packages/plugins/connections/connection-mongodb/mongod-*
packages/plugins/connections/connection-mongodb/globalConfig.json
packages/plugins/connections/connection-mongodb/*.lock
packages/utils/node-utils/test/writeFile/writeFile.txt
packages/utils/node-utils/test/copyDirectory/**

16
.pnp.cjs generated
View File

@ -5481,8 +5481,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@swc/cli", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.55"],
["@swc/core", "npm:1.2.130"],
["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.17"],
["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.3.1"],
["rimraf", "npm:3.0.2"]
["fs-extra", "npm:10.0.0"],
["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.3.1"]
],
"linkType": "SOFT",
}]
@ -5650,6 +5650,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@lowdefy/server", "workspace:packages/server"],
["@lowdefy/api", "workspace:packages/api"],
["@lowdefy/block-utils", "workspace:packages/utils/block-utils"],
["@lowdefy/blocks-antd", "workspace:packages/plugins/blocks/blocks-antd"],
["@lowdefy/blocks-basic", "workspace:packages/plugins/blocks/blocks-basic"],
["@lowdefy/build", "workspace:packages/build"],
["@lowdefy/engine", "workspace:packages/engine"],
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
@ -11752,6 +11754,16 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]
]],
["fs-extra", [
["npm:10.0.0", {
"packageLocation": "./.yarn/cache/fs-extra-npm-10.0.0-4f8c704115-5285a3d8f3.zip/node_modules/fs-extra/",
"packageDependencies": [
["fs-extra", "npm:10.0.0"],
["graceful-fs", "npm:4.2.8"],
["jsonfile", "npm:6.1.0"],
["universalify", "npm:2.0.0"]
],
"linkType": "HARD",
}],
["npm:9.1.0", {
"packageLocation": "./.yarn/cache/fs-extra-npm-9.1.0-983c2ddb4c-ba71ba32e0.zip/node_modules/fs-extra/",
"packageDependencies": [

Binary file not shown.

View File

@ -0,0 +1,31 @@
/*
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 path from 'path';
import fs from 'fs';
import { copyDirectory } from '@lowdefy/node-utils';
async function copyPublicFolder({ context }) {
if (context.directories.config === context.directories.server) return;
if (!fs.existsSync(path.resolve(context.directories.config, 'public'))) return;
await copyDirectory(
path.resolve(context.directories.config, 'public'),
path.resolve(context.directories.server, 'public')
);
}
export default copyPublicFolder;

View File

@ -49,10 +49,7 @@ async function updateServerPackageJson({ components, context }) {
// be watching the file to trigger reinstalls
if (newPackageJsonContent !== packageJsonContent) {
context.logger.warn('Plugin dependencies have changed. Updating "package.json".');
await writeFile({
filePath,
content: newPackageJsonContent,
});
await writeFile(filePath, newPackageJsonContent);
}
}

View File

@ -32,6 +32,7 @@ import buildRefs from './build/buildRefs/buildRefs.js';
import buildStyles from './build/buildStyles.js';
import buildTypes from './build/buildTypes.js';
import cleanBuildDirectory from './build/cleanBuildDirectory.js';
import copyPublicFolder from './build/copyPublicFolder.js';
import testSchema from './build/testSchema.js';
import validateApp from './build/validateApp.js';
import validateConfig from './build/validateConfig.js';
@ -110,6 +111,7 @@ async function build(options) {
await writeStyleImports({ components, context });
await writeIconImports({ components, context });
await updateServerPackageJson({ components, context });
await copyPublicFolder({ components, context });
} catch (error) {
context.logger.error(error);
throw error;

View File

@ -120,10 +120,10 @@ async function generateDefaultTypes() {
})
);
await writeFile({
filePath: path.resolve(process.cwd(), './dist/defaultTypes.json'),
content: JSON.stringify(defaultTypes, null, 2),
});
await writeFile(
path.resolve(process.cwd(), './dist/defaultTypes.json'),
JSON.stringify(defaultTypes, null, 2)
);
}
generateDefaultTypes();

View File

@ -19,7 +19,7 @@ import { writeFile } from '@lowdefy/node-utils';
function createWriteBuildArtifact({ directories }) {
async function writeBuildArtifact({ filePath, content }) {
return writeFile({ filePath: path.resolve(directories.build, filePath), content });
return writeFile(path.resolve(directories.build, filePath), content);
}
return writeBuildArtifact;
}

View File

@ -27,16 +27,13 @@ async function init({ context }) {
throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');
}
context.print.log(`Initializing Lowdefy project`);
await writeFile({
filePath: lowdefyFilePath,
content: lowdefyFile({ version: context.cliVersion }),
});
await writeFile(lowdefyFilePath, lowdefyFile({ version: context.cliVersion }));
context.print.log(`Created 'lowdefy.yaml'.`);
await writeFile({
filePath: path.resolve('./.gitignore'),
content: `.lowdefy/**
.env`,
});
await writeFile(
path.resolve('./.gitignore'),
`.lowdefy/**
.env`
);
context.print.log(`Created '.gitignore'.`);
await context.sendTelemetry();
context.print.succeed(`Project initialized.`);

View File

@ -23,7 +23,7 @@ async function getCliJson({ baseDirectory }) {
const cliJson = await readFile(filePath);
if (!cliJson) {
const appId = uuid();
await writeFile({ filePath, content: JSON.stringify({ appId }, null, 2) });
await writeFile(filePath, JSON.stringify({ appId }, null, 2));
return { appId };
}
return JSON.parse(cliJson);

View File

@ -45,12 +45,10 @@ test('getCliJson, no file exists', async () => {
expect(res).toEqual({ appId: 'uuidv4' });
expect(writeFile.mock.calls).toEqual([
[
{
content: `{
path.resolve(process.cwd(), '.lowdefy/cli.json'),
`{
"appId": "uuidv4"
}`,
filePath: path.resolve(process.cwd(), '.lowdefy/cli.json'),
},
],
]);
});

View File

@ -19,7 +19,7 @@ import { writeFile } from '@lowdefy/node-utils';
function reloadClients({ directories }) {
return async () => {
await writeFile({ filePath: path.join(directories.build, 'reload'), content: `${Date.now()}` });
await writeFile(path.join(directories.build, 'reload'), `${Date.now()}`);
};
}

View File

@ -9,6 +9,6 @@ module.exports = {
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { configFile: '../../.swcrc.test' }],
'^.+\\.(t|j)sx?$': ['@swc/jest', { configFile: '../../../.swcrc.test' }],
},
};

View File

@ -42,7 +42,7 @@
},
"dependencies": {
"@lowdefy/helpers": "4.0.0-alpha.6",
"rimraf": "3.0.2"
"fs-extra": "10.0.0"
},
"devDependencies": {
"@swc/cli": "0.1.55",

View File

@ -14,10 +14,10 @@
limitations under the License.
*/
import rimraf from 'rimraf';
import fsExtra from 'fs-extra';
async function cleanDirectory(dirPath) {
await new Promise((resolve) => rimraf(dirPath, resolve));
await fsExtra.emptyDir(dirPath);
}
export default cleanDirectory;

View File

@ -0,0 +1,23 @@
/*
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 fsExtra from 'fs-extra';
async function copyDirectory(dirPathFrom, dirPathTo) {
await fsExtra.copy(dirPathFrom, dirPathTo);
}
export default copyDirectory;

View File

@ -0,0 +1,34 @@
/*
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-extra';
import path from 'path';
import copyDirectory from './copyDirectory.js';
test('copyDirectory', async () => {
const dirPathFrom = path.resolve(process.cwd(), 'test/copyDirectory/From/');
const dirPathTo = path.resolve(process.cwd(), 'test/copyDirectory/To/');
const filePathFrom = path.resolve(dirPathFrom, 'copyDirectory.txt');
const filePathTo = path.resolve(dirPathTo, 'copyDirectory.txt');
fs.mkdirSync(dirPathFrom, {
recursive: true,
});
fs.writeFileSync(filePathFrom, 'copyDirectory');
await copyDirectory(dirPathFrom, dirPathTo);
expect(fs.existsSync(filePathTo)).toBe(true);
});

View File

@ -15,6 +15,7 @@
*/
import cleanDirectory from './cleanDirectory.js';
import copyDirectory from './copyDirectory.js';
import getConfigFromEnv from './getConfigFromEnv.js';
import getFileExtension, { getFileSubExtension } from './getFileExtension.js';
import getSecretsFromEnv from './getSecretsFromEnv.js';
@ -24,6 +25,7 @@ import writeFile from './writeFile.js';
export {
cleanDirectory,
copyDirectory,
getConfigFromEnv,
getFileExtension,
getFileSubExtension,

View File

@ -22,7 +22,7 @@ import { type } from '@lowdefy/helpers';
const mkdirPromise = promisify(fs.mkdir);
const writeFilePromise = promisify(fs.writeFile);
async function writeFile({ filePath, content }) {
async function writeFile(filePath, content) {
if (!type.isString(filePath)) {
throw new Error(
`Could not write file, file path should be a string, received ${JSON.stringify(filePath)}.`

View File

@ -15,8 +15,8 @@
*/
import fs from 'fs';
import fsExtra from 'fs-extra';
import path from 'path';
import rimraf from 'rimraf';
import writeFile from './writeFile.js';
const baseDir = path.resolve(process.cwd(), 'test/writeFile');
@ -29,10 +29,7 @@ test('writeFile', async () => {
//pass
}
expect(fs.existsSync(filePath)).toBe(false);
await writeFile({
filePath,
content: `Test Write File`,
});
await writeFile(filePath, `Test Write File`);
const res = fs.readFileSync(filePath, 'utf8');
expect(res).toEqual(`Test Write File`);
try {
@ -46,28 +43,23 @@ test('writeFile should create directories if they do not exist', async () => {
const filePath = path.resolve(baseDir, 'sub/dir/test/writeFile.txt');
const testBaseDir = path.resolve(baseDir, 'sub');
await new Promise((resolve) => rimraf(testBaseDir, resolve));
await new Promise((resolve) => fsExtra.emptyDir(testBaseDir, resolve));
expect(fs.existsSync(filePath)).toBe(false);
await writeFile({
filePath,
content: `Test Write File`,
});
await writeFile(filePath, `Test Write File`);
const res = fs.readFileSync(filePath, 'utf8');
expect(res).toEqual(`Test Write File`);
await new Promise((resolve) => rimraf(testBaseDir, resolve));
await new Promise((resolve) => fsExtra.emptyDir(testBaseDir, resolve));
});
test('readFile error id filepath is not a string', async () => {
await expect(writeFile({ filePath: true, content: `Test Write File` })).rejects.toThrow(
await expect(writeFile(true, `Test Write File`)).rejects.toThrow(
'Could not write file, file path should be a string, received true.'
);
});
test('readFile errors if path is not already resolved', async () => {
await expect(
writeFile({ filePath: './writeFile/writeFile.txt', content: `Test Write File` })
).rejects.toThrow(
'Could not write file, file path was not resolved, received "./writeFile/writeFile.txt".'
test('readFile errors if content is not a string.', async () => {
await expect(writeFile('./test/writeFile/writeFile.txt', 123)).rejects.toThrow(
'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (123)'
);
});

View File

@ -3749,8 +3749,8 @@ __metadata:
"@swc/cli": 0.1.55
"@swc/core": 1.2.130
"@swc/jest": 0.2.17
fs-extra: 10.0.0
jest: 27.3.1
rimraf: 3.0.2
languageName: unknown
linkType: soft
@ -3939,6 +3939,8 @@ __metadata:
dependencies:
"@lowdefy/api": 4.0.0-alpha.6
"@lowdefy/block-utils": 4.0.0-alpha.6
"@lowdefy/blocks-antd": 4.0.0-alpha.6
"@lowdefy/blocks-basic": 4.0.0-alpha.6
"@lowdefy/build": 4.0.0-alpha.6
"@lowdefy/engine": 4.0.0-alpha.6
"@lowdefy/helpers": 4.0.0-alpha.6
@ -8953,6 +8955,17 @@ __metadata:
languageName: node
linkType: hard
"fs-extra@npm:10.0.0":
version: 10.0.0
resolution: "fs-extra@npm:10.0.0"
dependencies:
graceful-fs: ^4.2.0
jsonfile: ^6.0.1
universalify: ^2.0.0
checksum: 5285a3d8f34b917cf2b66af8c231a40c1623626e9d701a20051d3337be16c6d7cac94441c8b3732d47a92a2a027886ca93c69b6a4ae6aee3c89650d2a8880c0a
languageName: node
linkType: hard
"fs-extra@npm:^9.1.0":
version: 9.1.0
resolution: "fs-extra@npm:9.1.0"
@ -16242,7 +16255,7 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard
"rimraf@npm:3.0.2, rimraf@npm:^3.0.0, rimraf@npm:^3.0.2":
"rimraf@npm:^3.0.0, rimraf@npm:^3.0.2":
version: 3.0.2
resolution: "rimraf@npm:3.0.2"
dependencies: