Skip to content

Commit

Permalink
feat: add rename script (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: CRIMX <straybugs@gmail.com>
  • Loading branch information
hyrious and crimx authored Oct 14, 2024
1 parent 70265d0 commit 1a9a806
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# @wopjs/template

[![Docs](https://img.shields.io/badge/Docs-read-%23fdf9f5)](https://wopjs.github.io/template)
[![Build Status](https://github.com/wopjs/template/actions/workflows/build.yml/badge.svg)](https://github.com/wopjs/template/actions/workflows/build.yml)
[![npm-version](https://img.shields.io/npm/v/@wopjs/template.svg)](https://www.npmjs.com/package/@wopjs/template)
[![Coverage Status](https://img.shields.io/coverallsCoverage/github/wopjs/template)](https://coveralls.io/github/wopjs/template)
[![minified-size](https://img.shields.io/bundlephobia/minzip/@wopjs/template)](https://bundlephobia.com/package/@wopjs/template)

Collection of common utilities.
Template for creating TypeScript packages.

## Install

```
npm add @wopjs/template
After you have cloned the repository generated by this template, run the following command to rename the package and install dependencies:

```console
npm i
```

## License
Expand Down
19 changes: 19 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @wopjs/template

[![Docs](https://img.shields.io/badge/Docs-read-%23fdf9f5)](https://wopjs.github.io/template)
[![Build Status](https://github.com/wopjs/template/actions/workflows/build.yml/badge.svg)](https://github.com/wopjs/template/actions/workflows/build.yml)
[![npm-version](https://img.shields.io/npm/v/@wopjs/template.svg)](https://www.npmjs.com/package/@wopjs/template)
[![Coverage Status](https://img.shields.io/coverallsCoverage/github/wopjs/template)](https://coveralls.io/github/wopjs/template)
[![minified-size](https://img.shields.io/bundlephobia/minzip/@wopjs/template)](https://bundlephobia.com/package/@wopjs/template)

Collection of common utilities.

## Install

```
npm add @wopjs/template
```

## License

MIT @ [wopjs](https://github.com/wopjs)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dist"
],
"scripts": {
"postinstall": "node scripts/rename.mjs",
"prepublishOnly": "npm run build",
"lint": "eslint && prettier --check .",
"docs": "typedoc --options typedoc.json",
Expand Down
33 changes: 33 additions & 0 deletions scripts/rename.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'node:fs'
import path from 'node:path'
import cp from 'node:child_process'

let user = 'wopjs'
let name = path.basename(process.cwd()).toLowerCase()

let docsURL = `https://${user.toLowerCase()}.github.io/${name}`
let userLink = `[${user}](https://github.com/${user.toLowerCase()})`

let pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
pkg.name = `@${user.toLowerCase()}/${name}`
pkg.description = name
pkg.keywords = name.split('-')
pkg.repository = `${user.toLowerCase()}/${name}`
if (user !== 'wopjs') {
pkg.maintainers = void 0
}
pkg.scripts.postinstall = void 0

let readme = fs.readFileSync('README.template.md', 'utf8')
readme = readme.replace(/wopjs\/template/g, `${user}/${name}`)
readme = readme.replace('https://wopjs.github.io/template', docsURL)
readme = readme.replace('Collection of common utilities.', `${name}.`)
readme = readme.replace('[wopjs](https://github.com/wopjs)', userLink)

fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n')
fs.writeFileSync('README.md', readme)
fs.rmSync('README.template.md')
fs.rmSync('scripts/rename.mjs')

const win = (bin) => process.platform === 'win32' ? `${bin}.cmd` : bin
cp.spawnSync(win('npm'), ['install'], { stdio: 'inherit' })

0 comments on commit 1a9a806

Please sign in to comment.