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