-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
230 lines (228 loc) · 8.1 KB
/
cli.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env node
const prog = require('caporal');
const chalk = require('chalk');
const Config = require('./internals/models/config');
const Validate = require('./internals/scripts/validate');
const Build = require('./internals/scripts/build');
const Harvest = require('./internals/scripts/harvest');
const Content = require('./internals/models/content');
const Site = require('./internals/models/site');
const config = new Config(__dirname);
const path = require('path');
const shell = require('shelljs');
prog
.version('0.0.1')
.command('validate-site-contents')
.help('validates a site contents based off of a schema')
.argument('site', 'The site to validate')
.action((args) => {
Validate.contents(args.site, config);
})
.command('validate-site')
.help('validates a site')
.argument('site', 'The site to validate')
.action((args) => {
const site = new Site(args.site, config);
site.validate((err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Config file is valid.')); // eslint-disable-line no-console
}
});
})
.command('build-collection-data')
.help('builds collection data for a site exporting it to the build dir')
.argument('site', 'The site to build')
.argument('env', 'The environment to build')
.action((args) => {
console.log("Exporting data for " + args.site); // eslint-disable-line
Build.docsExport(args.site, config, args.env, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Collection data exported.')); // eslint-disable-line no-console
}
});
})
.command('build-collection-data-item')
.help('builds collection data for a collection item')
.argument('site', 'The site to build from')
.argument('collection', 'The colleciton to build from')
.argument('interraId', 'The internal id of the item')
.argument('env', 'The environment to build')
.action((args) => {
Build.docExport(args.site, config, args.collection, args.interraId, args.env, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('File exported.')); // eslint-disable-line no-console
}
});
})
.command('build-config')
.help('builds config file for a site')
.argument('site', 'The site to build from')
.action((args) => {
Build.configExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Config exported.')); // eslint-disable-line no-console
}
});
})
.command('build-datajson')
.help('builds data.json file for a site')
.argument('site', 'The site to index from')
.action((args) => {
Build.datajsonExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Data.json built.')); // eslint-disable-line no-console
}
});
})
.command('build-routes')
.help('builds collection data for a site exporting it to the build dir')
.argument('site', 'The site to build')
.action((args) => {
Build.routesExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Routes built.')); // eslint-disable-line no-console
}
});
})
.command('build-sitemap')
.help('builds sitemap file for a site')
.argument('site', 'The site to build from')
.action((args) => {
Build.siteMapExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(err)); // eslint-disable-line no-console
} else {
console.log(chalk.green('Sitemap built.')); // eslint-disable-line no-console
}
});
})
.command('build-media')
.help('builds media files for a site')
.argument('site', 'The site to build from')
.action((args) => {
Build.mediaExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Media files built.')); // eslint-disable-line no-console
}
});
})
.command('build-schema')
.help('builds schema file for a site')
.argument('site', 'The site to build from')
.action((args) => {
Build.schemaExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Schema built.')); // eslint-disable-line no-console
}
});
})
.command('build-search')
.help('builds search index for a site')
.argument('site', 'The site to index from')
.action((args) => {
Build.searchExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Search built.')); // eslint-disable-line no-console
}
});
})
.command('build-swagger')
.help('builds swagger json file for a site')
.argument('site', 'The site to index from')
.action((args) => {
Build.swaggerExport(args.site, config, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Swagger build completed.')); // eslint-disable-line no-console
}
});
})
.command('build-apis')
.help('builds all api files for a site')
.argument('site', 'The site to index from')
.argument('env', 'The environment to build')
.action((args) => {
Build.all(args.site, config, args.env, (err) => {
if (err) {
console.log(chalk.red(JSON.stringify(err))); // eslint-disable-line no-console
} else {
console.log(chalk.green('Build completed.')); // eslint-disable-line no-console
}
});
})
.command('build-site')
.help('builds react app a site')
.argument('site', 'The site to index from')
.action((args) => {
process.env.NODE_ENV = 'production';
process.env.SITE = args.site;
process.env.PATH += (path.delimiter + path.join(__dirname, 'node_modules', '.bin'));
shell.exec('node_modules/.bin/webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules');
})
.command('run-dev')
.help('runs dev server for a site.')
.argument('site', 'The site run')
.action((args) => {
process.env.NODE_ENV = 'development';
process.env.SITE = args.site;
require('./server'); // eslint-disable-line
})
.command('run-dev-dll')
.help('builds dll for dev server.')
.action(() => {
process.env.NODE_ENV = 'development';
shell.exec('./internals/scripts/dependencies.js');
})
.command('run-dev-tunnel')
.help('runs dev server for a site.')
.argument('site', 'The site run')
.action((args) => {
process.env.NODE_ENV = 'development';
process.env.SITE = args.site;
process.env.ENABLE_TUNNEL = true;
require('./server'); // eslint-disable-line
})
.command('harvest-cache')
.argument('site', 'The site to import into')
.help('Caches harvest sources.')
.action((args) => {
Harvest.cache(args.site, config);
})
.command('harvest-run')
.argument('site', 'The site to import into')
.help('Runs a harvest with cached sources.')
.action((args) => {
Harvest.run(args.site, config);
})
.command('load-doc')
.argument('site', 'The site to build from')
.argument('collection', 'The colleciton to build from')
.argument('interraId', 'The internal id of the item')
.help('Runs a harvest with cached sources.')
.action((args) => {
const storage = config.get('storage');
const content = new Content[storage](args.site, config);
content.load(`${args.collection}/${args.interraId}.json`, (err, doc) => {
console.log(err, doc); // eslint-disable-line no-console
});
});
prog.parse(process.argv);