@aleleba/create-node-ts-graphql-server 1.1.1 → 1.1.2
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/bin/cli.js +63 -4
- package/package.json +2 -2
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { execSync } = require('child_process');
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
|
|
3
5
|
const isWin = process.platform === "win32";
|
|
4
6
|
|
|
5
7
|
const runCommand = command => {
|
|
@@ -12,22 +14,79 @@ const runCommand = command => {
|
|
|
12
14
|
return true;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
const replaceTextOnFile = ({
|
|
18
|
+
file,
|
|
19
|
+
textToBeReplaced,
|
|
20
|
+
textReplace,
|
|
21
|
+
arrOfObjectsBeReplaced
|
|
22
|
+
}) => {
|
|
23
|
+
let data
|
|
24
|
+
try{
|
|
25
|
+
data = fs.readFileSync(file, 'utf8');
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error(`Failed to read file ${file}`, e);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let result
|
|
32
|
+
if(arrOfObjectsBeReplaced){
|
|
33
|
+
arrOfObjectsBeReplaced.forEach( obj => {
|
|
34
|
+
if(result){
|
|
35
|
+
result = result.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' ');
|
|
36
|
+
}else{
|
|
37
|
+
result = data.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' ');
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}else{
|
|
41
|
+
result = data.replace(textToBeReplaced, textReplace).replace(/^\s*[\r\n]/gm, ' ');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try{
|
|
45
|
+
console.log('text changed')
|
|
46
|
+
fs.writeFileSync(file, result, 'utf8');
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(`Failed to read file ${file}`, e);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
15
53
|
const repoName = process.argv[2];
|
|
16
54
|
const gitCheckoutCommand = `git clone --depth 1 https://github.com/aleleba/create-node-ts-graphql-server ${repoName}`;
|
|
55
|
+
console.log(`Cloning the repository with name ${repoName}`);
|
|
56
|
+
const checkedOut = runCommand(gitCheckoutCommand);
|
|
57
|
+
if(!checkedOut) process.exit(-1);
|
|
58
|
+
|
|
59
|
+
const actualVersion = runCommandWithOutput(`cd ${repoName} && node -p "require('./package.json').version"`).toString().trim()
|
|
60
|
+
|
|
17
61
|
const installDepsCommand = `cd ${repoName} && npm install --legacy-peer-deps`;
|
|
18
62
|
const cleanGitHistoryCommand = `cd ${repoName} && rm -rf .git && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
|
|
19
63
|
const cleanGitHistoryCommandWindows = `cd ${repoName} && rmdir .git /s /q && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
|
|
20
64
|
const deleteFoldersCommand = `cd ${repoName} && rm -rf .github && rm -rf bin`
|
|
21
65
|
const deleteFoldersCommandWindows = `cd ${repoName} && rmdir .github /s /q && rmdir bin /s /q`
|
|
22
66
|
|
|
23
|
-
console.log(`Cloning the repository with name ${repoName}`);
|
|
24
|
-
const checkedOut = runCommand(gitCheckoutCommand);
|
|
25
|
-
if(!checkedOut) process.exit(-1);
|
|
26
|
-
|
|
27
67
|
console.log(`Installing dependencies for ${repoName}`);
|
|
28
68
|
const installedDeps = runCommand(installDepsCommand);
|
|
29
69
|
if(!installedDeps) process.exit(-1);
|
|
30
70
|
|
|
71
|
+
console.log(`Replacing Json data for ${repoName}`);
|
|
72
|
+
replaceTextOnFile({
|
|
73
|
+
file: `./${repoName}/package.json`,
|
|
74
|
+
arrOfObjectsBeReplaced: [
|
|
75
|
+
{
|
|
76
|
+
textToBeReplaced: `"bin": "./bin/cli.js",`,
|
|
77
|
+
textReplace: ``
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
textToBeReplaced: `"version": "${actualVersion}",`,
|
|
81
|
+
textReplace: `"version": "0.0.1",`
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
textToBeReplaced: `"name": "@aleleba/create-node-ts-graphql-server",`,
|
|
85
|
+
textReplace: `"name": "${repoName}",`
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
|
|
31
90
|
console.log(`Cleaning History of Git for ${repoName}`);
|
|
32
91
|
const cleanGitHistory = isWin ? runCommand(cleanGitHistoryCommandWindows) : runCommand(cleanGitHistoryCommand);
|
|
33
92
|
if(!cleanGitHistory) process.exit(-1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleleba/create-node-ts-graphql-server",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Node with Typescript and GraphQL Server",
|
|
5
5
|
"bin": "./bin/cli.js",
|
|
6
6
|
"main": "index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@babel/preset-typescript": "^7.18.6",
|
|
54
54
|
"@babel/register": "^7.18.9",
|
|
55
55
|
"@types/jest": "^28.1.6",
|
|
56
|
-
"@types/node": "^18.6.
|
|
56
|
+
"@types/node": "^18.6.4",
|
|
57
57
|
"@types/webpack": "^5.28.0",
|
|
58
58
|
"@types/webpack-node-externals": "^2.5.3",
|
|
59
59
|
"@typescript-eslint/eslint-plugin": "^5.32.0",
|