PR-815632: fixing npx.

This commit is contained in:
Alejandro Lembke Barrientos 2022-08-05 22:03:00 +00:00
parent 02722bc0be
commit 41668c541f
2 changed files with 42 additions and 17 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
const { execSync } = require('child_process'); const { execSync } = require('child_process');
var fs = require('fs') var fs = require('fs');
const isWin = process.platform === "win32"; const isWin = process.platform === "win32";
const isAppple = process.platform === "darwin"; const isAppple = process.platform === "darwin";
@ -24,18 +24,32 @@ const runCommandWithOutput = command => {
} }
} }
const replaceTextOnFile = ({ file, textToBeReplaced, textReplace }) => { const replaceTextOnFile = ({
file,
textToBeReplaced,
textReplace,
arrOfObjectsBeReplaced
}) => {
fs.readFile(file, 'utf8', function (err,data) { fs.readFile(file, 'utf8', function (err,data) {
let result
if (err) { if (err) {
console.log(err); return console.error(err);
return false }
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, ' ');
} }
var result = data.replace(textToBeReplaced, textReplace);
fs.writeFile(file, result, 'utf8', function (err) { fs.writeFile(file, result, 'utf8', function (err) {
if (err){ if (err){
console.log(err); return console.error(err);
return false
} }
}); });
}); });
@ -70,17 +84,28 @@ console.log(`Installing dependencies for ${repoName}`);
const installedDeps = runCommand(installDepsCommand); const installedDeps = runCommand(installDepsCommand);
if(!installedDeps) process.exit(-1); if(!installedDeps) process.exit(-1);
const deleteBin = isAppple ? runCommand(deleteBinCommandApple) : (isWin ? runCommand(deleteBinCommandWindows) : runCommand(deleteBinCommand)); replaceTextOnFile({
if(!deleteBin) process.exit(-1); file: '../package.json',
arrOfObjectsBeReplaced: [
const replaceNewVersion = replaceTextOnFile({ {
file: 'package.json', textToBeReplaced: `"bin": "./bin/cli.js",`,
textReplace: ``
},
{
textToBeReplaced: `"version": "${actualVersion}",`, textToBeReplaced: `"version": "${actualVersion}",`,
textReplace: `"version": "0.0.1",` textReplace: `"version": "0.0.1",`
},
{
textToBeReplaced: `"name": "@aleleba/create-react-ssr",`,
textReplace: `"name": "${repoName}",`
}
]
}) })
if(!replaceNewVersion) process.exit(-1);
/* const replaceNewVersion = runCommand(replaceNewVersionCommand) /* const deleteBin = isAppple ? runCommand(deleteBinCommandApple) : (isWin ? runCommand(deleteBinCommandWindows) : runCommand(deleteBinCommand));
if(!deleteBin) process.exit(-1);
const replaceNewVersion = runCommand(replaceNewVersionCommand)
if(!replaceNewVersion) process.exit(-1); if(!replaceNewVersion) process.exit(-1);
const replaceNameApp = runCommand(replaceNameAppCommand) const replaceNameApp = runCommand(replaceNameAppCommand)

View File

@ -1,6 +1,6 @@
{ {
"name": "@aleleba/create-react-ssr", "name": "@aleleba/create-react-ssr",
"version": "3.0.39", "version": "3.0.40",
"description": "Starter Kit of server side render of react", "description": "Starter Kit of server side render of react",
"bin": "./bin/cli.js", "bin": "./bin/cli.js",
"main": "src/server/index", "main": "src/server/index",