@winjs-dev/create-win 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/bin/create-win.js +4 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +23 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +396 -0
- package/dist/template.d.ts +13 -0
- package/dist/template.js +123 -0
- package/package.json +36 -0
- package/templates/app/.cursor/rules/clean-code.mdc +55 -0
- package/templates/app/.cursor/rules/general.mdc +51 -0
- package/templates/app/.cursor/rules/git-conventional-commit-messages.mdc +127 -0
- package/templates/app/.cursor/rules/gitflow.mdc +111 -0
- package/templates/app/.cursor/rules/project-structure.mdc +69 -0
- package/templates/app/.cursor/rules/typescript.mdc +57 -0
- package/templates/app/.cursor/rules/vue.mdc +86 -0
- package/templates/app/.editorconfig.tpl +23 -0
- package/templates/app/.eslintignore +13 -0
- package/templates/app/.eslintrc.js +9 -0
- package/templates/app/.gitignore.tpl +55 -0
- package/templates/app/.husky/commit-msg +6 -0
- package/templates/app/.husky/pre-commit +5 -0
- package/templates/app/.lintstagedrc.tpl +5 -0
- package/templates/app/.npmrc.tpl +2 -0
- package/templates/app/.prettierignore +13 -0
- package/templates/app/.prettierrc.js +4 -0
- package/templates/app/.stylelintignore +6 -0
- package/templates/app/.stylelintrc.js +16 -0
- package/templates/app/.winrc.ts.tpl +95 -0
- package/templates/app/README.md +244 -0
- package/templates/app/commitlint.config.js +3 -0
- package/templates/app/f2elint.config.js +6 -0
- package/templates/app/package.json.tpl +34 -0
- package/templates/app/plugin.ts.tpl +23 -0
- package/templates/app/src/app.js +55 -0
- package/templates/app/src/assets/fonts/demo.css +412 -0
- package/templates/app/src/assets/fonts/demo_fontclass.html +42 -0
- package/templates/app/src/assets/fonts/demo_symbol.html +69 -0
- package/templates/app/src/assets/fonts/demo_unicode.html +77 -0
- package/templates/app/src/assets/fonts/iconfont.css +20 -0
- package/templates/app/src/assets/fonts/iconfont.eot +0 -0
- package/templates/app/src/assets/fonts/iconfont.js +96 -0
- package/templates/app/src/assets/fonts/iconfont.svg +36 -0
- package/templates/app/src/assets/fonts/iconfont.ttf +0 -0
- package/templates/app/src/assets/fonts/iconfont.woff +0 -0
- package/templates/app/src/assets/img/logo.png +0 -0
- package/templates/app/src/assets/js/.gitkeep +0 -0
- package/templates/app/src/assets/style/app.less +5 -0
- package/templates/app/src/assets/style/main.less +39 -0
- package/templates/app/src/assets/style/variable.less +53 -0
- package/templates/app/src/constant.js +5 -0
- package/templates/app/src/global.less +1 -0
- package/templates/app/src/icons/cat.svg +1 -0
- package/templates/app/src/icons/dog.svg +1 -0
- package/templates/app/src/layouts/index.vue +15 -0
- package/templates/app/src/pages/docs.vue +5 -0
- package/templates/app/src/pages/hello/index.vue +88 -0
- package/templates/app/src/pages/hello/style.less +41 -0
- package/templates/app/src/pages/index.vue +9 -0
- package/templates/app/src/services/RESTFULURL.js +3 -0
- package/templates/app/src/services/autoMatchBaseUrl.js +18 -0
- package/templates/app/src/services/index.js +11 -0
- package/templates/app/src/services/request.js +178 -0
- package/templates/app/tsconfig.json.tpl +3 -0
- package/templates/app/typings.d.ts +1 -0
- package/templates/pc/.cursor/rules/clean-code.mdc +55 -0
- package/templates/pc/.cursor/rules/general.mdc +51 -0
- package/templates/pc/.cursor/rules/git-conventional-commit-messages.mdc +127 -0
- package/templates/pc/.cursor/rules/gitflow.mdc +111 -0
- package/templates/pc/.cursor/rules/project-structure.mdc +69 -0
- package/templates/pc/.cursor/rules/typescript.mdc +57 -0
- package/templates/pc/.cursor/rules/vue.mdc +86 -0
- package/templates/pc/.editorconfig.tpl +23 -0
- package/templates/pc/.eslintignore +13 -0
- package/templates/pc/.eslintrc.js +9 -0
- package/templates/pc/.gitignore.tpl +54 -0
- package/templates/pc/.husky/commit-msg +6 -0
- package/templates/pc/.husky/pre-commit +5 -0
- package/templates/pc/.lintstagedrc.tpl +5 -0
- package/templates/pc/.npmrc.tpl +2 -0
- package/templates/pc/.prettierignore +13 -0
- package/templates/pc/.prettierrc.js +4 -0
- package/templates/pc/.stylelintignore +6 -0
- package/templates/pc/.stylelintrc.js +16 -0
- package/templates/pc/.winrc.ts.tpl +74 -0
- package/templates/pc/README.md +255 -0
- package/templates/pc/commitlint.config.js +3 -0
- package/templates/pc/f2elint.config.js +6 -0
- package/templates/pc/package.json.tpl +33 -0
- package/templates/pc/plugin.ts.tpl +23 -0
- package/templates/pc/src/app.js +55 -0
- package/templates/pc/src/assets/fonts/demo.css +412 -0
- package/templates/pc/src/assets/fonts/demo_fontclass.html +42 -0
- package/templates/pc/src/assets/fonts/demo_symbol.html +69 -0
- package/templates/pc/src/assets/fonts/demo_unicode.html +77 -0
- package/templates/pc/src/assets/fonts/iconfont.css +20 -0
- package/templates/pc/src/assets/fonts/iconfont.eot +0 -0
- package/templates/pc/src/assets/fonts/iconfont.js +96 -0
- package/templates/pc/src/assets/fonts/iconfont.svg +36 -0
- package/templates/pc/src/assets/fonts/iconfont.ttf +0 -0
- package/templates/pc/src/assets/fonts/iconfont.woff +0 -0
- package/templates/pc/src/assets/img/logo.png +0 -0
- package/templates/pc/src/assets/js/.gitkeep +0 -0
- package/templates/pc/src/assets/style/app.less +5 -0
- package/templates/pc/src/assets/style/main.less +39 -0
- package/templates/pc/src/assets/style/variable.less +53 -0
- package/templates/pc/src/constant.js +5 -0
- package/templates/pc/src/global.less +1 -0
- package/templates/pc/src/icons/cat.svg +1 -0
- package/templates/pc/src/icons/dog.svg +1 -0
- package/templates/pc/src/layouts/index.vue +16 -0
- package/templates/pc/src/pages/docs.vue +5 -0
- package/templates/pc/src/pages/hello/index.vue +88 -0
- package/templates/pc/src/pages/hello/style.less +41 -0
- package/templates/pc/src/pages/index.vue +9 -0
- package/templates/pc/src/services/RESTFULURL.js +3 -0
- package/templates/pc/src/services/autoMatchBaseUrl.js +18 -0
- package/templates/pc/src/services/index.js +11 -0
- package/templates/pc/src/services/request.js +178 -0
- package/templates/pc/tsconfig.json.tpl +3 -0
- package/templates/pc/typings.d.ts +1 -0
- package/templates/plugin/.fatherrc.ts +5 -0
- package/templates/plugin/.gitignore.tpl +2 -0
- package/templates/plugin/.npmrc.tpl +2 -0
- package/templates/plugin/README.md.tpl +29 -0
- package/templates/plugin/package.json.tpl +26 -0
- package/templates/plugin/src/index.ts.tpl +5 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/templates/sample/.cursor/rules/clean-code.mdc +55 -0
- package/templates/sample/.cursor/rules/general.mdc +51 -0
- package/templates/sample/.cursor/rules/git-conventional-commit-messages.mdc +127 -0
- package/templates/sample/.cursor/rules/gitflow.mdc +111 -0
- package/templates/sample/.cursor/rules/project-structure.mdc +69 -0
- package/templates/sample/.cursor/rules/typescript.mdc +57 -0
- package/templates/sample/.cursor/rules/vue.mdc +86 -0
- package/templates/sample/.editorconfig.tpl +23 -0
- package/templates/sample/.gitignore.tpl +19 -0
- package/templates/sample/.npmrc.tpl +2 -0
- package/templates/sample/.winrc.ts.tpl +7 -0
- package/templates/sample/package.json.tpl +21 -0
- package/templates/sample/plugin.ts.tpl +7 -0
- package/templates/sample/src/assets/img/logo.png +0 -0
- package/templates/sample/src/layouts/index.vue +8 -0
- package/templates/sample/src/pages/docs.vue +5 -0
- package/templates/sample/src/pages/hello/index.vue +77 -0
- package/templates/sample/src/pages/hello/style.less +41 -0
- package/templates/sample/src/pages/index.vue +9 -0
- package/templates/sample/tsconfig.json.tpl +3 -0
- package/templates/sample/typings.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 winjs-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# @winjs-dev/create-win
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/v/@winjs-dev/create-win.svg" alt="npm version" />
|
|
5
|
+
<img src="https://img.shields.io/npm/dm/@winjs-dev/create-win.svg" alt="npm downloads" />
|
|
6
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
> 🚀 WinJS 框架官方脚手架工具,快速创建现代化前端应用项目
|
|
10
|
+
|
|
11
|
+
## 📋 项目简介
|
|
12
|
+
|
|
13
|
+
`@winjs-dev/create-win` 是 WinJS 框架的官方脚手架工具,提供了丰富的项目模板和配置选项。通过交互式命令行界面,帮助开发者快速搭建基于 WinJS 框架的各类前端应用项目,包括 H5 应用、企业级 Web 应用、混合式移动应用等。
|
|
14
|
+
|
|
15
|
+
## ✨ 核心特性
|
|
16
|
+
|
|
17
|
+
- 🎯 **多种项目模板** - 提供 4 种预设模板,覆盖不同应用场景
|
|
18
|
+
- 🛠️ **交互式配置** - 基于 clack-prompts 的友好命令行交互体验
|
|
19
|
+
- 📦 **多包管理器支持** - 支持 npm、yarn、pnpm、bun 等包管理器
|
|
20
|
+
- 🔧 **开箱即用** - 集成完整的开发工具链和最佳实践配置
|
|
21
|
+
- 🌐 **现代化技术栈** - 基于 Vue 3、TypeScript、现代构建工具
|
|
22
|
+
- 📱 **移动端优化** - 内置移动端适配和调试工具
|
|
23
|
+
- 🎨 **代码规范** - 预配置 ESLint、Prettier、StyleLint 等代码质量工具
|
|
24
|
+
- ⚡ **快速开发** - 支持热更新、Mock 数据、代理等开发特性
|
|
25
|
+
|
|
26
|
+
## 🚀 快速开始
|
|
27
|
+
|
|
28
|
+
### 安装
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 使用 npm
|
|
32
|
+
npm create @winjs-dev/win@latest my-project
|
|
33
|
+
|
|
34
|
+
# 使用 yarn
|
|
35
|
+
yarn create @winjs-dev/win my-project
|
|
36
|
+
|
|
37
|
+
# 使用 pnpm
|
|
38
|
+
pnpm create @winjs-dev/win my-project
|
|
39
|
+
|
|
40
|
+
# 使用 bun
|
|
41
|
+
bun create @winjs-dev/win my-project
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 或者全局安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 全局安装
|
|
48
|
+
npm install -g @winjs-dev/create-win
|
|
49
|
+
|
|
50
|
+
# 创建项目
|
|
51
|
+
create-win my-project
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 使用方式
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# 交互式创建项目
|
|
58
|
+
create-win
|
|
59
|
+
|
|
60
|
+
# 指定项目名称
|
|
61
|
+
create-win my-project
|
|
62
|
+
|
|
63
|
+
# 查看版本
|
|
64
|
+
create-win --version
|
|
65
|
+
|
|
66
|
+
# 查看帮助
|
|
67
|
+
create-win --help
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 📚 项目模板
|
|
71
|
+
|
|
72
|
+
### 🌐 App 模板
|
|
73
|
+
**适用场景:** 移动端 H5 应用开发
|
|
74
|
+
|
|
75
|
+
**技术栈:**
|
|
76
|
+
- Vue 3.2+ + Vue Router 4.x
|
|
77
|
+
- TypeScript 5.0+
|
|
78
|
+
- WinJS 构建工具链
|
|
79
|
+
- Less + PostCSS
|
|
80
|
+
- 移动端适配解决方案
|
|
81
|
+
|
|
82
|
+
**特性:**
|
|
83
|
+
- 📱 移动端优化(REM 适配、VConsole 调试)
|
|
84
|
+
- 🔧 插件化架构(请求拦截、移动端调试等)
|
|
85
|
+
- 🎨 完整样式解决方案
|
|
86
|
+
|
|
87
|
+
### 💻 PC 模板
|
|
88
|
+
**适用场景:** PC 端 Web 应用
|
|
89
|
+
|
|
90
|
+
**技术栈:**
|
|
91
|
+
- Vue 3.2.x + Vue Router 4.x
|
|
92
|
+
- TypeScript 5.x
|
|
93
|
+
- WinJS 构建工具链
|
|
94
|
+
- Less + PostCSS
|
|
95
|
+
|
|
96
|
+
**特性:**
|
|
97
|
+
- 🎯 PC 端优化体验
|
|
98
|
+
- 📦 模块联邦支持
|
|
99
|
+
|
|
100
|
+
### 🎯 Sample 模板
|
|
101
|
+
**适用场景:** 学习示例和快速原型
|
|
102
|
+
|
|
103
|
+
**技术栈:**
|
|
104
|
+
- Vue 3.x 基础配置
|
|
105
|
+
- TypeScript
|
|
106
|
+
- 最小化依赖
|
|
107
|
+
|
|
108
|
+
**特性:**
|
|
109
|
+
- 📚 学习友好的代码结构
|
|
110
|
+
- 🚀 最小化配置
|
|
111
|
+
- 💡 最佳实践示例
|
|
112
|
+
|
|
113
|
+
### 🔌 Plugin 模板
|
|
114
|
+
**适用场景:** WinJS 插件开发
|
|
115
|
+
|
|
116
|
+
**技术栈:**
|
|
117
|
+
- TypeScript
|
|
118
|
+
- WinJS 插件 API
|
|
119
|
+
- 测试工具链
|
|
120
|
+
|
|
121
|
+
**特性:**
|
|
122
|
+
- 🔌 插件开发框架
|
|
123
|
+
- 🧪 完整测试配置
|
|
124
|
+
- 📖 插件文档模板
|
|
125
|
+
|
|
126
|
+
## 🛠️ 配置选项
|
|
127
|
+
|
|
128
|
+
创建项目时,脚手架会询问以下配置选项:
|
|
129
|
+
|
|
130
|
+
- **项目名称** - 项目目录名和包名
|
|
131
|
+
- **项目模板** - 选择适合的项目模板
|
|
132
|
+
- **包管理器** - npm、yarn、pnpm、bun
|
|
133
|
+
- **Git 初始化** - 是否初始化 Git 仓库
|
|
134
|
+
- **依赖安装** - 是否自动安装依赖
|
|
135
|
+
- **代码规范** - 是否启用 Husky Git hooks
|
|
136
|
+
- **作者信息** - 项目作者和邮箱
|
|
137
|
+
|
|
138
|
+
## 📁 生成的项目结构
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
my-project/
|
|
142
|
+
├── src/ # 源代码目录
|
|
143
|
+
│ ├── app.js # 应用入口文件
|
|
144
|
+
│ ├── global.less # 全局样式
|
|
145
|
+
│ ├── constant.js # 常量定义
|
|
146
|
+
│ ├── assets/ # 静态资源
|
|
147
|
+
│ ├── layouts/ # 布局组件
|
|
148
|
+
│ ├── pages/ # 页面组件
|
|
149
|
+
│ └── services/ # 服务层
|
|
150
|
+
├── .winrc.ts # WinJS 配置文件
|
|
151
|
+
├── package.json # 项目依赖配置
|
|
152
|
+
├── tsconfig.json # TypeScript 配置
|
|
153
|
+
├── .eslintrc.js # ESLint 配置
|
|
154
|
+
├── .prettierrc.js # Prettier 配置
|
|
155
|
+
├── .stylelintrc.js # StyleLint 配置
|
|
156
|
+
├── .gitignore # Git 忽略文件
|
|
157
|
+
└── README.md # 项目说明文档
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 🔧 开发工具链
|
|
161
|
+
|
|
162
|
+
所有模板都内置了完整的开发工具链:
|
|
163
|
+
|
|
164
|
+
### 代码质量
|
|
165
|
+
- **ESLint** - JavaScript/TypeScript 代码检查
|
|
166
|
+
- **Prettier** - 代码格式化工具
|
|
167
|
+
- **StyleLint** - CSS/Less 样式检查
|
|
168
|
+
- **F2ELint** - 前端代码规范工具
|
|
169
|
+
|
|
170
|
+
### Git 工作流
|
|
171
|
+
- **Husky** - Git hooks 管理
|
|
172
|
+
- **lint-staged** - 暂存文件检查
|
|
173
|
+
- **commitlint** - 提交信息规范检查
|
|
174
|
+
|
|
175
|
+
### 构建工具
|
|
176
|
+
- **WinJS** - 现代化开发元框架
|
|
177
|
+
- **Webpack/Vite/Rsbuild** - 多种构建工具支持
|
|
178
|
+
- **Babel** - JavaScript 编译器
|
|
179
|
+
- **PostCSS** - CSS 后处理器
|
|
180
|
+
|
|
181
|
+
## 📖 环境要求
|
|
182
|
+
|
|
183
|
+
- **Node.js** >= 18.0.0
|
|
184
|
+
- **npm** >= 8.0.0 或其他包管理器的对应版本
|
|
185
|
+
|
|
186
|
+
## 🔗 相关链接
|
|
187
|
+
|
|
188
|
+
- [WinJS 官方文档](https://winjs-dev.github.io/winjs-docs)
|
|
189
|
+
- [问题反馈](https://github.com/winjs-dev/winjs/issues)
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
<p align="center">
|
|
194
|
+
如果这个项目对你有帮助,请给我们一个 ⭐!
|
|
195
|
+
</p>
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/cli.ts
|
|
2
|
+
var import_utils = require("@winner-fed/utils");
|
|
3
|
+
var args = (0, import_utils.yParser)(process.argv.slice(2), {
|
|
4
|
+
alias: {
|
|
5
|
+
version: ["v"],
|
|
6
|
+
help: ["h"]
|
|
7
|
+
},
|
|
8
|
+
boolean: ["version"]
|
|
9
|
+
});
|
|
10
|
+
if (args.version && !args._[0]) {
|
|
11
|
+
args._[0] = "version";
|
|
12
|
+
const local = (0, import_utils.isLocalDev)() ? import_utils.chalk.cyan("@local") : "";
|
|
13
|
+
const { name, version } = require("../package.json");
|
|
14
|
+
console.log(`${name}@${version}${local}`);
|
|
15
|
+
} else {
|
|
16
|
+
require("./").default({
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
args
|
|
19
|
+
}).catch((err) => {
|
|
20
|
+
console.error(`Create failed, ${err.message}`);
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
23
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { yParser } from '@winner-fed/utils';
|
|
2
|
+
import { type WinTemplate } from './template';
|
|
3
|
+
interface ITemplateArgs {
|
|
4
|
+
template?: WinTemplate;
|
|
5
|
+
}
|
|
6
|
+
interface IArgs extends yParser.Arguments, ITemplateArgs {
|
|
7
|
+
default?: boolean;
|
|
8
|
+
git?: boolean;
|
|
9
|
+
install?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ITemplatePluginParams {
|
|
12
|
+
pluginName?: string;
|
|
13
|
+
}
|
|
14
|
+
interface ITemplateParams extends ITemplatePluginParams {
|
|
15
|
+
version: string;
|
|
16
|
+
projectName: string;
|
|
17
|
+
appContainerName: string;
|
|
18
|
+
npmClient: ENpmClient | string;
|
|
19
|
+
registry: string;
|
|
20
|
+
author: string;
|
|
21
|
+
email: string;
|
|
22
|
+
withHusky: boolean;
|
|
23
|
+
extraNpmrc: string;
|
|
24
|
+
}
|
|
25
|
+
declare enum ENpmClient {
|
|
26
|
+
npm = "npm",
|
|
27
|
+
yarn = "yarn",
|
|
28
|
+
pnpm = "pnpm"
|
|
29
|
+
}
|
|
30
|
+
declare enum ETemplate {
|
|
31
|
+
app = "app",
|
|
32
|
+
pc = "pc",
|
|
33
|
+
plugin = "plugin",
|
|
34
|
+
sample = "sample"
|
|
35
|
+
}
|
|
36
|
+
export interface IDefaultData extends ITemplateParams {
|
|
37
|
+
appTemplate?: ETemplate;
|
|
38
|
+
}
|
|
39
|
+
interface IGeneratorOpts {
|
|
40
|
+
cwd: string;
|
|
41
|
+
args: IArgs;
|
|
42
|
+
defaultData?: IDefaultData;
|
|
43
|
+
}
|
|
44
|
+
declare const _default: ({ cwd, args, defaultData, }: IGeneratorOpts) => Promise<void>;
|
|
45
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var clackPrompts = __toESM(require("@winner-fed/clack-prompts"));
|
|
36
|
+
var import_utils = require("@winner-fed/utils");
|
|
37
|
+
var import_fs = require("fs");
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
var import_template = require("./template");
|
|
40
|
+
var devCommands = {
|
|
41
|
+
pnpm: "pnpm dev",
|
|
42
|
+
yarn: "yarn dev",
|
|
43
|
+
npm: "npm run dev",
|
|
44
|
+
bun: "bun run dev"
|
|
45
|
+
};
|
|
46
|
+
function parseStr(str) {
|
|
47
|
+
return str.replace(/-(\w)/g, function(_$0, $1) {
|
|
48
|
+
return $1.toUpperCase();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function getUUID() {
|
|
52
|
+
return Number(Math.random().toString().substr(2)).toString(36);
|
|
53
|
+
}
|
|
54
|
+
function generateOnlyContainer(str) {
|
|
55
|
+
return `${parseStr(str)}${getUUID()}`;
|
|
56
|
+
}
|
|
57
|
+
var pkg = require("../package");
|
|
58
|
+
var DEFAULT_DATA = {
|
|
59
|
+
pluginName: "winjs-plugin-demo",
|
|
60
|
+
projectName: "winjs-template",
|
|
61
|
+
email: "i@domain.com",
|
|
62
|
+
author: "winjs",
|
|
63
|
+
appContainerName: "root",
|
|
64
|
+
version: pkg.version,
|
|
65
|
+
npmClient: "pnpm" /* pnpm */,
|
|
66
|
+
registry: import_template.ERegistry.npm,
|
|
67
|
+
withHusky: false,
|
|
68
|
+
extraNpmrc: "",
|
|
69
|
+
appTemplate: "app" /* app */
|
|
70
|
+
};
|
|
71
|
+
var src_default = async ({
|
|
72
|
+
cwd,
|
|
73
|
+
args,
|
|
74
|
+
defaultData = DEFAULT_DATA
|
|
75
|
+
}) => {
|
|
76
|
+
let [name] = args._;
|
|
77
|
+
let npmClient = "pnpm" /* pnpm */;
|
|
78
|
+
let registry = import_template.ERegistry.npm;
|
|
79
|
+
let appTemplate = (defaultData == null ? void 0 : defaultData.appTemplate) || "app" /* app */;
|
|
80
|
+
const { username, email } = await (0, import_utils.getGitInfo)();
|
|
81
|
+
const author = email && username ? `${username} <${email}>` : "";
|
|
82
|
+
let pluginName = `winjs-plugin-${name || "demo"}`;
|
|
83
|
+
let projectName = `winjs-template-${name || "demo"}`;
|
|
84
|
+
const appContainerName = generateOnlyContainer(projectName);
|
|
85
|
+
let target = name ? (0, import_path.join)(cwd, name) : cwd;
|
|
86
|
+
const { isCancel, text, select, intro, outro, box, taskLog } = clackPrompts;
|
|
87
|
+
const exitPrompt = () => {
|
|
88
|
+
outro(import_utils.chalk.red("Exit create-win"));
|
|
89
|
+
process.exit(1);
|
|
90
|
+
};
|
|
91
|
+
const setName = async () => {
|
|
92
|
+
name = await text({
|
|
93
|
+
message: "What's the target folder name?",
|
|
94
|
+
initialValue: name || "my-app",
|
|
95
|
+
validate: (value) => {
|
|
96
|
+
if (!value.length) {
|
|
97
|
+
return "Please input project name";
|
|
98
|
+
}
|
|
99
|
+
if (value != "." && import_utils.fsExtra.existsSync((0, import_path.join)(cwd, value))) {
|
|
100
|
+
return `Folder ${value} already exists`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const selectAppTemplate = async () => {
|
|
106
|
+
appTemplate = await select({
|
|
107
|
+
message: "Pick WinJS App Template",
|
|
108
|
+
options: [
|
|
109
|
+
{ label: "Simple App", value: "sample" /* sample */ },
|
|
110
|
+
{
|
|
111
|
+
label: "PC Web",
|
|
112
|
+
value: "pc" /* pc */,
|
|
113
|
+
hint: "for pc web"
|
|
114
|
+
},
|
|
115
|
+
{ label: "H5 App", value: "app" /* app */ },
|
|
116
|
+
{
|
|
117
|
+
label: "WinJS Plugin",
|
|
118
|
+
value: "plugin" /* plugin */,
|
|
119
|
+
hint: "for plugin development"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
initialValue: "sample" /* sample */
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const selectNpmClient = async () => {
|
|
126
|
+
npmClient = await select({
|
|
127
|
+
message: "Pick Npm Client",
|
|
128
|
+
options: [
|
|
129
|
+
{ label: "npm" /* npm */, value: "npm" /* npm */ },
|
|
130
|
+
{ label: "yarn" /* yarn */, value: "yarn" /* yarn */, hint: "recommended" },
|
|
131
|
+
{ label: "pnpm" /* pnpm */, value: "pnpm" /* pnpm */ }
|
|
132
|
+
],
|
|
133
|
+
initialValue: "yarn" /* yarn */
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const selectRegistry = async () => {
|
|
137
|
+
registry = await select({
|
|
138
|
+
message: "Pick Npm Registry",
|
|
139
|
+
options: [
|
|
140
|
+
{
|
|
141
|
+
label: "npm",
|
|
142
|
+
value: import_template.ERegistry.npm
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
label: "taobao",
|
|
146
|
+
value: import_template.ERegistry.taobao,
|
|
147
|
+
hint: "recommended for China"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
initialValue: import_template.ERegistry.taobao
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
const internalTemplatePrompts = async () => {
|
|
154
|
+
intro("Creating a new WinJS project...");
|
|
155
|
+
await setName();
|
|
156
|
+
if (isCancel(name)) {
|
|
157
|
+
exitPrompt();
|
|
158
|
+
}
|
|
159
|
+
target = (0, import_path.join)(cwd, name);
|
|
160
|
+
await selectAppTemplate();
|
|
161
|
+
if (isCancel(appTemplate)) {
|
|
162
|
+
exitPrompt();
|
|
163
|
+
}
|
|
164
|
+
await selectNpmClient();
|
|
165
|
+
if (isCancel(npmClient)) {
|
|
166
|
+
exitPrompt();
|
|
167
|
+
}
|
|
168
|
+
await selectRegistry();
|
|
169
|
+
if (isCancel(registry)) {
|
|
170
|
+
exitPrompt();
|
|
171
|
+
}
|
|
172
|
+
const isPlugin = appTemplate === "plugin" /* plugin */;
|
|
173
|
+
if (isPlugin) {
|
|
174
|
+
pluginName = await text({
|
|
175
|
+
message: `What's the plugin name?`,
|
|
176
|
+
placeholder: pluginName,
|
|
177
|
+
validate: (value) => {
|
|
178
|
+
if (!(value == null ? void 0 : value.length)) {
|
|
179
|
+
return "Please input plugin name";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
if (isCancel(pluginName)) {
|
|
184
|
+
exitPrompt();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const useDefaultData = !!args.default;
|
|
189
|
+
const useExternalTemplate = !!args.template;
|
|
190
|
+
switch (true) {
|
|
191
|
+
case useExternalTemplate:
|
|
192
|
+
await selectNpmClient();
|
|
193
|
+
if (isCancel(npmClient)) {
|
|
194
|
+
exitPrompt();
|
|
195
|
+
}
|
|
196
|
+
await selectRegistry();
|
|
197
|
+
if (isCancel(registry)) {
|
|
198
|
+
exitPrompt();
|
|
199
|
+
}
|
|
200
|
+
await (0, import_template.unpackTemplate)({
|
|
201
|
+
template: args.template,
|
|
202
|
+
dest: target,
|
|
203
|
+
registry
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
if (!useDefaultData) {
|
|
208
|
+
await internalTemplatePrompts();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const version = pkg.version;
|
|
212
|
+
const monorepoRoot = await detectMonorepoRoot({ target });
|
|
213
|
+
const inMonorepo = !!monorepoRoot;
|
|
214
|
+
const projectRoot = inMonorepo ? monorepoRoot : target;
|
|
215
|
+
const shouldInitGit = args.git !== false;
|
|
216
|
+
const withHusky = shouldInitGit && !inMonorepo;
|
|
217
|
+
let pnpmExtraNpmrc = "";
|
|
218
|
+
const isPnpm = npmClient === "pnpm" /* pnpm */;
|
|
219
|
+
let pnpmMajorVersion;
|
|
220
|
+
if (isPnpm) {
|
|
221
|
+
pnpmMajorVersion = await getPnpmMajorVersion();
|
|
222
|
+
if (pnpmMajorVersion === 7) {
|
|
223
|
+
pnpmExtraNpmrc = `strict-peer-dependencies=false`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const injectInternalTemplateFiles = async () => {
|
|
227
|
+
const generator = new import_utils.BaseGenerator({
|
|
228
|
+
path: (0, import_path.join)(__dirname, "..", "templates", appTemplate),
|
|
229
|
+
target,
|
|
230
|
+
slient: true,
|
|
231
|
+
data: useDefaultData ? defaultData : {
|
|
232
|
+
version: version.includes("-canary.") ? version : `^${version}`,
|
|
233
|
+
npmClient,
|
|
234
|
+
registry,
|
|
235
|
+
author,
|
|
236
|
+
email,
|
|
237
|
+
withHusky,
|
|
238
|
+
extraNpmrc: isPnpm ? pnpmExtraNpmrc : "",
|
|
239
|
+
pluginName,
|
|
240
|
+
projectName,
|
|
241
|
+
appContainerName
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
await generator.run();
|
|
245
|
+
};
|
|
246
|
+
if (!useExternalTemplate) {
|
|
247
|
+
await injectInternalTemplateFiles();
|
|
248
|
+
}
|
|
249
|
+
const context = {
|
|
250
|
+
inMonorepo,
|
|
251
|
+
target,
|
|
252
|
+
projectRoot
|
|
253
|
+
};
|
|
254
|
+
if (!withHusky) {
|
|
255
|
+
await removeHusky(context);
|
|
256
|
+
}
|
|
257
|
+
if (inMonorepo) {
|
|
258
|
+
await moveNpmrc(context);
|
|
259
|
+
}
|
|
260
|
+
if (shouldInitGit) {
|
|
261
|
+
await initGit(context);
|
|
262
|
+
} else {
|
|
263
|
+
import_utils.logger.info(`Skip Git init`);
|
|
264
|
+
}
|
|
265
|
+
const isPnpm8 = pnpmMajorVersion === 8;
|
|
266
|
+
if (!useDefaultData && args.install !== false) {
|
|
267
|
+
const installTask = taskLog(`Installing dependencies with ${npmClient}...`);
|
|
268
|
+
if (isPnpm8) {
|
|
269
|
+
await installWithPnpm8(target);
|
|
270
|
+
} else {
|
|
271
|
+
const isYarn = npmClient === "yarn" /* yarn */;
|
|
272
|
+
try {
|
|
273
|
+
await execute(npmClient, [isYarn ? "" : "install"], {
|
|
274
|
+
cwd: target,
|
|
275
|
+
onData: (data) => {
|
|
276
|
+
installTask.text = data;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
} catch (error) {
|
|
280
|
+
installTask.fail(`Failed to install dependencies with ${npmClient}`);
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
installTask.success(`Installed dependencies with ${npmClient}`);
|
|
285
|
+
} else {
|
|
286
|
+
import_utils.logger.info(`Skip install deps`);
|
|
287
|
+
if (isPnpm8) {
|
|
288
|
+
import_utils.logger.warn(
|
|
289
|
+
import_utils.chalk.yellow(
|
|
290
|
+
`You current using pnpm v8, it will install minimal version of dependencies`
|
|
291
|
+
)
|
|
292
|
+
);
|
|
293
|
+
import_utils.logger.warn(
|
|
294
|
+
import_utils.chalk.green(
|
|
295
|
+
`Recommended that you run ${import_utils.chalk.bold.cyan(
|
|
296
|
+
"pnpm up -L"
|
|
297
|
+
)} to install latest version of dependencies`
|
|
298
|
+
)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(target, ".husky/pre-commit"))) {
|
|
303
|
+
if (process.platform !== "win32") {
|
|
304
|
+
import_utils.execa.execaCommandSync(`chmod +x ${(0, import_path.join)(target, ".husky/pre-commit")}`);
|
|
305
|
+
import_utils.logger.info(`Chmod ${(0, import_path.join)(target, ".husky/pre-commit")} successful`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(target, ".husky/commit-msg"))) {
|
|
309
|
+
if (process.platform !== "win32") {
|
|
310
|
+
import_utils.execa.execaCommandSync(`chmod +x ${(0, import_path.join)(target, ".husky/commit-msg")}`);
|
|
311
|
+
import_utils.logger.info(`Chmod ${(0, import_path.join)(target, ".husky/commit-msg")} successful`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
box(
|
|
315
|
+
`
|
|
316
|
+
1: ${import_utils.chalk.bold(import_utils.chalk.cyan(`cd ${target}`))}
|
|
317
|
+
2: ${import_utils.chalk.bold(import_utils.chalk.cyan(devCommands[npmClient]))}
|
|
318
|
+
|
|
319
|
+
To close the dev server, hit ${import_utils.chalk.bold(import_utils.chalk.cyan("Ctrl+C"))}
|
|
320
|
+
`.trim(),
|
|
321
|
+
"Next Steps"
|
|
322
|
+
);
|
|
323
|
+
outro(import_utils.chalk.green(`Create success!`));
|
|
324
|
+
};
|
|
325
|
+
async function detectMonorepoRoot(opts) {
|
|
326
|
+
const { target } = opts;
|
|
327
|
+
const rootPkg = await import_utils.pkgUp.pkgUp({ cwd: (0, import_path.dirname)(target) });
|
|
328
|
+
if (!rootPkg) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
const rootDir = (0, import_path.dirname)(rootPkg);
|
|
332
|
+
if ((0, import_utils.tryPaths)([
|
|
333
|
+
(0, import_path.join)(rootDir, "lerna.json"),
|
|
334
|
+
(0, import_path.join)(rootDir, "pnpm-workspace.yaml")
|
|
335
|
+
])) {
|
|
336
|
+
return rootDir;
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
async function moveNpmrc(opts) {
|
|
341
|
+
const { target, projectRoot } = opts;
|
|
342
|
+
const sourceNpmrc = (0, import_path.join)(target, "./.npmrc");
|
|
343
|
+
const targetNpmrc = (0, import_path.join)(projectRoot, "./.npmrc");
|
|
344
|
+
if (!(0, import_fs.existsSync)(targetNpmrc)) {
|
|
345
|
+
await import_utils.fsExtra.copyFile(sourceNpmrc, targetNpmrc);
|
|
346
|
+
}
|
|
347
|
+
await import_utils.fsExtra.remove(sourceNpmrc);
|
|
348
|
+
}
|
|
349
|
+
async function initGit(opts) {
|
|
350
|
+
const { projectRoot } = opts;
|
|
351
|
+
const isGit = (0, import_fs.existsSync)((0, import_path.join)(projectRoot, ".git"));
|
|
352
|
+
if (isGit) return;
|
|
353
|
+
try {
|
|
354
|
+
await import_utils.execa.execa("git", ["init"], { cwd: projectRoot });
|
|
355
|
+
} catch {
|
|
356
|
+
import_utils.logger.error(`Initial the git repo failed`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async function removeHusky(opts) {
|
|
360
|
+
const dir = (0, import_path.join)(opts.target, "./.husky");
|
|
361
|
+
if ((0, import_fs.existsSync)(dir)) {
|
|
362
|
+
await import_utils.fsExtra.remove(dir);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async function installWithPnpm8(cwd) {
|
|
366
|
+
await import_utils.execa.execa("pnpm", ["up", "-L"], { cwd, stdio: "inherit" });
|
|
367
|
+
}
|
|
368
|
+
async function getPnpmMajorVersion() {
|
|
369
|
+
try {
|
|
370
|
+
const { stdout } = await import_utils.execa.execa("pnpm", ["--version"]);
|
|
371
|
+
return parseInt(stdout.trim().split(".")[0], 10);
|
|
372
|
+
} catch (e) {
|
|
373
|
+
throw new Error("Please install pnpm first", { cause: e });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async function execute(cmd, args, options) {
|
|
377
|
+
const child = import_utils.execa.execa(cmd, args, {
|
|
378
|
+
stdio: "pipe",
|
|
379
|
+
cwd: options.cwd
|
|
380
|
+
});
|
|
381
|
+
return new Promise((resolve, reject) => {
|
|
382
|
+
var _a, _b;
|
|
383
|
+
(_a = child.stdout) == null ? void 0 : _a.on("data", (data) => {
|
|
384
|
+
options.onData(data);
|
|
385
|
+
});
|
|
386
|
+
(_b = child.stderr) == null ? void 0 : _b.on("data", (data) => {
|
|
387
|
+
options.onData(data);
|
|
388
|
+
});
|
|
389
|
+
child.on("close", (code) => {
|
|
390
|
+
resolve(code);
|
|
391
|
+
});
|
|
392
|
+
child.on("error", (error) => {
|
|
393
|
+
reject(error);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum ERegistry {
|
|
2
|
+
npm = "https://registry.npmjs.com/",
|
|
3
|
+
taobao = "https://registry.npmmirror.com/",
|
|
4
|
+
winner = "http://artifactory.hundsun.com/artifactory/api/npm/winnerproject-npm-virtual/"
|
|
5
|
+
}
|
|
6
|
+
export type WinTemplate = `@winner-fed/${string}-template`;
|
|
7
|
+
interface IUnpackTemplateOpts {
|
|
8
|
+
template: WinTemplate;
|
|
9
|
+
dest: string;
|
|
10
|
+
registry: ERegistry | string;
|
|
11
|
+
}
|
|
12
|
+
export declare const unpackTemplate: (opts: IUnpackTemplateOpts) => Promise<string>;
|
|
13
|
+
export {};
|