-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added script to create new package (#68)
- Loading branch information
1 parent
a1a3bb5
commit fdfd78c
Showing
9 changed files
with
325 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
README.md | ||
README.md | ||
scripts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const figlet = require("figlet") | ||
const { input} = require("@inquirer/prompts") | ||
const chalk = require("chalk") | ||
const Spinner = require('cli-spinner').Spinner; | ||
const fs = require("node:fs") | ||
const path = require("node:path") | ||
const _ = require("lodash") | ||
|
||
const run = async () => { | ||
console.log(figlet.textSync("React Awesome Components")) | ||
const packageName = await input({ message: 'Enter package name (write in camel case): ' }); | ||
const description = await input({ message: 'Enter package description: ' }); | ||
const keywordStr = await input({ message: 'Enter package keywords (separate by whitespace): ' }); | ||
|
||
const keywords = keywordStr.split(" ").map(str => JSON.stringify(str)).join(",\n") | ||
|
||
const spinner = new Spinner(chalk.yellow(`Creating new package ${packageName}... %s `)); | ||
spinner.setSpinnerString('⣾⣽⣻⢿⡿⣟⣯⣷'); | ||
spinner.start(); | ||
|
||
const kebabName = _.kebabCase(packageName) | ||
|
||
const packageFolder = path.resolve(__dirname, "../packages/" + kebabName) | ||
|
||
// Create new folder with kebab case | ||
fs.mkdirSync(packageFolder) | ||
|
||
// Copy contents to new folder | ||
fs.cpSync(path.resolve(__dirname, "./template"), packageFolder, { recursive: true }) | ||
|
||
// Replace package name | ||
|
||
const replaceFiles = [ | ||
path.resolve(packageFolder, "./README.md"), | ||
path.resolve(packageFolder, "./package.json") | ||
] | ||
|
||
for(const filePath of replaceFiles) { | ||
const content = fs.readFileSync(filePath).toString('utf8') | ||
const kebabRegex = new RegExp("<package-kebab>", 'g') | ||
const camelRegex = new RegExp("<package-camel>", 'g') | ||
const descriptionRegex = new RegExp("<description>", "g") | ||
const keywordRegex = new RegExp("\"<keywords>\"", "g") | ||
let updatedContent = content.replace(kebabRegex, kebabName) | ||
updatedContent = updatedContent.replace(camelRegex, packageName) | ||
updatedContent = updatedContent.replace(descriptionRegex, description) | ||
updatedContent = updatedContent.replace(keywordRegex, keywords) | ||
fs.writeFileSync(filePath, updatedContent, 'utf8') | ||
} | ||
|
||
spinner.stop(); | ||
|
||
console.log(chalk.green(`\nYour new package is located at ${packageFolder}. Happy Hacking!!`)) | ||
|
||
console.log(chalk.yellow("Remember to do the following steps:")) | ||
console.log(chalk.blue("- Ignore newly created package in vite.config.ts file.")) | ||
console.log(chalk.blue("- Add Codecov step for newly created package in test.yml workflow.")) | ||
console.log(chalk.blue("- Add new package to the @react-awesome/components's package.json dependencies.")) | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["@react-awesome/eslint-config/library.js"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# @react-awesome/<package-kebab> | ||
|
||
<p align="center"> | ||
<img alt="version" src="https://img.shields.io/npm/v/%40react-awesome%2F<package-kebab>" /> | ||
<img alt="coverage" src="https://img.shields.io/codecov/c/github/trinhthinh388/react-awesome-components/master?token=VQ8VJ7OECQ&flag=<package-camel>" /> | ||
<img alt="license" src="https://img.shields.io/github/license/trinhthinh388/react-awesome-components" /> | ||
<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/trinhthinh388/react-awesome-components/release.yml" /> | ||
<img alt="size" src="https://img.shields.io/bundlejs/size/%40react-awesome/<package-kebab>" /> | ||
</p> | ||
|
||
**<package-camel>** tracks the previous value of a variable. | ||
|
||
Please refer to the [documentation](https://react-awesome-components.vercel.app/docs/<package-kebab>) for more information. | ||
|
||
## Installation | ||
|
||
```sh | ||
yarn add @react-awesome/<package-kebab> | ||
# or | ||
npm i @react-awesome/<package-kebab> | ||
``` | ||
|
||
## Contribution | ||
|
||
Yes please! See the | ||
[contributing guidelines](https://github.com/trinhthinh388/react-awesome-components/blob/master/CONTRIBUTING.md) | ||
for details. | ||
|
||
## Licence | ||
|
||
This project is licensed under the terms of the | ||
[MIT license](https://github.com/trinhthinh388/react-awesome-components/blob/master/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@react-awesome/<package-kebab>", | ||
"version": "0.0.3", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"sideEffects": false, | ||
"license": "MIT", | ||
"description": "<description>", | ||
"keywords": [ | ||
"react", | ||
"<keywords>" | ||
], | ||
"repository": { | ||
"url": "https://github.com/trinhthinh388/react-awesome-components" | ||
}, | ||
"files": [ | ||
"dist/**" | ||
], | ||
"scripts": { | ||
"build": "vite --config ../../vite.config.ts build", | ||
"dev": "vite --watch --config ../../vite.config.ts build", | ||
"lint": "eslint \"src/**/*.ts*\"", | ||
"clean": "rimraf .turbo && rimraf node_modules && rimraf dist", | ||
"test": "vitest --config ../../vite.config.ts --coverage --run", | ||
"test:ui": "vitest --config ../../vite.config.ts --coverage --ui", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@react-awesome/eslint-config": "*", | ||
"@react-awesome/tsconfig": "*", | ||
"@types/react": "^18.2.46", | ||
"@types/react-dom": "^18.2.18", | ||
"eslint": "^8.56.0", | ||
"react": "^18.2.0", | ||
"typescript": "^5.3.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "@react-awesome/tsconfig/react-library.json", | ||
"compilerOptions": { | ||
"types": ["vitest/globals"], | ||
}, | ||
"include": ["."], | ||
"exclude": ["dist", "build", "node_modules"], | ||
} |
Oops, something went wrong.