mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-01-09 21:46:56 -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
|
#!/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({
|
||||||
|
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);
|
if(!deleteBin) process.exit(-1);
|
||||||
|
|
||||||
const replaceNewVersion = replaceTextOnFile({
|
const replaceNewVersion = runCommand(replaceNewVersionCommand)
|
||||||
file: 'package.json',
|
|
||||||
textToBeReplaced: `"version": "${actualVersion}",`,
|
|
||||||
textReplace: `"version": "0.0.1",`
|
|
||||||
})
|
|
||||||
if(!replaceNewVersion) 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)
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user