mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-01-09 05:26:58 -06:00
PR-815632: fixing npx.
This commit is contained in:
parent
02722bc0be
commit
41668c541f
57
bin/cli.js
57
bin/cli.js
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
const { execSync } = require('child_process');
|
||||
var fs = require('fs')
|
||||
var fs = require('fs');
|
||||
|
||||
const isWin = process.platform === "win32";
|
||||
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) {
|
||||
let result
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return false
|
||||
return console.error(err);
|
||||
}
|
||||
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) {
|
||||
if (err){
|
||||
console.log(err);
|
||||
return false
|
||||
return console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -70,17 +84,28 @@ console.log(`Installing dependencies for ${repoName}`);
|
||||
const installedDeps = runCommand(installDepsCommand);
|
||||
if(!installedDeps) process.exit(-1);
|
||||
|
||||
const deleteBin = isAppple ? runCommand(deleteBinCommandApple) : (isWin ? runCommand(deleteBinCommandWindows) : runCommand(deleteBinCommand));
|
||||
replaceTextOnFile({
|
||||
file: '../package.json',
|
||||
arrOfObjectsBeReplaced: [
|
||||
{
|
||||
textToBeReplaced: `"bin": "./bin/cli.js",`,
|
||||
textReplace: ``
|
||||
},
|
||||
{
|
||||
textToBeReplaced: `"version": "${actualVersion}",`,
|
||||
textReplace: `"version": "0.0.1",`
|
||||
},
|
||||
{
|
||||
textToBeReplaced: `"name": "@aleleba/create-react-ssr",`,
|
||||
textReplace: `"name": "${repoName}",`
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/* const deleteBin = isAppple ? runCommand(deleteBinCommandApple) : (isWin ? runCommand(deleteBinCommandWindows) : runCommand(deleteBinCommand));
|
||||
if(!deleteBin) process.exit(-1);
|
||||
|
||||
const replaceNewVersion = replaceTextOnFile({
|
||||
file: 'package.json',
|
||||
textToBeReplaced: `"version": "${actualVersion}",`,
|
||||
textReplace: `"version": "0.0.1",`
|
||||
})
|
||||
if(!replaceNewVersion) process.exit(-1);
|
||||
|
||||
/* const replaceNewVersion = runCommand(replaceNewVersionCommand)
|
||||
const replaceNewVersion = runCommand(replaceNewVersionCommand)
|
||||
if(!replaceNewVersion) process.exit(-1);
|
||||
|
||||
const replaceNameApp = runCommand(replaceNameAppCommand)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@aleleba/create-react-ssr",
|
||||
"version": "3.0.39",
|
||||
"version": "3.0.40",
|
||||
"description": "Starter Kit of server side render of react",
|
||||
"bin": "./bin/cli.js",
|
||||
"main": "src/server/index",
|
||||
|
Loading…
Reference in New Issue
Block a user