-
Notifications
You must be signed in to change notification settings - Fork 10
/
unibit.js
executable file
·68 lines (62 loc) · 2.24 KB
/
unibit.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
const yargs = require('yargs');
const path = require('path');
const Unibit = require('./src/unibit');
const Downloader = require('./src/downloader');
const inputDirOption = {
alias: 'i',
describe: 'Unibit site source directory.',
default: function cws() { return process.cwd(); },
defaultDescription: 'current working directory'
};
const buildOptions = yargs => yargs.options({
'input-dir': inputDirOption,
'output-dir': {
alias: 'o',
describe: 'Target directory for the generated site.',
default: function cwsPublic() { return path.join(process.cwd(), 'public'); },
defaultDescription: '"build" folder inside current working directory'
},
'with-banner': {
describe: 'Show stackbit theme banner.',
boolean: true,
defaultDescription: 'Displays the Stackbit theme banner'
},
'ugly-urls': {
describe: 'Generate ugly urls',
boolean: true,
defaultDescription: 'When this flag is missing, Unibit generates pretty URLs by default, unless uglyUrls defined in config.yaml'
}
}).alias('h', 'help');
let argv = yargs
.usage('Usage: $0 <command> [options]')
.command('build', 'Build site', buildOptions)
.command('develop', 'Develop site', buildOptions)
.command('init [path]', 'Initialize new site', yargs => {
yargs.positional('path', {
describe: 'Initializes new starter site in the provided directory',
default: 'unibit-universal'
});
})
.alias('v', 'version')
.demandCommand(1, 'You need to specify at least one command')
.example('$0 build -i path/to/source -o path/to/target', 'Build site from Unibit site located in the "path/to/source" folder and save it in the "path/to/target" folder.')
.wrap(null)
.help()
.argv;
const command = argv._[0];
if (command === 'build' || command === 'develop') {
const unibit = new Unibit({
inputDir: argv.inputDir,
outputDir: argv.outputDir,
withBanner: argv.withBanner,
uglyUrls: argv.uglyUrls,
watch: command === 'develop'
});
unibit.generate();
} else if (command === 'init') {
new Downloader(
'github:stackbithq/stackbit-theme-universal',
argv.path
);
}