-
-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add create-vuepress-theme-hope helper
- Loading branch information
1 parent
9b8f079
commit 92333cf
Showing
79 changed files
with
3,387 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
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
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (C) 2020 - PRESENT by MrHope | ||
|
||
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. |
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,42 @@ | ||
{ | ||
"name": "create-vuepress-theme-hope", | ||
"version": "2.0.0-alpha.23", | ||
"description": "Create vuepress-theme-hope demo project helper", | ||
"keywords": [ | ||
"create", | ||
"vuepress", | ||
"vuepress-theme-hope" | ||
], | ||
"homepage": "https://vuepress-theme-hope.github.io/v2/", | ||
"bugs": { | ||
"url": "https://github.com/vuepress-theme-hope/vuepress-theme-hope/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuepress-theme-hope/vuepress-theme-hope.git", | ||
"directory": "packages/create" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Mr.Hope", | ||
"email": "mister-hope@outlook.com", | ||
"url": "https://mrhope.site" | ||
}, | ||
"bin": { | ||
"create-vuepress-theme-hope": "./lib/node/index.js" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"clean": "rimraf ./lib ./*.tsbuildinfo", | ||
"dev": "yarn dev:ts", | ||
"dev:ts": "tsc -b tsconfig.build.json --watch" | ||
}, | ||
"dependencies": { | ||
"@mr-hope/vuepress-shared": "2.0.0-alpha.23", | ||
"@types/inquirer": "^8.2.0", | ||
"@vuepress/utils": "2.0.0-beta.35", | ||
"cac": "^6.7.12", | ||
"execa": "^5.1.1", | ||
"inquirer": "^8.2.0" | ||
} | ||
} |
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,33 @@ | ||
# create-vuepress-theme-hope | ||
|
||
[![Version](https://img.shields.io/npm/v/create-vuepress-theme-hope/next.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/create-vuepress-theme-hope.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/create-vuepress-theme-hope?style=flat-square&logo=npm)](https://www.npmjs.com/package/create-vuepress-theme-hope) | ||
|
||
Create template shortcut for vuepress-theme-hope. | ||
|
||
## Usage | ||
|
||
```bash | ||
npm init vuepress-theme-hope <dir> | ||
``` | ||
|
||
Or | ||
|
||
```bash | ||
yarn create vuepress-theme-hope <dir> | ||
``` | ||
|
||
--- | ||
|
||
快速创建 vuepress-theme-hope 模板捷径。 | ||
|
||
## 使用 | ||
|
||
```bash | ||
npm init vuepress-theme-hope <dir> | ||
``` | ||
|
||
或 | ||
|
||
```bash | ||
yarn create vuepress-theme-hope <dir> | ||
``` |
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,5 @@ | ||
import { rollupTypescript } from "../../scripts/rollup"; | ||
|
||
export default rollupTypescript("node/index", { | ||
external: ["@mr-hope/vuepress-shared", "@vuepress/utils", "https"], | ||
}); |
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,31 @@ | ||
import { get } from "https"; | ||
|
||
export const checkForLatestVersion = (packageName: string): Promise<string> => | ||
new Promise((resolve, reject) => { | ||
get( | ||
`https://registry.npmjs.org/-/package/${packageName}/dist-tags`, | ||
(res) => { | ||
if (res.statusCode === 200) { | ||
let body = ""; | ||
|
||
res.on("data", (data) => (body += data)); | ||
res.on("end", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
resolve(JSON.parse(body).next as string); | ||
}); | ||
} else { | ||
reject( | ||
new Error( | ||
`Get ${packageName} version failed, please check your network!` | ||
) | ||
); | ||
} | ||
} | ||
).on("error", () => { | ||
reject( | ||
new Error( | ||
`Get ${packageName} version failed, please check your network!` | ||
) | ||
); | ||
}); | ||
}); |
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,30 @@ | ||
import { fs, path } from "@vuepress/utils"; | ||
|
||
const copyFile = (srcFile: string, targetFile: string): void => { | ||
const targetDir = path.dirname(targetFile); | ||
|
||
fs.ensureDirSync(targetDir); | ||
|
||
const rs = fs.createReadStream(srcFile); // create read stream | ||
const ws = fs.createWriteStream(targetFile); // create write stream | ||
|
||
rs.pipe(ws); | ||
}; | ||
|
||
const copyDir = (srcDir: string, targetDir: string): void => { | ||
fs.ensureDirSync(targetDir); | ||
|
||
const files = fs.readdirSync(srcDir, { withFileTypes: true }); | ||
|
||
files.forEach((file) => { | ||
if (file.isFile()) | ||
copyFile(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`); | ||
else if (file.isDirectory()) | ||
copyDir(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`); | ||
}); | ||
}; | ||
|
||
export const copy = (src: string, target: string): void => { | ||
if (fs.statSync(src).isDirectory()) copyDir(src, target); | ||
else if (fs.statSync(src).isFile()) copyFile(src, target); | ||
}; |
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,10 @@ | ||
import { sync } from "execa"; | ||
|
||
export const detectYarn = (): boolean => { | ||
try { | ||
sync("yarn --version", { stdio: "ignore" }); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |
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,86 @@ | ||
import { prompt } from "inquirer"; | ||
|
||
export type Lang = "zh-CN" | "en-US"; | ||
|
||
export interface CreateI18n { | ||
getVersion: string; | ||
createPackage: string; | ||
updatePackage: string; | ||
template: string; | ||
install: string; | ||
wait: string; | ||
success: string; | ||
devServerAsk: string; | ||
devServer: string; | ||
hint: string; | ||
nameMessage: string; | ||
nameError: string; | ||
versionMessage: string; | ||
versionError: string; | ||
descriptionMessage: string; | ||
licenseMessage: string; | ||
} | ||
|
||
export const i18n: Record<Lang, CreateI18n> = { | ||
"zh-CN": { | ||
getVersion: "获取依赖的最新版本...", | ||
createPackage: "生成 package.json...", | ||
updatePackage: "更新 package.json...", | ||
template: "生成模板...", | ||
wait: "这可能需要数分钟,请耐心等待.\n我们无法正确输出子进程的进度条,所以进程可能会看似未响应", | ||
install: "安装依赖...", | ||
success: "模板已成功生成!", | ||
devServerAsk: "是否想要现在启动 Demo 查看?", | ||
devServer: | ||
"启动开发服务器...\n启动成功后,请在浏览器输入给出的开发服务器地址(默认为 'localhost:8080')", | ||
hint: '提示: 请使用 "yarn run docs:dev" 命令启动开发服务器', | ||
nameMessage: "设置应用名称", | ||
nameError: "应用名称应只包含小写字母、数字和连接线 (-)", | ||
versionMessage: "设置应用版本号", | ||
versionError: "此版本无效,版本号应为 'x.x.x'", | ||
descriptionMessage: "设置应用描述", | ||
licenseMessage: "设置协议", | ||
}, | ||
"en-US": { | ||
getVersion: "Getting lastest version of deps...", | ||
createPackage: "Generating package.json...", | ||
updatePackage: "Updating package.json...", | ||
template: "Generating Template...", | ||
wait: "This may take a few minutes, please be patient.\nWe can not correctly output progress bar from child process, so the process may look stuck.", | ||
install: "Installing Deps...", | ||
success: "Successful Generated!", | ||
devServerAsk: "Would you like to preview template now?", | ||
devServer: | ||
"Staring dev server...\nAfter the dev server starts running, please visit the given server link ('localhost:8080' by default)", | ||
hint: 'Hint: You should execute "yarn run docs:dev" to start dev server.', | ||
nameMessage: "Your project name", | ||
nameError: | ||
"package name should only contain lowercase characters, numbers and dash", | ||
versionMessage: "Your project version", | ||
versionError: | ||
"This version is not a valid one. Version should be like 'x.x.x'", | ||
descriptionMessage: "Your project description", | ||
licenseMessage: "Your project lincense", | ||
}, | ||
}; | ||
|
||
interface LanguageResult { | ||
lang: Lang; | ||
message: CreateI18n; | ||
} | ||
|
||
export const getLanguage = async (): Promise<LanguageResult> => { | ||
const { language } = await prompt<{ language: Lang }>([ | ||
{ | ||
name: "language", | ||
type: "list", | ||
message: "Select a language to display", | ||
choices: ["en-US", "zh-CN"], | ||
}, | ||
]); | ||
|
||
return { | ||
lang: language, | ||
message: i18n[language], | ||
}; | ||
}; |
Oops, something went wrong.