Merge pull request #4 from aleleba/PR-377800

PR-377800: fix npx and updating packages.
This commit is contained in:
Alejandro Lembke Barrientos 2022-08-05 19:35:11 -06:00 committed by GitHub
commit 9cbed6b8ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 15 deletions

View File

@ -1,5 +1,7 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
var fs = require('fs');
const isWin = process.platform === "win32";
const runCommand = command => {
@ -12,22 +14,79 @@ const runCommand = command => {
return true;
}
const replaceTextOnFile = ({
file,
textToBeReplaced,
textReplace,
arrOfObjectsBeReplaced
}) => {
let data
try{
data = fs.readFileSync(file, 'utf8');
} catch (e) {
console.error(`Failed to read file ${file}`, e);
return false;
}
let result
if(arrOfObjectsBeReplaced){
arrOfObjectsBeReplaced.forEach( obj => {
if(result){
result = result.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' ');
}else{
result = data.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' ');
}
})
}else{
result = data.replace(textToBeReplaced, textReplace).replace(/^\s*[\r\n]/gm, ' ');
}
try{
console.log('text changed')
fs.writeFileSync(file, result, 'utf8');
} catch (e) {
console.error(`Failed to read file ${file}`, e);
return false;
}
}
const repoName = process.argv[2];
const gitCheckoutCommand = `git clone --depth 1 https://github.com/aleleba/create-node-ts-graphql-server ${repoName}`;
console.log(`Cloning the repository with name ${repoName}`);
const checkedOut = runCommand(gitCheckoutCommand);
if(!checkedOut) process.exit(-1);
const actualVersion = runCommandWithOutput(`cd ${repoName} && node -p "require('./package.json').version"`).toString().trim()
const installDepsCommand = `cd ${repoName} && npm install --legacy-peer-deps`;
const cleanGitHistoryCommand = `cd ${repoName} && rm -rf .git && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
const cleanGitHistoryCommandWindows = `cd ${repoName} && rmdir .git /s /q && git init && git add --all -- ":!.github" ":!bin" && git commit -m "Initial commit"`
const deleteFoldersCommand = `cd ${repoName} && rm -rf .github && rm -rf bin`
const deleteFoldersCommandWindows = `cd ${repoName} && rmdir .github /s /q && rmdir bin /s /q`
console.log(`Cloning the repository with name ${repoName}`);
const checkedOut = runCommand(gitCheckoutCommand);
if(!checkedOut) process.exit(-1);
console.log(`Installing dependencies for ${repoName}`);
const installedDeps = runCommand(installDepsCommand);
if(!installedDeps) process.exit(-1);
console.log(`Replacing Json data for ${repoName}`);
replaceTextOnFile({
file: `./${repoName}/package.json`,
arrOfObjectsBeReplaced: [
{
textToBeReplaced: `"bin": "./bin/cli.js",`,
textReplace: ``
},
{
textToBeReplaced: `"version": "${actualVersion}",`,
textReplace: `"version": "0.0.1",`
},
{
textToBeReplaced: `"name": "@aleleba/create-node-ts-graphql-server",`,
textReplace: `"name": "${repoName}",`
}
]
})
console.log(`Cleaning History of Git for ${repoName}`);
const cleanGitHistory = isWin ? runCommand(cleanGitHistoryCommandWindows) : runCommand(cleanGitHistoryCommand);
if(!cleanGitHistory) process.exit(-1);

18
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.0.17",
"version": "1.1.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.0.17",
"version": "1.1.2",
"license": "MIT",
"dependencies": {
"@graphql-tools/schema": "^8.5.1",
@ -33,7 +33,7 @@
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@types/jest": "^28.1.6",
"@types/node": "^18.6.3",
"@types/node": "^18.6.4",
"@types/webpack": "^5.28.0",
"@types/webpack-node-externals": "^2.5.3",
"@typescript-eslint/eslint-plugin": "^5.32.0",
@ -3095,9 +3095,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "18.6.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz",
"integrity": "sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==",
"version": "18.6.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.4.tgz",
"integrity": "sha512-I4BD3L+6AWiUobfxZ49DlU43gtI+FTHSv9pE2Zekg6KjMpre4ByusaljW3vYSLJrvQ1ck1hUaeVu8HVlY3vzHg==",
"dev": true
},
"node_modules/@types/prettier": {
@ -13297,9 +13297,9 @@
"dev": true
},
"@types/node": {
"version": "18.6.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz",
"integrity": "sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==",
"version": "18.6.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.4.tgz",
"integrity": "sha512-I4BD3L+6AWiUobfxZ49DlU43gtI+FTHSv9pE2Zekg6KjMpre4ByusaljW3vYSLJrvQ1ck1hUaeVu8HVlY3vzHg==",
"dev": true
},
"@types/prettier": {

View File

@ -1,6 +1,6 @@
{
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.1.1",
"version": "1.1.2",
"description": "Node with Typescript and GraphQL Server",
"bin": "./bin/cli.js",
"main": "index.js",
@ -53,7 +53,7 @@
"@babel/preset-typescript": "^7.18.6",
"@babel/register": "^7.18.9",
"@types/jest": "^28.1.6",
"@types/node": "^18.6.3",
"@types/node": "^18.6.4",
"@types/webpack": "^5.28.0",
"@types/webpack-node-externals": "^2.5.3",
"@typescript-eslint/eslint-plugin": "^5.32.0",