@aleleba/create-node-ts-graphql-server 1.0.17 → 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.
@@ -0,0 +1,30 @@
1
+ name: NPM testing and publish package
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - uses: actions/setup-node@v3
12
+ with:
13
+ node-version: 16
14
+ registry-url: https://registry.npmjs.org/
15
+ - run: npm ci --legacy-peer-deps
16
+ - run: npm test
17
+
18
+ publish-npm:
19
+ needs: build
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+ - uses: actions/setup-node@v3
24
+ with:
25
+ node-version: 16
26
+ registry-url: https://registry.npmjs.org/
27
+ - run: npm ci --legacy-peer-deps
28
+ - run: npm publish --access=public
29
+ env:
30
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -0,0 +1,33 @@
1
+ name: Testing package
2
+
3
+ on:
4
+ pull_request:
5
+ branches: ['*']
6
+ jobs:
7
+ test:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ node-version: [16.x]
12
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Use Node.js 16
16
+ uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 16
19
+ cache: 'npm'
20
+ registry-url: https://registry.npmjs.org/
21
+ - run: npm ci --legacy-peer-deps
22
+ - run: npm test
23
+ test-build-package:
24
+ needs: test
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v3
28
+ - uses: actions/setup-node@v3
29
+ with:
30
+ node-version: 16
31
+ registry-url: https://registry.npmjs.org/
32
+ - run: npm ci --legacy-peer-deps
33
+ - run: npm run build
package/bin/cli.js CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  const { execSync } = require('child_process');
3
+ var fs = require('fs');
4
+
5
+ const isWin = process.platform === "win32";
3
6
 
4
7
  const runCommand = command => {
5
8
  try{
@@ -11,19 +14,87 @@ const runCommand = command => {
11
14
  return true;
12
15
  }
13
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
+
14
53
  const repoName = process.argv[2];
15
54
  const gitCheckoutCommand = `git clone --depth 1 https://github.com/aleleba/create-node-ts-graphql-server ${repoName}`;
16
- const installDepsCommand = `cd ${repoName} && rm -rf .git && git init && git add . && git commit -m "Initial commit" && npm install --legacy-peer-deps`;
17
-
18
55
  console.log(`Cloning the repository with name ${repoName}`);
19
56
  const checkedOut = runCommand(gitCheckoutCommand);
20
57
  if(!checkedOut) process.exit(-1);
21
58
 
59
+ const actualVersion = runCommandWithOutput(`cd ${repoName} && node -p "require('./package.json').version"`).toString().trim()
60
+
61
+ const installDepsCommand = `cd ${repoName} && npm install --legacy-peer-deps`;
62
+ const cleanGitHistoryCommand = `cd ${repoName} && rm -rf .git && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
63
+ const cleanGitHistoryCommandWindows = `cd ${repoName} && rmdir .git /s /q && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
64
+ const deleteFoldersCommand = `cd ${repoName} && rm -rf .github && rm -rf bin`
65
+ const deleteFoldersCommandWindows = `cd ${repoName} && rmdir .github /s /q && rmdir bin /s /q`
66
+
22
67
  console.log(`Installing dependencies for ${repoName}`);
23
68
  const installedDeps = runCommand(installDepsCommand);
24
69
  if(!installedDeps) process.exit(-1);
25
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
+
90
+ console.log(`Cleaning History of Git for ${repoName}`);
91
+ const cleanGitHistory = isWin ? runCommand(cleanGitHistoryCommandWindows) : runCommand(cleanGitHistoryCommand);
92
+ if(!cleanGitHistory) process.exit(-1);
93
+
26
94
  console.log("Congratulations! You are ready. Follow the following commands to start");
27
95
  console.log(`cd ${repoName}`);
28
96
  console.log('Create a .env file with ENV=development(defauld: production), PORT=4000 (default: 4000), WHITELIST_URLS=your_url(default: http://localhost), GRAPHIQL=true(default: false)');
29
- console.log(`Then you can run: npm start:dev`);
97
+ console.log(`Then you can run: npm start:dev`);
98
+
99
+ const deleteFolders = isWin ? runCommand(deleteFoldersCommandWindows) : runCommand(deleteFoldersCommand);
100
+ if(!deleteFolders) 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.0.17",
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",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "homepage": "https://github.com/aleleba/node-ts-graphql-server#readme",
34
34
  "dependencies": {
35
- "@graphql-tools/schema": "^8.5.0",
35
+ "@graphql-tools/schema": "^8.5.1",
36
36
  "body-parser": "^1.20.0",
37
37
  "cookie-parser": "^1.4.6",
38
38
  "cors": "^2.8.5",
@@ -42,26 +42,26 @@
42
42
  "graphql": "^16.5.0",
43
43
  "graphql-playground-middleware-express": "^1.7.23",
44
44
  "graphql-subscriptions": "^2.0.0",
45
- "graphql-tools": "^8.3.0",
45
+ "graphql-tools": "^8.3.1",
46
46
  "graphql-ws": "^5.9.1",
47
47
  "web-push": "^3.5.0",
48
48
  "ws": "^8.8.1"
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/core": "^7.18.9",
52
- "@babel/preset-env": "^7.18.9",
51
+ "@babel/core": "^7.18.10",
52
+ "@babel/preset-env": "^7.18.10",
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.1",
56
+ "@types/node": "^18.6.4",
57
57
  "@types/webpack": "^5.28.0",
58
58
  "@types/webpack-node-externals": "^2.5.3",
59
- "@typescript-eslint/eslint-plugin": "^5.31.0",
60
- "@typescript-eslint/parser": "^5.31.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.32.0",
60
+ "@typescript-eslint/parser": "^5.32.0",
61
61
  "babel-loader": "^8.2.5",
62
62
  "clean-webpack-plugin": "^4.0.0",
63
63
  "compression-webpack-plugin": "^10.0.0",
64
- "eslint": "^8.20.0",
64
+ "eslint": "^8.21.0",
65
65
  "eslint-webpack-plugin": "^3.2.0",
66
66
  "jest": "^28.1.3",
67
67
  "nodemon": "^2.0.19",