-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
reslate.js
36 lines (30 loc) · 1.17 KB
/
reslate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
'use strict';
const cp = require('child_process');
const path = require('path');
const sh = require('shelljs');
// path.relative is to work around https://github.com/11ty/eleventy/issues/1100
const env = Object.assign({}, process.env, {
'SLATEDIR': path.relative(__dirname, process.cwd()).replace(new RegExp('\\' + path.sep, 'g'), '/'),
'NODE_PATH': path.resolve(__dirname, './node_modules').replace(new RegExp('\\' + path.sep, 'g'), '/')
});
if (process.argv[2] === 'init') {
// TODO test for empty directory except dotfiles?
sh.cp('-R', __dirname+'/source/*', '.');
}
else if (process.argv[2] === 'build') {
cp.spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm',[ 'run', 'build.local' ], { stdio: 'inherit', cwd: __dirname, env }, function(err, output) {
if (err) console.warn(err);
console.log(output);
});
}
else if (process.argv[2] === 'serve') {
cp.spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm',[ 'run', 'serve.local' ], { stdio: 'inherit', cwd: __dirname, env }, function(err, output) {
if (err) console.warn(err);
console.log(output);
});
}
else {
console.warn('Usage: slate [init|build|serve]');
process.exit(1);
}