Skip to content

Commit 2d4aebe

Browse files
committed
new feature added
1 parent e5a70b9 commit 2d4aebe

File tree

5 files changed

+73
-1362
lines changed

5 files changed

+73
-1362
lines changed

bin/scion

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ program
4646
require(res('delete'))
4747
})
4848

49+
program
50+
.command('map')
51+
.description('Place files to diffirent position')
52+
.alias('m')
53+
.action(() => {
54+
require(res('map'))
55+
})
56+
4957
program.parse(process.argv)
5058

5159
if(!program.args.length){

commands/map.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const Metalsmith = require('metalsmith')
2+
const layout = require('metalsmith-layouts')
3+
const { resolve } = require('path')
4+
const { prompt } = require('inquirer')
5+
const currentFoler = process.cwd()
6+
7+
let template = require('handlebars').compile
8+
9+
const question = [
10+
{
11+
type: 'input',
12+
name: 'folderPath',
13+
message: 'Path of your Map folder:',
14+
default: '/map',
15+
validate (val) {
16+
if (!val) {
17+
return 'Path is required!'
18+
}
19+
return true
20+
}
21+
}
22+
]
23+
24+
const myPlugin = (file) => {
25+
return (files, metalsmith, done) => {
26+
let content = files[file.name].contents.toString()
27+
let tpl = template(content)
28+
files[file.name].contents = tpl(file.data)
29+
if (file.rename) {
30+
files[file.rename] = files[file.name]
31+
delete files[file.name]
32+
}
33+
metalsmith
34+
.destination(resolve(currentFoler + file.dist))
35+
.clean(true)
36+
done()
37+
}
38+
}
39+
40+
const ignore = (fileMap, fileName, folderPath) => {
41+
let ignoreArr = [resolve(currentFoler + folderPath + '/' + 'map.js')]
42+
fileMap.forEach((file) => {
43+
if (file.name !== fileName) {
44+
ignoreArr.push(resolve(currentFoler + folderPath + '/' + file.name))
45+
}
46+
})
47+
return ignoreArr
48+
}
49+
50+
module.exports = prompt(question).then(({ folderPath }) => {
51+
const fileMap = require(resolve(currentFoler + folderPath + '/map.js'))
52+
53+
for (let i = 0, len = fileMap.length; i < len; i++) {
54+
Metalsmith(__dirname)
55+
.source(resolve(currentFoler + folderPath))
56+
.ignore(ignore(fileMap, fileMap[i].name, folderPath))
57+
.use(myPlugin(fileMap[i]))
58+
.build((err, files) => {
59+
if (err) throw err
60+
})
61+
}
62+
})

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scion-cli",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "A simple CLI for creating your projects",
55
"bin": {
66
"scion": "bin/scion"
@@ -25,7 +25,9 @@
2525
"cli-table": "^0.3.1",
2626
"commander": "^2.9.0",
2727
"download-git-repo": "^1.0.0",
28+
"handlebars": "^4.0.8",
2829
"inquirer": "^3.0.6",
30+
"metalsmith": "^2.3.0",
2931
"ora": "^1.2.0"
3032
}
3133
}

0 commit comments

Comments
 (0)