-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(edam): template config append
process
- Loading branch information
Showing
12 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable quotes */ | ||
/** | ||
* @file spec | ||
* @author Cuttle Cong | ||
* @date 2018/3/28 | ||
* @description | ||
*/ | ||
import { mockPrompts } from '../../index' | ||
import { join, relative, normalize } from 'path' | ||
import fileSystem from '../../lib/fileSystem' | ||
|
||
async function readdirDeep(dest) { | ||
const files = await fileSystem.readdirDeep(dest) | ||
return files.filter(x => fileSystem.isFile(x)).map(x => relative(dest, x)) | ||
} | ||
describe('process_config', function() { | ||
const tplPath = join(__dirname, '../fixture/edam') | ||
const outputRoot = join(__dirname, '../fixture/edam-output') | ||
|
||
it('should process_config', async () => { | ||
const ft = await mockPrompts( | ||
join(tplPath, 'process_config'), | ||
{ | ||
value: 'ojbk' | ||
}, | ||
join(outputRoot, 'process_config') | ||
) | ||
|
||
expect(Object.keys(ft.tree)).toEqual( | ||
expect.arrayContaining([ | ||
normalize('.gitignore'), | ||
normalize('imignored/keep.module.js'), | ||
normalize('index.js') | ||
]) | ||
) | ||
}) | ||
|
||
it('should process_config output', async function() { | ||
const fp = await mockPrompts( | ||
join(tplPath, 'process_config'), | ||
{ | ||
// value: 'ojbk' | ||
}, | ||
join(outputRoot, 'process_config') | ||
) | ||
|
||
expect(Object.keys(fp.tree)).toEqual( | ||
expect.arrayContaining([ | ||
normalize('.gitignore'), | ||
normalize('imignored/keep.module.js'), | ||
normalize('index.js') | ||
]) | ||
) | ||
expect(await fp.writeToFile(null, { overwrite: true })).toBeTruthy() | ||
|
||
expect( | ||
await readdirDeep(join(outputRoot, 'process_config')) | ||
).toEqual( | ||
expect.arrayContaining([ | ||
normalize('.gitignore'), | ||
normalize('imignored/keep.module.js'), | ||
normalize('index.js') | ||
]) | ||
) | ||
expect( | ||
require(join(outputRoot, 'process_config', 'index.js')) | ||
).toBe('process_config') | ||
|
||
await fileSystem.cleanDir(join(outputRoot, 'process_config')) | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
packages/edam/src/__tests__/fixture/edam/process_config/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @file index | ||
* @author Cuttle Cong | ||
* @date 2018/3/28 | ||
* @description | ||
*/ | ||
|
||
module.exports = function(/*options*/) { | ||
return { | ||
prompts: [ | ||
{ | ||
name: 'username', | ||
type: 'input', | ||
default: '${git.name}' | ||
}, | ||
{ | ||
name: 'value', | ||
type: 'input', | ||
default: '${baseName}' | ||
} | ||
], | ||
process(answer) { | ||
console.log('answer.username', answer.username) | ||
return { | ||
ignore: ['im_ignored', 'imignored/*', '!imignored/keep*'], | ||
variables: { | ||
haha: 'hhhh' | ||
}, | ||
hooks: { | ||
assets: [ | ||
function(assets) { | ||
console.log(assets) | ||
} | ||
] | ||
}, | ||
usefulHook: { | ||
gitInit: true | ||
} | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/edam/src/__tests__/fixture/edam/process_config/template/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= JSON.stringify(_.file) %> |
Empty file.
10 changes: 10 additions & 0 deletions
10
packages/edam/src/__tests__/fixture/edam/process_config/template/imignored/a.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/edam/src/__tests__/fixture/edam/process_config/template/imignored/keep.module.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @loader module?indent=4 | ||
|
||
module.exports = function (variables) { | ||
return Object.assign({}, { | ||
name: variables.value, | ||
version: '2.3.5' | ||
}) | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/edam/src/__tests__/fixture/edam/process_config/template/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @file index | ||
* @author <%= JSON.stringify(_.file) %> | ||
* @date 2018/3/28 | ||
* @description | ||
*/ | ||
|
||
module.exports = '<%= value %>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters