Skip to content

Commit

Permalink
fix: config.output is null
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed May 31, 2018
1 parent 6ed148d commit c27f958
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
6 changes: 6 additions & 0 deletions packages/edam/src/__tests__/fixture/edam/spec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ module.exports = {
{
name: 'value',
type: 'input',
validate: (val) => {
console.error('validate', val)
if (val === 'error') {
return 'should be error message here!'
}
},
default: () => 'default_val'
}
],
Expand Down
16 changes: 0 additions & 16 deletions packages/edam/src/__tests__/pull/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ describe('npm', function() {
// await fileSystenpmm.cleanDir(output)
})

it('should npm pull universal package when use `npm` and nocache', async () => {
expect(
await npmPull(
source,
constant.DEFAULT_CACHE_DIR,
{
cacheDir: false,
pull: {
npmClient: 'npm'
}
}
)
).toBe(output)
expect(version()).toBe('1.0.1')
})

afterAll(async function () {
await fileSystem.cleanDir(this.constants.DEFAULT_CACHE_DIR)
})
Expand Down
21 changes: 14 additions & 7 deletions packages/edam/src/core/promptProcessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export default async function prompt(
}

let value
const {
transformer,
validate
} = prompt
const { transformer, validate } = prompt
delete prompt.when
delete prompt.transformer
delete prompt.validate
Expand All @@ -65,9 +62,19 @@ export default async function prompt(
value = await transformer(value, set, context)
}

if (_.isFunction(validate) && !await validate(value, set, context)) {
this.logger.warn('validate %s failed, so the value "%s" is ignored.', prompt.name, value)
return set
if (_.isFunction(validate)) {
let message = await validate(value, set, context)
if (typeof message === 'string') {
value = prompt.default
this.logger &&
this.logger.warn(
'validate %s failed, error message: %s, so the value "%s" fallback to default value.',
prompt.name,
message,
value
)
return set
}
}

Object.assign(set, {
Expand Down
4 changes: 2 additions & 2 deletions packages/edam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Edam extends AwaitEventEmitter {
...this.constants.DEFAULT_CONTEXT,
absoluteDir: this.config.output,
dirName: this.config.output && nps.dirname(this.config.output),
baseName: nps.basename(this.config.output)
baseName: this.config.output && nps.basename(this.config.output)
}

if (this.config.storePrompts && this.config.cacheDir) {
Expand All @@ -165,7 +165,7 @@ export class Edam extends AwaitEventEmitter {
}

await this.emit('prompt:before', prompts, context)
const promptValues = await this.prompt(prompts, {
const promptValues = await this.prompt.call(this, prompts, {
yes: this.config.yes,
context,
promptProcess: this.promptProcess
Expand Down

0 comments on commit c27f958

Please sign in to comment.