@uni-plus/create 0.0.2 → 0.1.1
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/CHANGELOG.md +14 -0
- package/dist/index.js +66 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -1
- package/src/index.ts +82 -2
- package/tsconfig.json +4 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
@@ -7,10 +7,75 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
8
|
});
|
9
9
|
};
|
10
|
+
import { select, input, confirm } from '@inquirer/prompts';
|
11
|
+
import os from 'node:os';
|
12
|
+
import { NpmPackage } from '@uni-plus/utils';
|
13
|
+
import fse from 'fs-extra';
|
14
|
+
import path from 'node:path';
|
15
|
+
import ora from 'ora';
|
16
|
+
import ejs from 'ejs';
|
17
|
+
import { glob } from 'glob';
|
10
18
|
function create() {
|
11
19
|
return __awaiter(this, void 0, void 0, function* () {
|
12
|
-
|
20
|
+
const projectTemplate = yield select({
|
21
|
+
message: '请选择项目模版',
|
22
|
+
choices: [
|
23
|
+
{
|
24
|
+
name: 'uni-plus Base 模板',
|
25
|
+
value: '@uni-plus/template-uni-plus-base'
|
26
|
+
},
|
27
|
+
{
|
28
|
+
name: 'uni-plus Demo 模板',
|
29
|
+
value: '@uni-plus/template-uni-plus-demo'
|
30
|
+
}
|
31
|
+
],
|
32
|
+
});
|
33
|
+
let projectName = '';
|
34
|
+
while (!projectName) {
|
35
|
+
projectName = yield input({ message: '请输入项目名' });
|
36
|
+
}
|
37
|
+
const targetPath = path.join(process.cwd(), projectName);
|
38
|
+
if (fse.existsSync(targetPath)) {
|
39
|
+
const empty = yield confirm({ message: '该目录不为空,是否清空' });
|
40
|
+
if (empty) {
|
41
|
+
fse.emptyDirSync(targetPath);
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
process.exit(0);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
const pkg = new NpmPackage({
|
48
|
+
name: projectTemplate,
|
49
|
+
targetPath: path.join(os.homedir(), '.uni-plus-template')
|
50
|
+
});
|
51
|
+
if (!(yield pkg.exists())) {
|
52
|
+
const spinner = ora('下载模版中...').start();
|
53
|
+
yield pkg.install();
|
54
|
+
spinner.stop();
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
const spinner = ora('更新模版中...').start();
|
58
|
+
yield pkg.update();
|
59
|
+
spinner.stop();
|
60
|
+
}
|
61
|
+
const spinner = ora('创建项目中...').start();
|
62
|
+
const templatePath = path.join(pkg.npmFilePath, 'template');
|
63
|
+
fse.copySync(templatePath, targetPath);
|
64
|
+
spinner.stop();
|
65
|
+
const renderData = { projectName };
|
66
|
+
const files = yield glob('**', {
|
67
|
+
cwd: targetPath,
|
68
|
+
nodir: true,
|
69
|
+
ignore: 'node_modules/**'
|
70
|
+
});
|
71
|
+
for (let i = 0; i < files.length; i++) {
|
72
|
+
const filePath = path.join(targetPath, files[i]);
|
73
|
+
const renderResult = yield ejs.renderFile(filePath, renderData);
|
74
|
+
fse.writeFileSync(filePath, renderResult);
|
75
|
+
}
|
76
|
+
console.log(`uniapp 项目 ${projectName} 创建成功`);
|
13
77
|
});
|
14
78
|
}
|
79
|
+
create();
|
15
80
|
export default create;
|
16
81
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAe,MAAM;;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C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Aa,WAAW,OAAO,CAAC,CAAC;IAE/C,CAAC;CAAA;AAED,MAAM,EAAE,CAAA;AAER,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uni-plus/create",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"description": "",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.js",
|
@@ -11,6 +11,18 @@
|
|
11
11
|
"keywords": [],
|
12
12
|
"author": "",
|
13
13
|
"license": "ISC",
|
14
|
+
"dependencies": {
|
15
|
+
"@inquirer/prompts": "^7.2.3",
|
16
|
+
"ejs": "^3.1.10",
|
17
|
+
"fs-extra": "^11.3.0",
|
18
|
+
"glob": "^11.0.1",
|
19
|
+
"ora": "^8.1.1",
|
20
|
+
"@uni-plus/utils": "^0.1.1"
|
21
|
+
},
|
22
|
+
"devDependencies": {
|
23
|
+
"@types/ejs": "^3.1.5",
|
24
|
+
"@types/fs-extra": "^11.0.4"
|
25
|
+
},
|
14
26
|
"scripts": {
|
15
27
|
"test": "echo \"Error: no test specified\" && exit 1"
|
16
28
|
}
|
package/src/index.ts
CHANGED
@@ -1,6 +1,86 @@
|
|
1
|
+
import { select, input, confirm } from '@inquirer/prompts';
|
2
|
+
import os from 'node:os';
|
3
|
+
import { NpmPackage } from '@uni-plus/utils';
|
4
|
+
import fse from 'fs-extra';
|
5
|
+
import path from 'node:path';
|
6
|
+
import ora from 'ora';
|
7
|
+
import ejs from 'ejs';
|
8
|
+
import { glob } from 'glob';
|
9
|
+
|
1
10
|
async function create() {
|
2
|
-
|
11
|
+
|
12
|
+
const projectTemplate = await select({
|
13
|
+
message: '请选择项目模版',
|
14
|
+
choices: [
|
15
|
+
{
|
16
|
+
name: 'uni-plus Base 模板',
|
17
|
+
value: '@uni-plus/template-uni-plus-base'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
name: 'uni-plus Demo 模板',
|
21
|
+
value: '@uni-plus/template-uni-plus-demo'
|
22
|
+
}
|
23
|
+
],
|
24
|
+
});
|
25
|
+
|
26
|
+
let projectName = '';
|
27
|
+
while (!projectName) {
|
28
|
+
projectName = await input({ message: '请输入项目名' });
|
29
|
+
}
|
30
|
+
|
31
|
+
const targetPath = path.join(process.cwd(), projectName);
|
32
|
+
|
33
|
+
if (fse.existsSync(targetPath)) {
|
34
|
+
const empty = await confirm({ message: '该目录不为空,是否清空' });
|
35
|
+
if (empty) {
|
36
|
+
fse.emptyDirSync(targetPath);
|
37
|
+
} else {
|
38
|
+
process.exit(0);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
const pkg = new NpmPackage({
|
43
|
+
name: projectTemplate,
|
44
|
+
targetPath: path.join(os.homedir(), '.uni-plus-template')
|
45
|
+
});
|
46
|
+
|
47
|
+
if (!await pkg.exists()) {
|
48
|
+
const spinner = ora('下载模版中...').start();
|
49
|
+
await pkg.install();
|
50
|
+
spinner.stop();
|
51
|
+
} else {
|
52
|
+
const spinner = ora('更新模版中...').start();
|
53
|
+
await pkg.update();
|
54
|
+
spinner.stop();
|
55
|
+
}
|
56
|
+
|
57
|
+
const spinner = ora('创建项目中...').start();
|
58
|
+
|
59
|
+
const templatePath = path.join(pkg.npmFilePath, 'template');
|
60
|
+
|
61
|
+
fse.copySync(templatePath, targetPath);
|
62
|
+
|
63
|
+
spinner.stop();
|
64
|
+
|
65
|
+
const renderData: Record<string, any> = { projectName };
|
66
|
+
|
67
|
+
const files = await glob('**', {
|
68
|
+
cwd: targetPath,
|
69
|
+
nodir: true,
|
70
|
+
ignore: 'node_modules/**'
|
71
|
+
})
|
72
|
+
|
73
|
+
for (let i = 0; i < files.length; i++) {
|
74
|
+
const filePath = path.join(targetPath, files[i]);
|
75
|
+
const renderResult = await ejs.renderFile(filePath, renderData)
|
76
|
+
|
77
|
+
fse.writeFileSync(filePath, renderResult);
|
78
|
+
}
|
79
|
+
|
80
|
+
console.log(`uniapp 项目 ${projectName} 创建成功`);
|
81
|
+
|
3
82
|
}
|
4
83
|
|
5
|
-
|
84
|
+
create()
|
6
85
|
|
86
|
+
export default create;
|