UNPKG

2.04 kBJavaScriptView Raw
1const fs = require('fs');
2const fsExtra = require('fs-extra');
3const path = require('path');
4const prompt = require('@creuna/prompt');
5
6const emoji = require('./emoji');
7const messages = require('./messages');
8
9const getNewAppInput = () => {
10 return prompt({
11 projectName: `${emoji('🚀')} Project name (kebab-case)`,
12 authorName: `${emoji('😸')} Your full name`,
13 authorEmail: `${emoji('💌')} Your email address`,
14 useApiHelper: {
15 text: `${emoji('☁️')} Include API-helper?`,
16 type: Boolean
17 },
18 useMessenger: {
19 text: `${emoji('💬')} Include message helper for API?`,
20 type: Boolean
21 },
22 useAnalyticsHelper: {
23 text: `${emoji('📈')} Include Analytics helper?`,
24 type: Boolean
25 },
26 useResponsiveImages: {
27 text: `${emoji('🖼️')} Include responsive images helper?`,
28 type: Boolean
29 },
30 shouldWriteVSCodeTasks: {
31 text: `${emoji('💻')} Include VS Code shortcuts for react scripts?`,
32 type: Boolean
33 }
34 });
35};
36
37module.exports = async projectPath => {
38 const appCreator = require('@creuna/create-react-app');
39
40 try {
41 await appCreator.canWriteFiles(projectPath);
42
43 const answers = await getNewAppInput();
44 const response = await appCreator.writeFiles(
45 Object.assign({}, answers, { projectPath })
46 );
47
48 if (answers.shouldWriteVSCodeTasks) {
49 fsExtra.ensureDirSync(path.join(projectPath, '.vscode'));
50 fs.copyFileSync(
51 path.join(__dirname, 'tasks.json'),
52 path.join(projectPath, '.vscode', 'tasks.json')
53 );
54 }
55
56 const creunaRcContent = {
57 componentsPath: 'source/components',
58 staticSitePath: 'source/static-site/pages',
59 dataFileContent: '{}',
60 dataFileExtension: 'json'
61 };
62
63 fs.writeFileSync(
64 path.join(projectPath, '.creunarc.json'),
65 JSON.stringify(creunaRcContent, null, 2)
66 );
67
68 messages.emptyLine();
69 messages.messageList(response.messages);
70 messages.emptyLine();
71 } catch (error) {
72 messages.error(error);
73 }
74};