MCPcopy
hub / github.com/shower/shower / handler

Function handler

packages/cli/core/command/new.js:14–85  ·  view source on GitHub ↗
({ cwd, directory: folderName = 'slides', yes: isDefault })

Source from the content-addressed store, hash-verified

12const __dirname = dirname(fileURLToPath(import.meta.url));
13
14async function handler ({ cwd, directory: folderName = 'slides', yes: isDefault }) {
15 // Let's check if such folder exists
16 const directory = path.isAbsolute(folderName) ? folderName : path.join(cwd, folderName);
17
18 if (existsSync(directory)) {
19 const { isForce } = await inquirer.prompt({
20 name: 'isForce',
21 type: 'confirm',
22 default: false,
23 message: `The ${styleText('yellow', folderName)} dir already exists. Do you want to overwrite it?`
24 });
25
26 if (isForce) {
27 await rm(directory, { recursive: true, force: true });
28 } else {
29 process.stdout.write(styleText('red', `\n Creating aborted\n`));
30
31 return;
32 }
33 }
34
35 const options = {
36 template: 'slides',
37 year: (new Date()).getFullYear()
38 };
39
40 const defaultParams = {
41 theme: 'ribbon',
42 ratio: '16:9'
43 };
44
45 const params = [{
46 name: 'theme',
47 type: 'select',
48 message: 'Select theme',
49 choices: ['ribbon', 'material']
50 }, {
51 name: 'ratio',
52 type: 'select',
53 message: 'Select slides ratio',
54 choices: ['16:9', '4:3']
55 }];
56
57 if (isDefault) {
58 Object.assign(options, defaultParams);
59 } else {
60 Object.assign(options, await inquirer.prompt(params));
61 }
62
63 options.ratio = options.ratio.replace(/:/, ' / ');
64
65 process.stdout.write('\n');
66
67 await runTask('Creating slides', async () => {
68 const templateDir = path.join(__dirname, '..', '..', 'templates', options.template);
69
70 await cp(templateDir, directory, { recursive: true });
71

Callers

nothing calls this directly

Calls 2

runTaskFunction · 0.90
installDependenciesFunction · 0.90

Tested by

no test coverage detected