-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9690bb0
commit 270b401
Showing
5 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const json = require('format-json') | ||
const inquirer = require('inquirer') | ||
const checkTemplateList = require('../util').checkTemplateList | ||
const writeTemplateList = require('../util').writeTemplateList | ||
|
||
let templateList = checkTemplateList(path.resolve(__dirname, '../template.json')) | ||
|
||
module.exports = inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'dest', | ||
message: 'Input the path you want to exact the template.json to.', | ||
validate(val){ | ||
val = val.trim() | ||
if(!val || !val.length){ | ||
return 'Path can not be empty. You can input `pwd` in your terminal to check the path.' | ||
} | ||
return true | ||
} | ||
} | ||
]) | ||
.then(({ dest }) => { | ||
const jsonPath = path.resolve(__dirname, dest, 'template.json') | ||
|
||
fs.openSync(jsonPath, 'w') | ||
writeTemplateList(templateList, jsonPath) | ||
}) |
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,53 @@ | ||
const download = require('download') | ||
const path = require('path') | ||
const inquirer = require('inquirer') | ||
const writeTemplateList = require('../util').writeTemplateList | ||
const checkTemplateList = require('../util').checkTemplateList | ||
|
||
let templateList = checkTemplateList(path.resolve(__dirname, '../template.json')) | ||
|
||
module.exports = inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'url', | ||
message: 'Url of the template.json: ', | ||
validate(val){ | ||
val = val.trim() | ||
if(!val || !val.length){ | ||
return 'Url can not be empty.' | ||
} | ||
return true | ||
}, | ||
filter(val){ | ||
val = val.trim() | ||
if(val.substring(0, 2) === '//') val = 'http:' + val | ||
return val | ||
} | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'mode', | ||
message: 'Merge or Replace your current template? ', | ||
choices: [ | ||
'merge', 'replace' | ||
] | ||
} | ||
]) | ||
.then(({ url, mode }) => { | ||
download(url, path.resolve(__dirname, '../'), { encoding: 'utf8' }) | ||
.then(data => { | ||
|
||
try { | ||
data = JSON.parse(data) | ||
} catch (error) { | ||
throw new Error('Template is not a json!') | ||
} | ||
|
||
if(mode === 'merge'){ | ||
templateList = Object.assign(templateList, data) | ||
} else if(mode === 'replace'){ | ||
templateList = data | ||
} | ||
writeTemplateList(templateList, path.resolve(__dirname, '../template.json')) | ||
}) | ||
}) |
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