This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
scaffold.ts
65 lines (52 loc) · 1.69 KB
/
scaffold.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
import { Arguments } from 'yargs';
import cpy from 'cpy';
import { debug, log } from '../../lib/messaging';
import { dirs, mainScss } from '../../lib/themes';
import { buildPath, exists } from '../../lib/dirs';
interface ScaffoldArgs {
force: boolean;
}
// yargs exports
export const command = 'scaffold';
export const describe =
'Sets up project scaffolding. This is done automatically when creating a theme for the first time.';
export const builder = {
force: {
alias: 'f',
describe: 'forces creation of project scaffolding',
type: 'boolean',
},
};
export const handler = async (argv: Arguments<ScaffoldArgs>): Promise<void> => {
const workspacePath = buildPath(`<cwd>/<workspace>/`, dirs);
await scaffold(workspacePath, argv.force);
};
// utils
export async function scaffold(workspacePath: string, force = false): Promise<void> {
const workspaceExists = await exists(workspacePath);
if (workspaceExists) {
if (!force) {
log('workspace exists, will not scaffold. If you wish to overwrite, use the --force flag.');
return;
}
}
const themesPath = buildPath('<nodeModules>/<themes>', dirs);
const copyOptions = {
cwd: themesPath,
expandDirectories: true,
overwrite: true,
parents: true,
};
debug(`copying base`);
await cpy('**/*', buildPath(`${workspacePath}/<base>`, dirs), {
...copyOptions,
cwd: buildPath(`${themesPath}/<base>`, dirs),
});
debug(`copying examples`);
await cpy([`**/${mainScss}`, `!${dirs.base}/*.*`], buildPath(`${workspacePath}/<examples>`, dirs), copyOptions);
debug(`copying preview file`);
await cpy('preview', buildPath(`${workspacePath}/<preview>`, dirs), {
cwd: buildPath(`<dirname>/../../`, dirs),
});
log(`project scaffolding complete`);
}