diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index d6e4bb60..00000000 --- a/scripts/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## scripts/create - -在 `packages/` 目录下生成一个新的 插件包 - -``` sh -pnpm pkg [--option] -``` - -- `package-name` 插件名称 - -### Option - -- `--client,-c` 是否生成 `client` 目录及其文件,默认不生成 -- `--shared,-s` 是否生成 `shared` 目录及其文件,默认不生成 - -- `--help,-h` 显示帮助信息 diff --git a/scripts/create/generator.js b/scripts/create/generator.js deleted file mode 100644 index 63ed78e0..00000000 --- a/scripts/create/generator.js +++ /dev/null @@ -1,97 +0,0 @@ -import path from 'node:path' -import fs from 'node:fs' -import { fileURLToPath } from 'node:url' -import handlebars from 'handlebars' -import chalk from 'chalk' -import ora from 'ora' -import { execa } from 'execa' -import { readTemplateList } from './readTpl.js' -import { lowerCase, packageName, upperCase } from './utils.js' -import { writeFile } from './writeFile.js' - -const compile = handlebars.compile - -const _dirname - = typeof __dirname !== 'undefined' - ? __dirname - : path.dirname(fileURLToPath(import.meta.url)) - -const packagesRoot = path.join(_dirname, '../../packages') -const spinner = ora() - -const pkg = JSON.parse( - fs.readFileSync(path.join(_dirname, '../../package.json'), 'utf-8'), -) - -async function generatorFile(config) { - const templateList = readTemplateList(path.join(_dirname, './template')) - - const { name, client, shared } = config - const pkgName = packageName(name) - const targetDir = path.join(packagesRoot, pkgName) - const data = { - pkgName, - upperName: upperCase(name), - lowerName: lowerCase(name), - client, - shared, - version: pkg.version, - } - const include = [ - !client && 'client', - !shared && 'shared', - !shared && 'client/index.js', - ] - .filter(Boolean) - .join('|') - const filterRE = new RegExp(`/(${include})/`) - const templates = templateList - .filter(({ file }) => { - return !filterRE.test(file) - }) - .map(({ file, content }) => { - return { - file, - template: compile(content), - } - }) - spinner.start(`${chalk.cyan(pkgName)} generating....`) - templates.forEach(async ({ file, template }) => { - try { - const filepath = path.join(targetDir, file) - await writeFile(filepath, template(data)) - } - catch (e) { - spinner.fail(`Failed to generate ${chalk.cyan(pkgName)}`) - throw e - } - }) - spinner.succeed(`${chalk.cyan(pkgName)} generated !`) -} - -async function initPackage(config) { - const { name, client } = config - const pkgName = packageName(name) - const targetDir = path.join(packagesRoot, pkgName) - const dependencies = [ - '@vuepress/core@next', - '@vuepress/utils@next', - '@vuepress/shared@next', - ] - client && dependencies.push('@vuepress/client@next') - - spinner.start(chalk.cyan('Installing...')) - try { - await execa('pnpm', ['add', ...dependencies], { cwd: targetDir }) - spinner.succeed('Installed.') - } - catch (e) { - spinner.fail('Failed to Installed') - throw e - } -} - -export async function generator(config) { - await generatorFile(config) - await initPackage(config) -} diff --git a/scripts/create/getConfig.js b/scripts/create/getConfig.js deleted file mode 100644 index f9e9f524..00000000 --- a/scripts/create/getConfig.js +++ /dev/null @@ -1,29 +0,0 @@ -import process from 'node:process' -import minimist from 'minimist' - -const defaultOptions = { - s: false, - shared: false, - c: false, - client: false, - h: false, - help: false, -} - -function normalizeArgv(argv) { - return { - name: argv._[0] || '', - client: argv.client || argv.c, - shared: argv.shared || argv.s, - help: argv.h || argv.help, - } -} - -export function getConfig() { - const argv = Object.assign( - {}, - defaultOptions, - minimist(process.argv.slice(2)), - ) - return normalizeArgv(argv) -} diff --git a/scripts/create/getHelp.js b/scripts/create/getHelp.js deleted file mode 100644 index d92015cf..00000000 --- a/scripts/create/getHelp.js +++ /dev/null @@ -1,18 +0,0 @@ -import chalk from 'chalk' - -export function getHelp() { - console.log(` this command will generator a package to ${chalk.cyan('packages')}. - command: ${chalk.green('pnpm pkg [--options]')} - - ${chalk.green('package-name')}: 包名 - - options: - ${chalk.green('--client, -c')}: 是否生成 ${chalk.cyan('client/')} 目录 - ${chalk.green('--shared, -s')}: 是否生成 ${chalk.cyan('shared/')} 目录 - - ${chalk.green('--help, -h')}: show help message. - - exp: ${chalk.green('pnpm pkg caniuse -c -s')} - It will generator to ${chalk.cyan('packages/plugin-caniuse')} - `) -} diff --git a/scripts/create/index.js b/scripts/create/index.js deleted file mode 100644 index 68963fc8..00000000 --- a/scripts/create/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import process from 'node:process' -import { getConfig } from './getConfig.js' -import { getHelp } from './getHelp.js' -import { generator } from './generator.js' - -const config = getConfig() - -if (config.help) { - getHelp() - process.exit(0) -} -else { - generator(config).catch((err) => { - console.error(err) - process.exit(1) - }) -} diff --git a/scripts/create/readTpl.js b/scripts/create/readTpl.js deleted file mode 100644 index 605eb9d8..00000000 --- a/scripts/create/readTpl.js +++ /dev/null @@ -1,33 +0,0 @@ -import fs from 'node:fs' -import path from 'node:path' - -const tplRE = /\.tpl$/ -function readFileList(dir, fileList = {}) { - const files = fs.readdirSync(dir) - files.forEach((file) => { - const filepath = path.join(dir, file) - const stat = fs.statSync(filepath) - if (stat.isDirectory()) { - readFileList(filepath, fileList) - } - else { - const extname = path.extname(filepath) - if (tplRE.test(extname)) - fileList[filepath.replace(tplRE, '')] = fs.readFileSync(filepath, 'utf-8') - } - }) - return fileList -} - -export function readTemplateList(dir) { - const templateMap = readFileList(dir) - const result = [] - Object.keys(templateMap).forEach((key) => { - const file = path.relative(dir, key) - result.push({ - file, - content: templateMap[key], - }) - }) - return result -} diff --git a/scripts/create/template/LICENSE.tpl b/scripts/create/template/LICENSE.tpl deleted file mode 100644 index 9f677c90..00000000 --- a/scripts/create/template/LICENSE.tpl +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (C) 2021 - PRESENT by pengzhanbo - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/scripts/create/template/README.md.tpl b/scripts/create/template/README.md.tpl deleted file mode 100644 index 4c2c83fe..00000000 --- a/scripts/create/template/README.md.tpl +++ /dev/null @@ -1,18 +0,0 @@ -# `@vuepress-plume/{{ pkgName }}` - -## Install -``` -yarn add @vuepress-plume/{{ pkgName }} -``` -## Usage -``` js -// .vuepress/config.js -const {{ lowerName }}Plugin = require('@vuepress-plume/{{ pkgName }}') -module.exports = { - //... - plugins: [ - {{ lowerName }}Plugin() - ] - // ... -} -``` diff --git a/scripts/create/template/package.json.tpl b/scripts/create/template/package.json.tpl deleted file mode 100644 index ea1e0361..00000000 --- a/scripts/create/template/package.json.tpl +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "@vuepress-plume/{{ pkgName }}", - "version": "{{ version }}", - "description": "The Plugin for VuePres 2", - "keyword": [ - "VuePress", - "vuepress plugin", - "{{ lowerName }}", - "vuepress-plugin-{{ pkgName }}" - ], - "homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme", - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git" - }, - "license": "MIT", - "author": "pengzhanbo ", - "type": "module", - "exports": { - ".": "./lib/node/index.js", - {{#if shared }} - "./client": "./lib/client/index.js", - {{/if}} - "./package.json": "./package.json" - }, - "main": "lib/node/index.js", - "types": "./lib/node/index.d.ts", - "scripts": { - "build": "pnpm run clean && pnpm run copy && pnpm run ts", - "clean": "rimraf lib *.tsbuildinfo", - "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib", - "copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib -w", - "dev": "concurrently \"pnpm copy:watch\" \"pnpm ts:watch\"", - "ts": "tsc -b tsconfig.build.json", - "ts:watch": "tsc -b tsconfig.build.json --watch" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/scripts/create/template/src/client/clientConfig.ts.tpl b/scripts/create/template/src/client/clientConfig.ts.tpl deleted file mode 100644 index e5214719..00000000 --- a/scripts/create/template/src/client/clientConfig.ts.tpl +++ /dev/null @@ -1,8 +0,0 @@ -import { defineClientConfig } from '@vuepress/client' - - -export default defineClientConfig({ - setup() { - // do something - }, -}) diff --git a/scripts/create/template/src/client/index.ts.tpl b/scripts/create/template/src/client/index.ts.tpl deleted file mode 100644 index 72593733..00000000 --- a/scripts/create/template/src/client/index.ts.tpl +++ /dev/null @@ -1 +0,0 @@ -export * from '../shared/index.js' diff --git a/scripts/create/template/src/node/index.ts.tpl b/scripts/create/template/src/node/index.ts.tpl deleted file mode 100644 index cecc69ed..00000000 --- a/scripts/create/template/src/node/index.ts.tpl +++ /dev/null @@ -1,8 +0,0 @@ -import { {{ lowerName }}Plugin } from './plugin.js' - -export * from './plugin.js' -{{#if shared }} -export * from '../shared/index.js' -{{/if}} - -export default {{ lowerName }}Plugin diff --git a/scripts/create/template/src/node/plugin.ts.tpl b/scripts/create/template/src/node/plugin.ts.tpl deleted file mode 100644 index 5561d9e2..00000000 --- a/scripts/create/template/src/node/plugin.ts.tpl +++ /dev/null @@ -1,23 +0,0 @@ -import type { App, Plugin } from '@vuepress/core' -{{#if client}} -import { path } from '@vuepress/utils' -{{/if}} -{{#if shared}} -import type { {{ upperName }}Options } from '../shared/index.js' -{{else}} - -export interface {{ upperName }}Options { - a?: string -} -{{/if}} - -export const {{ lowerName }}Plugin = (options: {{ upperName }}Options): Plugin => { - return (app: App) => { - return { - name: '@vuepress-plume/{{ pkgName }}', - {{#if client}} - clientConfigFile: path.resolve(__dirname, '../client/clientConfig.js'), - {{/if}} - } - } -} diff --git a/scripts/create/template/src/shared/index.ts.tpl b/scripts/create/template/src/shared/index.ts.tpl deleted file mode 100644 index e22084f5..00000000 --- a/scripts/create/template/src/shared/index.ts.tpl +++ /dev/null @@ -1,3 +0,0 @@ -export interface {{ upperName }}Options { - a?: string -} diff --git a/scripts/create/template/tsconfig.build.json.tpl b/scripts/create/template/tsconfig.build.json.tpl deleted file mode 100644 index 66824ada..00000000 --- a/scripts/create/template/tsconfig.build.json.tpl +++ /dev/null @@ -1,8 +0,0 @@ -{ -"extends": "../tsconfig.build.json", -"compilerOptions": { -"rootDir": "./src", -"outDir": "./lib" -}, -"include": ["./src"] -} diff --git a/scripts/create/utils.js b/scripts/create/utils.js deleted file mode 100644 index 279d4e19..00000000 --- a/scripts/create/utils.js +++ /dev/null @@ -1,14 +0,0 @@ -export function upperCase(str) { - return str.split(/-|\s+/).filter(Boolean).map((s) => { - return s[0].toUpperCase() + s.slice(1) - }).join('') -} - -export function lowerCase(str) { - str = upperCase(str) - return str[0].toLowerCase() + str.slice(1) -} - -export function packageName(name) { - return `plugin-${name.trim().split(/-|\s+/).filter(Boolean).join('-')}` -} diff --git a/scripts/create/writeFile.js b/scripts/create/writeFile.js deleted file mode 100644 index f3ace897..00000000 --- a/scripts/create/writeFile.js +++ /dev/null @@ -1,17 +0,0 @@ -import path from 'node:path' -import fs from 'node:fs' - -export async function writeFile(filepath, content) { - const dirname = path.dirname(filepath) - if (!fs.existsSync(dirname)) - fs.mkdirSync(dirname, { recursive: true }) - - return new Promise((resolve, reject) => { - fs.writeFile(filepath, content, 'utf-8', (err) => { - if (err) - reject(err) - else - resolve() - }) - }) -}