mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
fix(node-utils): Convert writeFile function prototype.
This commit is contained in:
parent
762df5ffc5
commit
5371430712
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.`);
|
||||
|
@ -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);
|
||||
|
@ -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'),
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -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()}`);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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)}.`
|
||||
|
@ -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 {
|
||||
@ -49,25 +46,20 @@ test('writeFile should create directories if they do not exist', async () => {
|
||||
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) => 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 content is not a string.', async () => {
|
||||
await expect(
|
||||
writeFile({ filePath: './test/writeFile/writeFile.txt', content: 123 })
|
||||
).rejects.toThrow(
|
||||
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)'
|
||||
);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user