diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts index f8fc1f1dc5..ba8a145721 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.test.ts @@ -46,6 +46,9 @@ describe('fs:delete', () => { [workspacePath]: { 'unit-test-a.js': 'hello', 'unit-test-b.js': 'world', + 'a-folder': { + 'unit-test-in-a-folder.js2': 'content', + }, }, }); }); @@ -90,14 +93,18 @@ describe('fs:delete', () => { ...mockContext, input: { files: ['/foo/../../../index.js'] }, }), - ).rejects.toThrow(/Relative path is not allowed to refer to a directory outside its parent/); + ).rejects.toThrow( + /Relative path is not allowed to refer to a directory outside its parent/, + ); await expect( action.handler({ ...mockContext, input: { files: ['../../../index.js'] }, }), - ).rejects.toThrow(/Relative path is not allowed to refer to a directory outside its parent/); + ).rejects.toThrow( + /Relative path is not allowed to refer to a directory outside its parent/, + ); }); it('should call fs.rm with the correct values', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts index ec8d60f955..068f777ec5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/delete.ts @@ -21,6 +21,7 @@ import fs from 'fs-extra'; export const createFilesystemDeleteAction = () => { return createTemplateAction<{ files: string[] }>({ id: 'fs:delete', + description: 'Deletes files and directories from the workspace', schema: { input: { required: ['files'], @@ -28,7 +29,7 @@ export const createFilesystemDeleteAction = () => { properties: { files: { title: 'Files', - description: 'A list of files or directories that will be deleted', + description: 'A list of files and directories that will be deleted', type: 'array', items: { type: 'string', diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts index 58bb558ff5..8452735083 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts @@ -37,6 +37,10 @@ describe('fs:rename', () => { from: 'unit-test-b.js', to: 'new-b.js', }, + { + from: 'a-folder', + to: 'brand-new-folder', + }, ]; const mockContext = { input: { @@ -57,6 +61,9 @@ describe('fs:rename', () => { 'unit-test-a.js': 'hello', 'unit-test-b.js': 'world', 'unit-test-c.js': 'i will be overwritten :-(', + 'a-folder': { + 'file.md': 'content', + }, }, }); }); @@ -124,14 +131,18 @@ describe('fs:rename', () => { ...mockContext, input: { files: [{ from: 'index.js', to: '/core/../../../index.js' }] }, }), - ).rejects.toThrow(/Relative path is not allowed to refer to a directory outside its parent/); + ).rejects.toThrow( + /Relative path is not allowed to refer to a directory outside its parent/, + ); await expect( action.handler({ ...mockContext, input: { files: [{ from: '/core/../../../index.js', to: 'index.js' }] }, }), - ).rejects.toThrow(/Relative path is not allowed to refer to a directory outside its parent/); + ).rejects.toThrow( + /Relative path is not allowed to refer to a directory outside its parent/, + ); }); it('should throw is trying to override by mistake', async () => { @@ -184,7 +195,6 @@ describe('fs:rename', () => { const destBeforeContent = fs.readFileSync(destFilePath, 'utf-8'); expect(sourceBeforeContent).not.toEqual(destBeforeContent); - await action.handler({ ...mockContext, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.ts index bcfb35025c..aaadd5df57 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.ts @@ -28,6 +28,7 @@ interface FilesToRename extends JsonObject { export const createFilesystemRenameAction = () => { return createTemplateAction<{ files: FilesToRename }>({ id: 'fs:rename', + description: 'Renames files and directories within the workspace', schema: { input: { required: ['files'], @@ -35,7 +36,8 @@ export const createFilesystemRenameAction = () => { properties: { files: { title: 'Files', - description: 'A list of file names that will be renamed', + description: + 'A list of file and directory names that will be renamed', type: 'array', items: { type: 'object', @@ -70,12 +72,15 @@ export const createFilesystemRenameAction = () => { throw new InputError('each file must have a from and to property'); } - const sourceFilepath = resolveSafeChildPath(ctx.workspacePath, file.from); + const sourceFilepath = resolveSafeChildPath( + ctx.workspacePath, + file.from, + ); const destFilepath = resolveSafeChildPath(ctx.workspacePath, file.to); try { await fs.move(sourceFilepath, destFilepath, { - overwrite: file.overwrite || false, + overwrite: file.overwrite ?? false, }); ctx.logger.info( `File ${sourceFilepath} renamed to ${destFilepath} successfully`,