-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
mod.ts
67 lines (61 loc) · 2.35 KB
/
mod.ts
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
#!/usr/bin/env -S deno --unstable --allow-read --allow-write --allow-net --allow-env --allow-run
export { React, ReactDOM, ReactDOMServer } from './deps.ts';
export { t, Trans } from './src/plugins/i18n.tsx';
import { fs } from './deps.ts';
import { logger } from './src/utils/mod.ts';
import Pagic from './src/Pagic.ts';
export default Pagic;
export * from './src/Pagic.ts';
import { Command } from 'https://deno.land/x/[email protected]/command/mod.ts';
import { Select } from 'https://deno.land/x/[email protected]/prompt/select.ts';
import { Confirm } from 'https://deno.land/x/[email protected]/prompt/confirm.ts';
if (import.meta.main) {
const build = new Command()
.description('Build a static website')
.option('--watch [watch:boolean]', 'Watch file changes to rebuild')
.option('--serve [serve:boolean]', 'Start local service, preview static website')
.option('--port <port:number>', 'Specify the local port of the service')
.action((options: any) => {
const pagic = new Pagic(options);
pagic.build();
if (!options.watch && !options.serve) {
pagic.on('buildFinish', () => Deno.exit(0));
}
});
const init = new Command().description('Init pagic site/theme/plugin').action(async () => {
const mode: string = await Select.prompt({
message: 'Init current dir as a',
options: [
{ name: 'site', value: 'site' },
{ name: 'theme', value: 'theme' },
{ name: 'plugin', value: 'plugin' },
],
});
const pagic = new Pagic();
switch (mode) {
case 'site':
if (await fs.exists('pagic.config.ts')) {
logger.warn('pagic.config.ts already exists, exit');
return;
}
if (await fs.exists('pagic.config.tsx')) {
logger.warn('pagic.config.tsx already exists, exit');
return;
}
await Deno.writeTextFile('pagic.config.ts', 'export default {};\n');
break;
case 'theme':
if (await fs.exists('mod.ts')) {
const confirmed = await Confirm.prompt('mod.ts already exists, do you want to override it?');
if (!confirmed) {
return;
}
}
pagic.generateThemeMod();
break;
default:
logger.error(`Invalid mode ${mode}`);
}
});
await new Command().name('pagic').command('build', build).command('init', init).parse(Deno.args);
}