mirror of
https://github.com/aleleba/create-react-component-library.git
synced 2025-01-09 13:16:57 -06:00
Merge pull request #4 from aleleba/PR-115540
PR-115540: npx fix and updating packages.
This commit is contained in:
commit
13a2cec219
@ -48,11 +48,6 @@ It will create a dist folder and run:
|
|||||||
```
|
```
|
||||||
npm publish
|
npm publish
|
||||||
```
|
```
|
||||||
This will publish on npm your package. (Remember to delete on package.json)
|
|
||||||
```
|
|
||||||
"bin": "./bin/cli.js",
|
|
||||||
```
|
|
||||||
and delete bin folder or modify node bash to use npx.
|
|
||||||
|
|
||||||
## Cheers
|
## Cheers
|
||||||
Hope you enjoy this proyect! Sincerely Alejandro Lembke Barrientos.
|
Hope you enjoy this proyect! Sincerely Alejandro Lembke Barrientos.
|
76
bin/cli.js
76
bin/cli.js
@ -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,88 @@ const runCommand = command => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const runCommandWithOutput = command => {
|
||||||
|
try{
|
||||||
|
return execSync(`${command}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to execute ${command}`, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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-react-component-library ${repoName}`;
|
const gitCheckoutCommand = `git clone --depth 1 https://github.com/aleleba/create-react-component-library ${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`;
|
const installDepsCommand = `cd ${repoName} && npm install`;
|
||||||
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-react-ssr",`,
|
||||||
|
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);
|
||||||
|
1855
package-lock.json
generated
1855
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@aleleba/create-react-component-library",
|
"name": "@aleleba/create-react-component-library",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "A starter kit for create a React component Library with storybook",
|
"description": "A starter kit for create a React component Library with storybook",
|
||||||
"bin": "./bin/cli.js",
|
"bin": "./bin/cli.js",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -38,22 +38,22 @@
|
|||||||
"@babel/preset-typescript": "^7.18.6",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
"@babel/register": "^7.18.9",
|
"@babel/register": "^7.18.9",
|
||||||
"@mdx-js/react": "^2.1.2",
|
"@mdx-js/react": "^2.1.2",
|
||||||
"@storybook/addon-actions": "^6.5.9",
|
"@storybook/addon-actions": "^6.5.10",
|
||||||
"@storybook/addon-essentials": "^6.5.9",
|
"@storybook/addon-essentials": "^6.5.10",
|
||||||
"@storybook/addon-interactions": "^6.5.9",
|
"@storybook/addon-interactions": "^6.5.10",
|
||||||
"@storybook/addon-links": "^6.5.9",
|
"@storybook/addon-links": "^6.5.10",
|
||||||
"@storybook/addon-postcss": "^2.0.0",
|
"@storybook/addon-postcss": "^2.0.0",
|
||||||
"@storybook/builder-webpack5": "^6.5.9",
|
"@storybook/builder-webpack5": "^6.5.10",
|
||||||
"@storybook/manager-webpack5": "^6.5.9",
|
"@storybook/manager-webpack5": "^6.5.10",
|
||||||
"@storybook/mdx2-csf": "^0.0.3",
|
"@storybook/mdx2-csf": "^0.0.3",
|
||||||
"@storybook/preset-scss": "^1.0.3",
|
"@storybook/preset-scss": "^1.0.3",
|
||||||
"@storybook/react": "^6.5.9",
|
"@storybook/react": "^6.5.10",
|
||||||
"@storybook/testing-library": "^0.0.13",
|
"@storybook/testing-library": "^0.0.13",
|
||||||
"@testing-library/jest-dom": "^5.16.4",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
"@testing-library/react": "^13.3.0",
|
"@testing-library/react": "^13.3.0",
|
||||||
"@testing-library/user-event": "^14.4.0",
|
"@testing-library/user-event": "^14.4.2",
|
||||||
"@types/jest": "^28.1.6",
|
"@types/jest": "^28.1.6",
|
||||||
"@types/node": "^18.6.3",
|
"@types/node": "^18.6.4",
|
||||||
"@types/react": "^18.0.15",
|
"@types/react": "^18.0.15",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/webpack": "^5.28.0",
|
"@types/webpack": "^5.28.0",
|
||||||
@ -64,7 +64,7 @@
|
|||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"eslint": "^8.21.0",
|
"eslint": "^8.21.0",
|
||||||
"eslint-plugin-react": "^7.30.1",
|
"eslint-plugin-react": "^7.30.1",
|
||||||
"eslint-plugin-storybook": "^0.6.1",
|
"eslint-plugin-storybook": "^0.6.3",
|
||||||
"eslint-webpack-plugin": "^3.2.0",
|
"eslint-webpack-plugin": "^3.2.0",
|
||||||
"identity-obj-proxy": "^3.0.0",
|
"identity-obj-proxy": "^3.0.0",
|
||||||
"jest": "^28.1.3",
|
"jest": "^28.1.3",
|
||||||
@ -73,7 +73,7 @@
|
|||||||
"mini-css-extract-plugin": "^2.6.1",
|
"mini-css-extract-plugin": "^2.6.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"sass": "^1.54.0",
|
"sass": "^1.54.3",
|
||||||
"sass-loader": "^13.0.2",
|
"sass-loader": "^13.0.2",
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
"terser-webpack-plugin": "^5.3.3",
|
"terser-webpack-plugin": "^5.3.3",
|
||||||
|
Loading…
Reference in New Issue
Block a user