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 #!/usr/bin/env node
const { execSync } = require('child_process'); const { execSync } = require('child_process');
var fs = require('fs');
const isWin = process.platform === "win32"; const isWin = process.platform === "win32";
const runCommand = command => { const runCommand = command => {
@ -12,22 +14,79 @@ const runCommand = command => {
return true; 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 repoName = process.argv[2];
const gitCheckoutCommand = `git clone --depth 1 https://github.com/aleleba/create-node-ts-graphql-server ${repoName}`; 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 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 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 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 deleteFoldersCommand = `cd ${repoName} && rm -rf .github && rm -rf bin`
const deleteFoldersCommandWindows = `cd ${repoName} && rmdir .github /s /q && rmdir bin /s /q` 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}`); console.log(`Installing dependencies for ${repoName}`);
const installedDeps = runCommand(installDepsCommand); const installedDeps = runCommand(installDepsCommand);
if(!installedDeps) process.exit(-1); 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}`); console.log(`Cleaning History of Git for ${repoName}`);
const cleanGitHistory = isWin ? runCommand(cleanGitHistoryCommandWindows) : runCommand(cleanGitHistoryCommand); const cleanGitHistory = isWin ? runCommand(cleanGitHistoryCommandWindows) : runCommand(cleanGitHistoryCommand);
if(!cleanGitHistory) process.exit(-1); if(!cleanGitHistory) process.exit(-1);

18
package-lock.json generated
View File

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

View File

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