Skip to content

Commit

Permalink
perf: supports baseName value
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Apr 14, 2018
1 parent a264175 commit b7e8a88
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/edam/src/__tests__/edam/functional.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('functional', function() {
const fp = await mockPrompts(
join(tplPath, 'functional'),
{
value: 'ojbk'
// value: 'ojbk'
},
join(outputRoot, 'functional')
)
Expand All @@ -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'))
Expand All @@ -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'))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function(/*options*/) {
{
name: 'value',
type: 'input',
default: () => 'default_val'
default: '${baseName}'
}
],
variables: {
Expand Down
4 changes: 4 additions & 0 deletions packages/edam/src/core/TreeProcessor/FileProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class FileProcessor extends TreeProcessor {
overwrite: false
}
): Promise<boolean> {
if (!filepath) {
filepath = this.dest
}

await pify(mkdirp)(filepath)
if (option.clean) {
await pify(rimraf)(filepath)
Expand Down
3 changes: 2 additions & 1 deletion packages/edam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b7e8a88

Please sign in to comment.