@reactful/create 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -27
- package/package.json +1 -1
package/index.js
CHANGED
@@ -38,37 +38,38 @@ async function prompting(answers) {
|
|
38
38
|
if (!answers.project) throw 'Required project name!'
|
39
39
|
|
40
40
|
const destination = path.join(process.cwd(), answers.project)
|
41
|
-
const
|
41
|
+
const downloadPath = path.join(destination, 'temp')
|
42
42
|
|
43
43
|
await createDirectory(destination)
|
44
44
|
|
45
45
|
console.log('- loading NPM...')
|
46
|
-
await download('@reactful/create',
|
46
|
+
await download('@reactful/create', downloadPath)
|
47
47
|
|
48
48
|
console.log('- creating .env...')
|
49
49
|
const env = `PORT=333\nMINIFY=FALSE`
|
50
50
|
fs.writeFileSync(`${destination}/.env`, env)
|
51
51
|
|
52
52
|
console.log('- copying template...')
|
53
|
-
await
|
54
|
-
await
|
55
|
-
|
56
|
-
|
57
|
-
console.log('- templating project...')
|
53
|
+
await copyPath(`${downloadPath}/commons`, destination)
|
54
|
+
await copyPath(`${downloadPath}/templates/${answers.template}`, destination)
|
55
|
+
|
56
|
+
console.log('- renaming project...')
|
58
57
|
renamingJSON(destination, answers.project)
|
59
58
|
|
60
59
|
console.log('- installing dependencies...\n')
|
61
60
|
process.chdir(answers.project)
|
62
61
|
execSync(`bun install`)
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
if (answers.vscode) {
|
64
|
+
spawn("code", ['.'])
|
65
|
+
|
66
|
+
const pathVSCode = `${destination}/.vscode`
|
67
|
+
|
68
|
+
await createDirectory(pathVSCode)
|
69
|
+
await copyPath(`${downloadPath}/vscode`, pathVSCode)
|
71
70
|
}
|
71
|
+
|
72
|
+
await removeDirectory(downloadPath)
|
72
73
|
}
|
73
74
|
|
74
75
|
function renamingJSON(directory, projectName) {
|
@@ -81,17 +82,6 @@ function renamingJSON(directory, projectName) {
|
|
81
82
|
fs.writeFileSync(url, JSON.stringify(obj, null, 3))
|
82
83
|
}
|
83
84
|
|
84
|
-
async function copyTemplate(temporaryPath, subdirectory, destination) {
|
85
|
-
try {
|
86
|
-
const folder = path.join(temporaryPath, subdirectory)
|
87
|
-
await copyFolder(folder, destination)
|
88
|
-
|
89
|
-
} catch (error) {
|
90
|
-
console.error('copyTemplate')
|
91
|
-
throw error
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
85
|
async function download(packageName, directory) {
|
96
86
|
try {
|
97
87
|
await createDirectory(directory)
|
@@ -134,7 +124,7 @@ function removeDirectory(directory) {
|
|
134
124
|
else fs.rmSync(directory, { recursive: true })
|
135
125
|
}
|
136
126
|
|
137
|
-
function
|
127
|
+
function copyPath(source, target) {
|
138
128
|
if (!fs.existsSync(target)) fs.mkdirSync(target)
|
139
129
|
|
140
130
|
fs.readdirSync(source).forEach(function (file) {
|
@@ -142,7 +132,7 @@ function copyFolder(source, target) {
|
|
142
132
|
const targetPath = path.join(target, file)
|
143
133
|
|
144
134
|
if (fs.lstatSync(currentPath).isDirectory())
|
145
|
-
|
135
|
+
copyPath(currentPath, targetPath)
|
146
136
|
|
147
137
|
else fs.copyFileSync(currentPath, targetPath)
|
148
138
|
})
|