Skip to content

Commit e81c30f

Browse files
committed
update.
1 parent 1d57cbf commit e81c30f

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
coverage
3+
.idea
4+
npm-debug.log
5+
package-lock.json

bin/build.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fsAction = require('../lib/fsAction');
2+
const chalk = require('chalk');
3+
4+
console.log(`\n`);
5+
const actions = [
6+
['remove', '/build', 'Remove a folder called `build`.'],
7+
['mkdir', '/build', 'Create a folder called `build`.'],
8+
['copy', '/app', '/build/app', 'Copy the `app` folder to the `build` directory.'],
9+
['copy', '/config', '/build/config', 'Copy the `config` folder to the `build` directory.'],
10+
['rebuildNpmConfig', '/package.json' , '/build/package.json', 'Rebuild `package.json`'],
11+
['copy', '/README.md' , '/build/README.md', 'Copy the `README.md` file to the `build` directory']
12+
];
13+
fsAction(actions);
14+
console.log(`\n${chalk.bgGreen(chalk.black((' DONE ')))} ${chalk.green('Build complete.')}\n`);

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const build = require('./lib/build');
2+
3+
module.exports = build;

lib/fsAction.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const fs = require('fs-extra');
2+
const path = require('path');
3+
const chalk = require('chalk');
4+
const getTime = require('../lib/time');
5+
const base = path.resolve('.');
6+
7+
let actionFn = {
8+
remove: function(_path) {
9+
fs.removeSync(base + _path);
10+
},
11+
12+
mkdir: function(_path) {
13+
fs.mkdirSync(base + _path);
14+
},
15+
16+
copy: function(source, destination) {
17+
fs.copySync(base + source, base + destination);
18+
},
19+
20+
rebuildNpmConfig: function(source, destination) {
21+
let fullSource = base + source;
22+
let fullDestination = base + destination;
23+
let json = JSON.parse(fs.readFileSync(fullSource, 'utf-8'));
24+
let newJson = {
25+
"name": "jscms-server-template",
26+
"version": json.version,
27+
"description": "jscms-server's template for jscms-cli",
28+
"private": true,
29+
"dependencies": json.dependencies,
30+
"devDependencies": {},
31+
"engines": json.engines,
32+
"scripts": {
33+
"start": json.scripts.start,
34+
"stop": json.scripts.stop
35+
},
36+
"repository": json.repository,
37+
"author": json.author,
38+
"license": json.license
39+
}
40+
fs.writeFileSync(fullDestination, JSON.stringify(newJson, null , 2));
41+
}
42+
}
43+
44+
function fsAction(actions) {
45+
actions.forEach(a => {
46+
let actName = a[0];
47+
let aFn = actionFn[actName];
48+
let logMsg = a[a.length - 1];
49+
let parameter = a.splice(0);
50+
parameter.shift();
51+
parameter.pop();
52+
if ( typeof aFn === 'function' ) {
53+
aFn.apply(null, parameter);
54+
console.log(`${chalk.green(getTime())} ${logMsg}`);
55+
}
56+
});
57+
}
58+
59+
module.exports = fsAction;

lib/time.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function getTime() {
2+
let date = new Date();
3+
return '[' + date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + ']';
4+
}
5+
6+
module.exports = getTime;

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "jscms-server-build-build",
3+
"version": "0.0.1",
4+
"description": "jscms-server-build",
5+
"bin": {
6+
"jscms-server-build": "bin/build.js"
7+
},
8+
"files": [
9+
"index.js",
10+
"README.md",
11+
"bin",
12+
"lib",
13+
"LICENSE"
14+
],
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/js-cms/jscms-server-build.git"
21+
},
22+
"author": "zhibing <[email protected]>",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/js-cms/jscms-server-build/issues"
26+
},
27+
"homepage": "https://github.com/js-cms/jscms-server-build#readme",
28+
"dependencies": {
29+
"chalk": "^2.4.2",
30+
"fs-extra": "^7.0.1"
31+
}
32+
}

0 commit comments

Comments
 (0)