-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
138 lines (116 loc) · 4.85 KB
/
Copy pathcli.js
File metadata and controls
138 lines (116 loc) · 4.85 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env node
//----------------------------------------------------------------------------------------------------------------------
// Main Spiderworks Script
//
// @module
//----------------------------------------------------------------------------------------------------------------------
const path = require('path');
const chalk = require('chalk');
const program = require('commander');
const pkg = require('./package');
const paths = require('./lib/paths');
const contentGen = require('./lib/generator');
const devServer = require('./lib/devel');
//----------------------------------------------------------------------------------------------------------------------
program.version(pkg.version);
//----------------------------------------------------------------------------------------------------------------------
// `create` command
//----------------------------------------------------------------------------------------------------------------------
program
.command('create <site>')
.alias('new')
.description('Creates a new default site with the name <site>.')
.action((site) =>
{
console.log(chalk.magenta('>> ') + `Creating "${ chalk.cyan(site) }".`);
contentGen.create(site)
.then(() =>
{
console.log(chalk.yellow('>> ') + chalk.green('Done.'));
})
.catch((error) =>
{
console.error(`Create Error: \n ${ error.stack || error }`);
process.exit(1);
});
});
//----------------------------------------------------------------------------------------------------------------------
// `clean` command
//----------------------------------------------------------------------------------------------------------------------
program
.command('clean [directory]')
.description('Cleans the generated source files from <directory>.')
.action((directory) =>
{
let sourceDir = process.cwd();
if(directory)
{
sourceDir = path.join(sourceDir, directory);
} // end if
paths.sourceDir = sourceDir;
console.log(chalk.magenta('>> ') + `Cleaning "${ chalk.cyan(sourceDir) }".`);
contentGen.clean(sourceDir)
.then(() =>
{
console.log(chalk.yellow('>> ') + chalk.green('Done.'));
})
.catch((error) =>
{
console.error(`Clean Error: \n ${ error.stack || error }`);
process.exit(1);
});
});
//----------------------------------------------------------------------------------------------------------------------
// `generate` command
//----------------------------------------------------------------------------------------------------------------------
program
.command('generate [directory]')
.description('Generates the site from the source files in <directory>.')
.option("-c, --clean", "clean the output directory before generation")
.action((directory, options) =>
{
let sourceDir = process.cwd();
if(directory)
{
sourceDir = path.join(sourceDir, directory);
} // end if
paths.sourceDir = sourceDir;
console.log(chalk.magenta('>> ') + `Generating from "${ chalk.cyan(sourceDir) }".`);
contentGen.generate(sourceDir, { clean: options.clean })
.then(() =>
{
console.log(chalk.yellow('>> ') + chalk.green('Done.'));
})
.catch((error) =>
{
console.error(chalk.red('>>') + `Generation Error: \n ${ error.stack || error }`);
process.exit(1);
});
});
//----------------------------------------------------------------------------------------------------------------------
// `watch` command
//----------------------------------------------------------------------------------------------------------------------
program
.command('watch [directory]')
.description('Starts a development server and watches the source folder for changes.')
.option("-p, --port <port>", "The port to start the development HTTP server on")
.action((directory, options) =>
{
let sourceDir = process.cwd();
if(directory)
{
sourceDir = path.join(sourceDir, directory);
} // end if
paths.sourceDir = sourceDir;
// Start the dev server
devServer.start(sourceDir, { port: options.port });
});
//----------------------------------------------------------------------------------------------------------------------
// Print the help text if nothing was input
if(process.argv.length < 3)
{
program.outputHelp();
} // end if
// Parse the arguments
program.parse(process.argv);
//----------------------------------------------------------------------------------------------------------------------