create-catalyst-app 0.1.0-beta.2 → 0.1.0-beta.4
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/codemod/new-route/template.js +4 -4
- package/codemod/new-route/utils.js +33 -5
- package/package.json +2 -2
- package/scripts/cli.cjs +30 -23
- package/templates/none-js/package.json +1 -1
- package/templates/none-ts/package.json +1 -1
- package/templates/redux-js/package.json +1 -1
- package/templates/redux-ts/package.json +1 -1
- package/templates/rtk-js/package.json +1 -1
- package/templates/rtk-ts/package.json +1 -1
|
@@ -4,7 +4,7 @@ const pc = require("picocolors")
|
|
|
4
4
|
|
|
5
5
|
// Function to create component using given input
|
|
6
6
|
function createNewComponent({ componentName, containersDir }) {
|
|
7
|
-
const componentPath = path.
|
|
7
|
+
const componentPath = `${containersDir}${path.sep}${componentName}${path.sep}${componentName}.js`
|
|
8
8
|
|
|
9
9
|
// Component template
|
|
10
10
|
const componentTemplate = `import React from 'react';
|
|
@@ -27,7 +27,7 @@ function createNewComponent({ componentName, containersDir }) {
|
|
|
27
27
|
|
|
28
28
|
// Function to create rtk reducer file using given input
|
|
29
29
|
function createRTKReducerFile({ componentName, containersDir, reducerName }) {
|
|
30
|
-
const reducerPath = path.
|
|
30
|
+
const reducerPath = `${containersDir}${path.sep}${componentName}${path.sep}reducer.js`
|
|
31
31
|
|
|
32
32
|
// rtk reducer template
|
|
33
33
|
const reducerTemplate = `import { createSlice } from "@reduxjs/toolkit"
|
|
@@ -56,7 +56,7 @@ export const ${reducerName}Reducer = appSlice.reducer
|
|
|
56
56
|
|
|
57
57
|
// Function to create redux action file using given input
|
|
58
58
|
function createReduxActionFile({ componentName, containersDir, reducerName }) {
|
|
59
|
-
const actionsPath = path.
|
|
59
|
+
const actionsPath = `${containersDir}${path.sep}${componentName}${path.sep}actions.js`
|
|
60
60
|
|
|
61
61
|
// redux action template
|
|
62
62
|
const actionTemplate = `const createActionTypes = (prefix, actionTypeList = []) => {
|
|
@@ -84,7 +84,7 @@ export const reduxTest = () => {
|
|
|
84
84
|
|
|
85
85
|
// Function to create redux reducer file using given input
|
|
86
86
|
function createReduxReducerFile({ componentName, containersDir, reducerName }) {
|
|
87
|
-
const reducerPath = path.
|
|
87
|
+
const reducerPath = `${containersDir}${path.sep}${componentName}${path.sep}reducer.js`
|
|
88
88
|
|
|
89
89
|
// redux reducer template
|
|
90
90
|
const reducerTemplate = `import { ${reducerName}Actions } from "./actions"
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const fs = require("fs")
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const pc = require("picocolors")
|
|
4
|
-
const {
|
|
4
|
+
const { execFileSync } = require("child_process")
|
|
5
|
+
|
|
6
|
+
const executable = (command) => (process.platform === "win32" ? `${command}.cmd` : command)
|
|
5
7
|
|
|
6
8
|
// validates router path
|
|
7
9
|
function validatePath(path) {
|
|
@@ -60,14 +62,40 @@ function createDirectory({ componentName, containersDir }) {
|
|
|
60
62
|
|
|
61
63
|
// adds route object inside src/js/route/index.js file
|
|
62
64
|
function createNewRoute({ componentName, routePath, routeTransformerPath }) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
execFileSync(
|
|
66
|
+
executable("jscodeshift"),
|
|
67
|
+
[
|
|
68
|
+
"--silent",
|
|
69
|
+
"-t",
|
|
70
|
+
routeTransformerPath,
|
|
71
|
+
"--routePath",
|
|
72
|
+
routePath,
|
|
73
|
+
"--componentName",
|
|
74
|
+
componentName,
|
|
75
|
+
"src/js/routes/index.js",
|
|
76
|
+
],
|
|
77
|
+
{ stdio: "inherit" }
|
|
78
|
+
)
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
// adds newly created reducer into src/js/store/index.js file
|
|
68
82
|
function createReducerEntryInStore({ componentName, routePath, reducerTransformerPath, reducerName }) {
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
execFileSync(
|
|
84
|
+
executable("jscodeshift"),
|
|
85
|
+
[
|
|
86
|
+
"--silent",
|
|
87
|
+
"-t",
|
|
88
|
+
reducerTransformerPath,
|
|
89
|
+
"--reducerName",
|
|
90
|
+
reducerName,
|
|
91
|
+
"--routePath",
|
|
92
|
+
routePath,
|
|
93
|
+
"--componentName",
|
|
94
|
+
componentName,
|
|
95
|
+
"src/js/store/index.js",
|
|
96
|
+
],
|
|
97
|
+
{ stdio: "inherit" }
|
|
98
|
+
)
|
|
71
99
|
}
|
|
72
100
|
|
|
73
101
|
// converts string to camel case
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-catalyst-app",
|
|
3
3
|
"bin": "scripts/cli.cjs",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.4",
|
|
5
5
|
"description": "cli package to scaffold Catalyst application",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"jscodeshift": "^0.16.0",
|
|
19
19
|
"picocolors": "^0.1.0",
|
|
20
20
|
"prompts": "^2.4.0",
|
|
21
|
-
"tar": "^
|
|
21
|
+
"tar": "^7.5.15",
|
|
22
22
|
"validate-npm-package-name": "^5.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
package/scripts/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { execSync } = require("child_process")
|
|
2
|
+
const { execFileSync, execSync } = require("child_process")
|
|
3
3
|
const Commander = require("commander")
|
|
4
4
|
const { Option } = require("commander")
|
|
5
5
|
const prompts = require("prompts")
|
|
@@ -10,6 +10,7 @@ const fs = require("fs")
|
|
|
10
10
|
var validate = require("validate-npm-package-name")
|
|
11
11
|
const packageJson = require("../package.json")
|
|
12
12
|
const packageRoot = path.join(__dirname, "..")
|
|
13
|
+
const executable = (command) => (process.platform === "win32" ? `${command}.cmd` : command)
|
|
13
14
|
|
|
14
15
|
let projectName = null
|
|
15
16
|
const program = new Commander.Command()
|
|
@@ -160,17 +161,25 @@ const program = new Commander.Command()
|
|
|
160
161
|
})()
|
|
161
162
|
function packNpmPackage(packageName, packageVersion, tempDir) {
|
|
162
163
|
const tarballFileName = `${packageName}-${packageVersion}.tgz`
|
|
163
|
-
const tarballFilePath = path.
|
|
164
|
+
const tarballFilePath = `${tempDir}${path.sep}${tarballFileName}`
|
|
164
165
|
|
|
165
166
|
try {
|
|
166
167
|
if (process.env.CREATE_CATALYST_APP_PACK_SOURCE === "local") {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
execFileSync(
|
|
169
|
+
executable("npm"),
|
|
170
|
+
["pack", `--pack-destination=${tempDir}`, "--silent"],
|
|
171
|
+
{
|
|
172
|
+
cwd: packageRoot,
|
|
173
|
+
}
|
|
174
|
+
)
|
|
170
175
|
} else {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
execFileSync(
|
|
177
|
+
executable("npm"),
|
|
178
|
+
["pack", `${packageName}@${packageVersion}`, "--silent"],
|
|
179
|
+
{
|
|
180
|
+
cwd: tempDir,
|
|
181
|
+
}
|
|
182
|
+
)
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
return tarballFilePath
|
|
@@ -193,22 +202,20 @@ const program = new Commander.Command()
|
|
|
193
202
|
tar.extract({
|
|
194
203
|
file: packageFilePath,
|
|
195
204
|
sync: true,
|
|
196
|
-
filter: (path, entry) => {
|
|
197
|
-
return subDirectoriesToExtract.reduce((acc, item) => {
|
|
198
|
-
return acc || path.startsWith(item)
|
|
199
|
-
}, false)
|
|
200
|
-
},
|
|
201
205
|
cwd: path.join(process.cwd()),
|
|
202
|
-
|
|
206
|
+
filter: (entryPath, entry) => {
|
|
207
|
+
const shouldExtract = subDirectoriesToExtract.reduce((acc, item) => {
|
|
208
|
+
return acc || entryPath.startsWith(item)
|
|
209
|
+
}, false)
|
|
210
|
+
if (!shouldExtract) return false
|
|
203
211
|
if (entry.path.startsWith(commonCodeDirectory)) {
|
|
204
212
|
entry.path = entry.path.replace(commonCodeDirectory, extractionDestination)
|
|
205
|
-
}
|
|
206
|
-
if (entry.path.startsWith(selectedTemplateCode)) {
|
|
213
|
+
} else if (entry.path.startsWith(selectedTemplateCode)) {
|
|
207
214
|
entry.path = entry.path.replace(selectedTemplateCode, extractionDestination)
|
|
208
|
-
}
|
|
209
|
-
if (entry.path.startsWith(tailwindCodeDirectory)) {
|
|
215
|
+
} else if (entry.path.startsWith(tailwindCodeDirectory)) {
|
|
210
216
|
entry.path = entry.path.replace(tailwindCodeDirectory, extractionDestination)
|
|
211
217
|
}
|
|
218
|
+
return true
|
|
212
219
|
},
|
|
213
220
|
})
|
|
214
221
|
} catch (e) {
|
|
@@ -261,12 +268,12 @@ program
|
|
|
261
268
|
program.parse(process.argv)
|
|
262
269
|
|
|
263
270
|
function runMcpSetup(mcpDir, cwd = process.cwd()) {
|
|
264
|
-
const pkgPath = path.
|
|
271
|
+
const pkgPath = `${mcpDir}${path.sep}package.json`
|
|
265
272
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
266
273
|
pkg.dependencies["better-sqlite3"] = "^12.8.0"
|
|
267
274
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
|
|
268
275
|
|
|
269
|
-
const mcpNodeModules = path.
|
|
276
|
+
const mcpNodeModules = `${mcpDir}${path.sep}node_modules`
|
|
270
277
|
let needsInstall = !fs.existsSync(mcpNodeModules)
|
|
271
278
|
|
|
272
279
|
if (!needsInstall) {
|
|
@@ -284,7 +291,7 @@ function runMcpSetup(mcpDir, cwd = process.cwd()) {
|
|
|
284
291
|
execSync("npm install", { cwd: mcpDir, stdio: "inherit" })
|
|
285
292
|
}
|
|
286
293
|
|
|
287
|
-
|
|
294
|
+
execFileSync(process.execPath, [`${mcpDir}${path.sep}setup.js`], { cwd, stdio: "inherit" })
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
async function promptStateManagement() {
|
|
@@ -397,7 +404,7 @@ function validateOptions(cmd) {
|
|
|
397
404
|
function deleteDirectory(dirPath) {
|
|
398
405
|
if (dirPath && fs.existsSync(dirPath)) {
|
|
399
406
|
fs.readdirSync(dirPath).forEach((file) => {
|
|
400
|
-
const currentPath = path.
|
|
407
|
+
const currentPath = `${dirPath}${path.sep}${file}`
|
|
401
408
|
if (fs.lstatSync(currentPath).isDirectory()) {
|
|
402
409
|
deleteDirectory(currentPath)
|
|
403
410
|
} else {
|
|
@@ -412,7 +419,7 @@ function deleteDirectory(dirPath) {
|
|
|
412
419
|
function createGitignore(projectName) {
|
|
413
420
|
const gitiIgnorePatterns = ["node_modules", "build", "logs"]
|
|
414
421
|
|
|
415
|
-
const gitignorePath =
|
|
422
|
+
const gitignorePath = `${process.cwd()}${path.sep}${projectName}${path.sep}.gitignore`
|
|
416
423
|
|
|
417
424
|
if (fs.existsSync(gitignorePath)) {
|
|
418
425
|
console.log(".gitignore already exists. Please rename or remove it before running the script.")
|