Skip to content

Commit

Permalink
feat: automatically replace package name
Browse files Browse the repository at this point in the history
  • Loading branch information
peterroe committed Mar 23, 2024
1 parent d24c509 commit cf85fee
Show file tree
Hide file tree
Showing 47 changed files with 3,565 additions and 71 deletions.
39 changes: 17 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,9 @@ async function init() {

spinner.succeed()

const pkg = pkgRead(root)
pkg.name = targetDir
switch (framework) {
case 'cli-starter':
pkg.bin = {
[targetDir]: './bin/index.mjs',
}
break
case 'vue-component-starter':
break
case 'ts-starter':
break
}
pkgWrite(root, pkg)
const dirName = targetDir.split('/').pop() || ''

replacePkgName(root, dirName)

console.log('\nDone. Now run:\n')
console.log(` cd ${targetDir}`)
Expand Down Expand Up @@ -160,12 +149,18 @@ function emptyDir(dir: string) {
}
}

function pkgRead(path: string) {
const pkg = JSON.parse(
fs.readFileSync(resolve(path, 'package.json'), 'utf-8'),
)
return pkg
}
function pkgWrite(root: string, pkg: any) {
fs.writeFileSync(resolve(root, 'package.json'), JSON.stringify(pkg, null, 2))
function replacePkgName(root: string, target: string) {
// foreach root subfile
const files = fs.readdirSync(root)
for (const file of files) {
const filePath = resolve(root, file)

if (fs.statSync(filePath).isDirectory()) {
replacePkgName(filePath, target)
}
else {
const content = fs.readFileSync(filePath, 'utf8')
fs.writeFileSync(filePath, content.replaceAll('__pkg_name_placeholder__', target))
}
}
}
10 changes: 5 additions & 5 deletions templates/cli-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cli-starter",
"name": "__pkg_name_placeholder__",
"version": "1.0.0",
"packageManager": "pnpm@8.10.2",
"description": "A command line tool template",
Expand All @@ -15,12 +15,12 @@
"typescript",
"template"
],
"homepage": "https://github.com/peterroe/cli-starter#readme",
"homepage": "https://github.com/peterroe/__pkg_name_placeholder__#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/peterroe/cli-starter.git"
"url": "git+https://github.com/peterroe/__pkg_name_placeholder__.git"
},
"bugs": "https://github.com/peterroe/cli-starter/issues",
"bugs": "https://github.com/peterroe/__pkg_name_placeholder__/issues",
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand All @@ -33,7 +33,7 @@
"./*": "./*"
},
"bin": {
"cli-starter": "./bin/index.mjs"
"__pkg_name_placeholder__": "./bin/index.mjs"
},
"scripts": {
"build": "unbuild",
Expand Down
11 changes: 5 additions & 6 deletions templates/docs-starter/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig } from 'vitepress'
import type { DefaultTheme } from 'vitepress/types'
import pkg from '../package.json'

const title = 'Front End'
const description = 'The docs template for the front end'
Expand Down Expand Up @@ -35,10 +34,10 @@ export default defineConfig({
titleTemplate: title,
description,
outDir: './dist',
base: `/${pkg.name}/`,
base: '/__pkg_name_placeholder__/',
head: [
['link', { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' }],
['link', { rel: 'alternate icon', href: '/favicon.ico', type: 'image/png', sizes: '16x16' }],
['link', { rel: 'icon', href: '/__pkg_name_placeholder__/favicon.svg', type: 'image/svg+xml' }],
['link', { rel: 'alternate icon', href: '/__pkg_name_placeholder__/favicon.ico', type: 'image/png', sizes: '16x16' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { name: 'og:title', content: title }],
['meta', { name: 'og:description', content: description }],
Expand Down Expand Up @@ -70,11 +69,11 @@ export default defineConfig({
'/guide/': SidebarGuide,
},
editLink: {
pattern: 'https://github.com/peterroe/un/edit/main/templates/docs-starter/:paht',
pattern: 'https://github.com/peterroe/__pkg_name_placeholder__/edit/main/:paht',
text: 'Suggest changes to this page',
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/peterroe/un' },
{ icon: 'github', link: 'https://github.com/peterroe/__pkg_name_placeholder__' },
],
footer: {
message: 'Released under the MIT License.',
Expand Down
2 changes: 1 addition & 1 deletion templates/docs-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "docs-starter",
"name": "__pkg_name_placeholder__",
"type": "module",
"private": true,
"scripts": {
Expand Down
48 changes: 24 additions & 24 deletions templates/docs-starter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"skipDefaultLibCheck": true,
"preserveSymlinks": true,
"skipLibCheck": true,
"jsx": "preserve",
"types": [
"node",
"vitepress",
"vite/client",
"vitest/importMeta"
],
},
"exclude": [
"dist/**",
"node_modules/**",
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"skipDefaultLibCheck": true,
"preserveSymlinks": true,
"skipLibCheck": true,
"jsx": "preserve",
"types": [
"node",
"vitepress",
"vite/client",
"vitest/importMeta"
]
}
},
"exclude": [
"dist/**",
"node_modules/**"
]
}
11 changes: 6 additions & 5 deletions templates/ts-starter-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ts-starter-vite",
"name": "__pkg_name_placeholder__",
"version": "1.0.0",
"packageManager": "pnpm@8.10.2",
"description": "typescript-vite-template",
Expand All @@ -13,12 +13,12 @@
"keywords": [
"typescript"
],
"homepage": "https://github.com/peterroe/un#readme",
"homepage": "https://github.com/peterroe/__pkg_name_placeholder__#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/peterroe/un.git"
"url": "git+https://github.com/peterroe/__pkg_name_placeholder__.git"
},
"bugs": "https://github.com/peterroe/un/issues",
"bugs": "https://github.com/peterroe/__pkg_name_placeholder__/issues",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -54,5 +54,6 @@
"vite": "4.5.2",
"vite-plugin-dts": "2.3.0",
"vitest": "0.28.5"
}
},
"dependencies": {}
}
8 changes: 4 additions & 4 deletions templates/ts-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ts-starter",
"name": "__pkg_name_placeholder__",
"version": "1.0.0",
"packageManager": "pnpm@8.10.2",
"description": "typescript-template",
Expand All @@ -14,12 +14,12 @@
"typescript",
"template"
],
"homepage": "https://github.com/peterroe/un#readme",
"homepage": "https://github.com/peterroe/__pkg_name_placeholder__#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/peterroe/un.git"
"url": "git+https://github.com/peterroe/__pkg_name_placeholder__.git"
},
"bugs": "https://github.com/peterroe/un/issues",
"bugs": "https://github.com/peterroe/__pkg_name_placeholder__/issues",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions templates/vue-component-starter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "vue-component-starter",
"name": "__pkg_name_placeholder__",
"version": "1.0.0",
"packageManager": "pnpm@8.10.2",
"description": "component based on vue3.x",
Expand All @@ -11,12 +11,12 @@
"component",
"vite"
],
"homepage": "https://github.com/peterroe/un#readme",
"homepage": "https://github.com/peterroe/__pkg_name_placeholder__#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/peterroe/un.git"
"url": "git+https://github.com/peterroe/__pkg_name_placeholder__.git"
},
"bugs": "https://github.com/peterroe/un/issues",
"bugs": "https://github.com/peterroe/__pkg_name_placeholder__/issues",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
Expand Down
62 changes: 62 additions & 0 deletions un-project/.github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 🐞 Bug report
description: Report an issue
labels: [pending triage]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: bug-description
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks!
placeholder: Bug description
validations:
required: true
- type: input
id: reproduction
attributes:
label: Reproduction
description: A [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) is **required**, otherwise the issue might be closed without further notice. [**Why & How?**](https://antfu.me/posts/why-reproductions-are-required)
placeholder: Reproduction
validations:
required: true
- type: textarea
id: system-info
attributes:
label: System Info
description: Output of `npx envinfo --system --binaries --browsers`
render: Shell
placeholder: System, Binaries, Browsers
validations:
required: true
- type: dropdown
id: package-manager
attributes:
label: Used Package Manager
description: Select the used package manager
options:
- npm
- yarn
- pnpm
- bun
- n/a
validations:
required: true
- type: checkboxes
id: checkboxes
attributes:
label: Validations
description: Before submitting the issue, please make sure you do the following
options:
- label: Follow our [Code of Conduct](https://github.com/antfu/.github/blob/main/CODE_OF_CONDUCT.md)
required: true
- label: Read the [Contributing Guide](https://github.com/antfu/contribute).
required: true
- label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
required: true
- label: Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
required: true
- label: The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
required: true
10 changes: 10 additions & 0 deletions un-project/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contact_links:
- name: 🙌 Contribution Guide
url: https://github.com/antfu/contribute
about: Please read through before making contributions.
- name: 💬 Anthony's Discord Server
url: https://chat.antfu.me/
about: Want to discuss / chat with the community? Here you go!
- name: ⁉️ Why and How to make a reproduction?
url: https://antfu.me/posts/why-reproductions-are-required
about: Reproduction is very important for maintainer to help on your issues!
44 changes: 44 additions & 0 deletions un-project/.github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 🚀 New feature proposal
description: Propose a new feature
labels: [enhancement]
body:
- type: markdown
attributes:
value: |
Thanks for your interest in the project and taking the time to fill out this feature report!
- type: textarea
id: feature-description
attributes:
label: Clear and concise description of the problem
description: 'As a developer using VueUse I want [goal / wish] so that [benefit]. If you intend to submit a PR for this issue, tell us in the description. Thanks!'
validations:
required: true
- type: textarea
id: suggested-solution
attributes:
label: Suggested solution
description: 'In module [xy] we could provide following implementation...'
validations:
required: true
- type: textarea
id: alternative
attributes:
label: Alternative
description: Clear and concise description of any alternative solutions or features you've considered.
- type: textarea
id: additional-context
attributes:
label: Additional context
description: Any other context or screenshots about the feature request here.
- type: checkboxes
id: checkboxes
attributes:
label: Validations
description: Before submitting the issue, please make sure you do the following
options:
- label: Follow our [Code of Conduct](https://github.com/antfu/.github/blob/main/CODE_OF_CONDUCT.md)
required: true
- label: Read the [Contributing Guide](https://github.com/antfu/contribute).
required: true
- label: Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
required: true
15 changes: 15 additions & 0 deletions un-project/.github/ISSUE_TEMPLATE/typo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 👀 Typo / Grammar fix
description: You can just go ahead and send a PR! Thank you!
labels: []
body:
- type: markdown
attributes:
value: |
## PR Welcome!
If the typo / grammar issue is trivial and straightforward, you can help by **directly sending a quick pull request**!
If you spot multiple of them, we suggest combining them into a single PR. Thanks!
- type: textarea
id: context
attributes:
label: Additional context

0 comments on commit cf85fee

Please sign in to comment.