From b7e8a888943897c916cc4ef4148292a261f1c02c Mon Sep 17 00:00:00 2001 From: imcuttle Date: Sat, 14 Apr 2018 19:36:23 +0800 Subject: [PATCH] perf: supports `baseName` value --- packages/edam/src/__tests__/edam/functional.test.js | 7 +++++-- .../edam/src/__tests__/fixture/edam/functional/index.js | 2 +- packages/edam/src/core/TreeProcessor/FileProcessor.ts | 4 ++++ packages/edam/src/index.ts | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/edam/src/__tests__/edam/functional.test.js b/packages/edam/src/__tests__/edam/functional.test.js index 370c545..b18cfcb 100644 --- a/packages/edam/src/__tests__/edam/functional.test.js +++ b/packages/edam/src/__tests__/edam/functional.test.js @@ -39,7 +39,7 @@ describe('functional', function() { const fp = await mockPrompts( join(tplPath, 'functional'), { - value: 'ojbk' + // value: 'ojbk' }, join(outputRoot, 'functional') ) @@ -51,7 +51,7 @@ describe('functional', function() { normalize('index.js') ]) ) - expect(await fp.writeToFile()).toBeTruthy() + expect(await fp.writeToFile(null, { overwrite: true })).toBeTruthy() expect( await readdirDeep(join(outputRoot, 'functional')) @@ -62,6 +62,9 @@ describe('functional', function() { normalize('index.js') ]) ) + expect( + require(join(outputRoot, 'functional', 'index.js')) + ).toBe('functional') await fileSystem.cleanDir(join(outputRoot, 'functional')) }) diff --git a/packages/edam/src/__tests__/fixture/edam/functional/index.js b/packages/edam/src/__tests__/fixture/edam/functional/index.js index 9c8f03a..3116e53 100644 --- a/packages/edam/src/__tests__/fixture/edam/functional/index.js +++ b/packages/edam/src/__tests__/fixture/edam/functional/index.js @@ -17,7 +17,7 @@ module.exports = function(/*options*/) { { name: 'value', type: 'input', - default: () => 'default_val' + default: '${baseName}' } ], variables: { diff --git a/packages/edam/src/core/TreeProcessor/FileProcessor.ts b/packages/edam/src/core/TreeProcessor/FileProcessor.ts index 3443951..bda9e71 100644 --- a/packages/edam/src/core/TreeProcessor/FileProcessor.ts +++ b/packages/edam/src/core/TreeProcessor/FileProcessor.ts @@ -42,6 +42,10 @@ export default class FileProcessor extends TreeProcessor { overwrite: false } ): Promise { + if (!filepath) { + filepath = this.dest + } + await pify(mkdirp)(filepath) if (option.clean) { await pify(rimraf)(filepath) diff --git a/packages/edam/src/index.ts b/packages/edam/src/index.ts index deda948..2a45ea8 100644 --- a/packages/edam/src/index.ts +++ b/packages/edam/src/index.ts @@ -143,7 +143,8 @@ export class Edam extends AwaitEventEmitter { const context = { ...this.constants.DEFAULT_CONTEXT, absoluteDir: this.config.output, - dirName: this.config.output && nps.dirname(this.config.output) + dirName: this.config.output && nps.dirname(this.config.output), + baseName: nps.basename(this.config.output) } if (this.config.storePrompts && this.config.cacheDir) {