cmyr-template-cli 1.24.2 → 1.25.0
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/dist/plopfile.js +59 -42
- package/package.json +1 -1
- package/templates/CONTRIBUTING.md +1 -1
- package/templates/README.md +5 -6
- package/templates/scripts/minify-docker.js +17 -6
package/dist/plopfile.js
CHANGED
|
@@ -424,7 +424,7 @@ async function downloadGitRepo(repository, destination, options = {}) {
|
|
|
424
424
|
resolve(true);
|
|
425
425
|
});
|
|
426
426
|
}),
|
|
427
|
-
new Promise((
|
|
427
|
+
new Promise((_resolve, reject) => setTimeout(reject, 60 * 1000)),
|
|
428
428
|
]);
|
|
429
429
|
}
|
|
430
430
|
async function getFastGitRepo(repository) {
|
|
@@ -485,12 +485,12 @@ async function init(projectPath, answers) {
|
|
|
485
485
|
await asyncExec(`${PACKAGE_MANAGER} -v`, {
|
|
486
486
|
cwd: projectPath,
|
|
487
487
|
});
|
|
488
|
-
const newPkg = await initProjectJson(projectPath, answers);
|
|
489
488
|
await initConfig(projectPath);
|
|
490
489
|
await initCommitizen(projectPath);
|
|
491
490
|
if (isOpenSource) {
|
|
492
491
|
const info = await getProjectInfo(projectPath, answers);
|
|
493
492
|
if (info) {
|
|
493
|
+
await initProjectJson(projectPath, info);
|
|
494
494
|
if (isInitReadme) {
|
|
495
495
|
await initReadme(projectPath, info);
|
|
496
496
|
}
|
|
@@ -520,7 +520,8 @@ async function init(projectPath, answers) {
|
|
|
520
520
|
await asyncExec('git add .', {
|
|
521
521
|
cwd: projectPath,
|
|
522
522
|
});
|
|
523
|
-
|
|
523
|
+
const pkg = await getProjectJson(projectPath);
|
|
524
|
+
if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.lint) {
|
|
524
525
|
await asyncExec(`${PACKAGE_MANAGER} run lint`, {
|
|
525
526
|
cwd: projectPath,
|
|
526
527
|
});
|
|
@@ -811,36 +812,24 @@ async function initTsconfig(projectPath) {
|
|
|
811
812
|
console.error(error);
|
|
812
813
|
}
|
|
813
814
|
}
|
|
814
|
-
async function initProjectJson(projectPath,
|
|
815
|
+
async function initProjectJson(projectPath, projectInfos) {
|
|
815
816
|
const loading = ora__default["default"]('正在初始化 package.json ……').start();
|
|
816
817
|
try {
|
|
817
|
-
const {
|
|
818
|
-
const repositoryUrl = `https://github.com/${author}/${name}`;
|
|
819
|
-
const homepage = `${repositoryUrl}#readme`;
|
|
820
|
-
const issuesUrl = `${repositoryUrl}/issues`;
|
|
821
|
-
const gitUrl = `git+${repositoryUrl}.git`;
|
|
822
|
-
const nodeVersion = await getLtsNodeVersion() || '18';
|
|
823
|
-
const node = Number(nodeVersion) - 4;
|
|
818
|
+
const { packageName, engines, license, homepage, issuesUrl, gitUrl, author, description, keywords = [], isOpenSource, isPublishToNpm = false } = projectInfos;
|
|
824
819
|
const pkg = await getProjectJson(projectPath);
|
|
825
820
|
const pkgData = {
|
|
826
|
-
name,
|
|
821
|
+
name: packageName,
|
|
827
822
|
author,
|
|
828
823
|
description,
|
|
829
824
|
keywords,
|
|
830
825
|
private: !isPublishToNpm,
|
|
831
826
|
license: 'UNLICENSED',
|
|
832
|
-
engines
|
|
833
|
-
...(pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {},
|
|
834
|
-
node: `>=${node}`,
|
|
835
|
-
},
|
|
836
|
-
devDependencies: {
|
|
837
|
-
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
838
|
-
},
|
|
827
|
+
engines,
|
|
839
828
|
};
|
|
840
829
|
let extData = {};
|
|
841
830
|
if (isOpenSource) {
|
|
842
831
|
extData = {
|
|
843
|
-
license
|
|
832
|
+
license,
|
|
844
833
|
homepage,
|
|
845
834
|
repository: {
|
|
846
835
|
type: 'git',
|
|
@@ -849,9 +838,6 @@ async function initProjectJson(projectPath, answers) {
|
|
|
849
838
|
bugs: {
|
|
850
839
|
url: issuesUrl,
|
|
851
840
|
},
|
|
852
|
-
changelog: {
|
|
853
|
-
language: 'zh',
|
|
854
|
-
},
|
|
855
841
|
};
|
|
856
842
|
}
|
|
857
843
|
if (isPublishToNpm) {
|
|
@@ -859,7 +845,7 @@ async function initProjectJson(projectPath, answers) {
|
|
|
859
845
|
access: 'public',
|
|
860
846
|
};
|
|
861
847
|
}
|
|
862
|
-
const newPkg =
|
|
848
|
+
const newPkg = lodash.merge({}, pkg, pkgData, extData);
|
|
863
849
|
await saveProjectJson(projectPath, newPkg);
|
|
864
850
|
loading.succeed('package.json 初始化成功!');
|
|
865
851
|
return newPkg;
|
|
@@ -874,36 +860,42 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
874
860
|
var _a, _b, _c, _d, _e, _f;
|
|
875
861
|
const loading = ora__default["default"]('正在获取项目信息 ……').start();
|
|
876
862
|
try {
|
|
877
|
-
const { name, author, description, isOpenSource, isPublishToNpm, license } = answers;
|
|
863
|
+
const { name, author, description, template, isOpenSource, isPublishToNpm, license, isPrivateScopePackage, scopeName } = answers;
|
|
864
|
+
const templateMeta = getTemplateMeta(template);
|
|
865
|
+
const projectName = name;
|
|
878
866
|
const packageManager = 'npm';
|
|
879
867
|
const config = await loadTemplateCliConfig();
|
|
880
868
|
const pkg = await getProjectJson(projectPath);
|
|
881
|
-
const
|
|
882
|
-
const
|
|
869
|
+
const nodeVersion = await getLtsNodeVersion() || '20';
|
|
870
|
+
const node = Number(nodeVersion) - 4;
|
|
871
|
+
const packageName = isPrivateScopePackage ? `@${scopeName}/${name}` : name;
|
|
872
|
+
const engines = lodash.merge({}, pkg === null || pkg === void 0 ? void 0 : pkg.engines, { node: `>=${node}` });
|
|
883
873
|
const version = (pkg === null || pkg === void 0 ? void 0 : pkg.version) || '0.1.0';
|
|
884
|
-
const installCommand = isPublishToNpm ? `${packageManager} install ${
|
|
874
|
+
const installCommand = isPublishToNpm ? `${packageManager} install ${packageName}` : `${packageManager} install`;
|
|
885
875
|
const startCommand = ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.start) && `${packageManager} run start`;
|
|
886
876
|
const devCommand = ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _b === void 0 ? void 0 : _b.dev) && `${packageManager} run dev`;
|
|
887
877
|
const buildCommand = ((_c = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _c === void 0 ? void 0 : _c.build) && `${packageManager} run build`;
|
|
888
878
|
const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
|
|
889
879
|
const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
|
|
890
880
|
const commitCommand = ((_f = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _f === void 0 ? void 0 : _f.commit) && `${packageManager} run commit`;
|
|
891
|
-
const
|
|
881
|
+
const githubUsername = (config === null || config === void 0 ? void 0 : config.GITHUB_USERNAME) || author;
|
|
882
|
+
const giteeUsername = config === null || config === void 0 ? void 0 : config.GITEE_USERNAME;
|
|
883
|
+
const weiboUsername = config === null || config === void 0 ? void 0 : config.WEIBO_USERNAME;
|
|
884
|
+
const twitterUsername = config === null || config === void 0 ? void 0 : config.TWITTER_USERNAME;
|
|
885
|
+
const afdianUsername = config === null || config === void 0 ? void 0 : config.AFDIAN_USERNAME;
|
|
886
|
+
const patreonUsername = config === null || config === void 0 ? void 0 : config.PATREON_USERNAME;
|
|
887
|
+
const npmUsername = config === null || config === void 0 ? void 0 : config.NPM_USERNAME;
|
|
888
|
+
const repositoryUrl = `https://github.com/${githubUsername}/${projectName}`;
|
|
889
|
+
const gitUrl = `git+${repositoryUrl}.git`;
|
|
892
890
|
const issuesUrl = `${repositoryUrl}/issues`;
|
|
893
891
|
const contributingUrl = `${repositoryUrl}/blob/master/CONTRIBUTING.md`;
|
|
894
892
|
const documentationUrl = `${repositoryUrl}#readme`;
|
|
895
893
|
const demoUrl = `${repositoryUrl}#readme`;
|
|
896
894
|
const homepage = documentationUrl;
|
|
897
|
-
const githubUsername = (config === null || config === void 0 ? void 0 : config.GITHUB_USERNAME) || author;
|
|
898
|
-
const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
|
|
899
895
|
const licenseUrl = `${repositoryUrl}/blob/master/LICENSE`;
|
|
900
896
|
const discussionsUrl = `${repositoryUrl}/discussions`;
|
|
901
897
|
const pullRequestsUrl = `${repositoryUrl}/pulls`;
|
|
902
|
-
const
|
|
903
|
-
const weiboUsername = config === null || config === void 0 ? void 0 : config.WEIBO_USERNAME;
|
|
904
|
-
const twitterUsername = config === null || config === void 0 ? void 0 : config.TWITTER_USERNAME;
|
|
905
|
-
const afdianUsername = config === null || config === void 0 ? void 0 : config.AFDIAN_USERNAME;
|
|
906
|
-
const patreonUsername = config === null || config === void 0 ? void 0 : config.PATREON_USERNAME;
|
|
898
|
+
const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
|
|
907
899
|
const projectInfos = {
|
|
908
900
|
...answers,
|
|
909
901
|
currentYear: new Date().getFullYear(),
|
|
@@ -914,6 +906,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
914
906
|
authorWebsite,
|
|
915
907
|
homepage,
|
|
916
908
|
demoUrl,
|
|
909
|
+
gitUrl,
|
|
917
910
|
repositoryUrl,
|
|
918
911
|
issuesUrl,
|
|
919
912
|
contributingUrl,
|
|
@@ -925,7 +918,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
925
918
|
licenseName: cleanText(license),
|
|
926
919
|
licenseUrl,
|
|
927
920
|
documentationUrl,
|
|
928
|
-
isGithubRepos:
|
|
921
|
+
isGithubRepos: isOpenSource,
|
|
929
922
|
installCommand,
|
|
930
923
|
startCommand,
|
|
931
924
|
usage: startCommand,
|
|
@@ -934,12 +927,12 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
934
927
|
testCommand,
|
|
935
928
|
lintCommand,
|
|
936
929
|
commitCommand,
|
|
937
|
-
isJSProject:
|
|
930
|
+
isJSProject: ['nodejs', 'browser'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime),
|
|
938
931
|
packageManager,
|
|
939
932
|
isProjectOnNpm: isPublishToNpm,
|
|
940
933
|
isOpenSource,
|
|
941
934
|
packageName,
|
|
942
|
-
projectName
|
|
935
|
+
projectName,
|
|
943
936
|
projectVersion: version,
|
|
944
937
|
projectDocumentationUrl: documentationUrl,
|
|
945
938
|
projectDescription: description,
|
|
@@ -956,6 +949,8 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
956
949
|
patreonUsername,
|
|
957
950
|
weiboUsername,
|
|
958
951
|
twitterUsername,
|
|
952
|
+
npmUsername,
|
|
953
|
+
templateMeta,
|
|
959
954
|
};
|
|
960
955
|
loading.succeed('项目信息 初始化成功!');
|
|
961
956
|
return projectInfos;
|
|
@@ -1092,6 +1087,9 @@ async function initSemanticRelease(projectPath) {
|
|
|
1092
1087
|
'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
|
|
1093
1088
|
'semantic-release': devDependencies['semantic-release'],
|
|
1094
1089
|
},
|
|
1090
|
+
changelog: {
|
|
1091
|
+
language: 'zh',
|
|
1092
|
+
},
|
|
1095
1093
|
};
|
|
1096
1094
|
await saveProjectJson(projectPath, pkgData);
|
|
1097
1095
|
loading.succeed('semantic-release 初始化成功!');
|
|
@@ -1288,7 +1286,7 @@ async function initCommitizen(projectPath) {
|
|
|
1288
1286
|
config: {
|
|
1289
1287
|
...pkg === null || pkg === void 0 ? void 0 : pkg.config,
|
|
1290
1288
|
commitizen: {
|
|
1291
|
-
path: '
|
|
1289
|
+
path: 'cz-conventional-changelog-cmyr',
|
|
1292
1290
|
},
|
|
1293
1291
|
},
|
|
1294
1292
|
};
|
|
@@ -1528,9 +1526,9 @@ module.exports = function (plop) {
|
|
|
1528
1526
|
{
|
|
1529
1527
|
type: 'input',
|
|
1530
1528
|
name: 'keywords',
|
|
1531
|
-
message: '请输入项目关键词(
|
|
1529
|
+
message: '请输入项目关键词(用,分割)',
|
|
1532
1530
|
default: '',
|
|
1533
|
-
filter: (e) => e.trim().split('
|
|
1531
|
+
filter: (e) => e.trim().split(',').filter(Boolean),
|
|
1534
1532
|
},
|
|
1535
1533
|
{
|
|
1536
1534
|
type: 'list',
|
|
@@ -1634,6 +1632,25 @@ module.exports = function (plop) {
|
|
|
1634
1632
|
return answers.isOpenSource && templateMeta.npm;
|
|
1635
1633
|
},
|
|
1636
1634
|
},
|
|
1635
|
+
{
|
|
1636
|
+
type: 'confirm',
|
|
1637
|
+
name: 'isPrivateScopePackage',
|
|
1638
|
+
message: '是否为私域包?',
|
|
1639
|
+
default: false,
|
|
1640
|
+
when(answers) {
|
|
1641
|
+
return answers.isPublishToNpm;
|
|
1642
|
+
},
|
|
1643
|
+
},
|
|
1644
|
+
{
|
|
1645
|
+
type: 'input',
|
|
1646
|
+
name: 'scopeName',
|
|
1647
|
+
message: '请输入私域名称',
|
|
1648
|
+
default: config.NPM_USERNAME,
|
|
1649
|
+
when(answers) {
|
|
1650
|
+
return answers.isPrivateScopePackage;
|
|
1651
|
+
},
|
|
1652
|
+
filter: (e) => e.trim(),
|
|
1653
|
+
},
|
|
1637
1654
|
{
|
|
1638
1655
|
type: 'confirm',
|
|
1639
1656
|
name: 'isInitSemanticRelease',
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<h1 align="center"><%=
|
|
1
|
+
<h1 align="center"><%= packageName %> </h1>
|
|
2
2
|
<p>
|
|
3
3
|
<% if (isProjectOnNpm) { -%>
|
|
4
|
-
<a href="https://www.npmjs.com/package/<%=
|
|
5
|
-
<img alt="Version" src="https://img.shields.io/npm/v/<%=
|
|
4
|
+
<a href="https://www.npmjs.com/package/<%= packageName %>" target="_blank">
|
|
5
|
+
<img alt="Version" src="https://img.shields.io/npm/v/<%= packageName %>.svg">
|
|
6
6
|
</a>
|
|
7
7
|
<% } -%>
|
|
8
8
|
<% if (projectVersion && !isProjectOnNpm) { -%>
|
|
@@ -121,10 +121,9 @@
|
|
|
121
121
|
|
|
122
122
|
<% if (authorWebsite) { -%>
|
|
123
123
|
* Website: [<%= authorWebsite %>](<%= authorWebsite %>)
|
|
124
|
-
|
|
125
124
|
<% } -%>
|
|
126
|
-
<% if (
|
|
127
|
-
* GitHub: [@<%=
|
|
125
|
+
<% if (githubUsername) { -%>
|
|
126
|
+
* GitHub: [@<%= githubUsername %>](https://github.com/<%= githubUsername %>)
|
|
128
127
|
<% } -%>
|
|
129
128
|
<% if (twitterUsername) { -%>
|
|
130
129
|
* Twitter: [@<%= twitterUsername %>](https://twitter.com/<%= twitterUsername %>)
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
/* eslint-disable no-console, @typescript-eslint/no-var-requires */
|
|
2
2
|
const fs = require('fs-extra')
|
|
3
3
|
const path = require('path')
|
|
4
|
-
const { nodeFileTrace } = require('@vercel/nft')
|
|
4
|
+
const { nodeFileTrace } = require('@vercel/nft');
|
|
5
5
|
// !!! if any new dependencies are added, update the Dockerfile !!!
|
|
6
6
|
|
|
7
|
-
const projectRoot = path.resolve(process.env.PROJECT_ROOT || path.join(__dirname, '../'))
|
|
8
|
-
const resultFolder = path.join(projectRoot, 'app-minimal') // no need to resolve, ProjectRoot is always absolute
|
|
9
|
-
const pkg = fs.readJSONSync(path.join(projectRoot, 'package.json'))
|
|
10
|
-
const files = [pkg.main || 'dist/index.js'].map((file) => path.join(projectRoot, file));
|
|
11
|
-
|
|
12
7
|
(async () => {
|
|
8
|
+
const projectRoot = path.resolve(process.env.PROJECT_ROOT || path.join(__dirname, '../'))
|
|
9
|
+
const resultFolder = path.join(projectRoot, 'app-minimal') // no need to resolve, ProjectRoot is always absolute
|
|
10
|
+
const pkg = await fs.readJSON(path.join(projectRoot, 'package.json'))
|
|
11
|
+
|
|
12
|
+
let mainPath = ''
|
|
13
|
+
const mainPaths = [pkg.main, 'dist/index.js', 'dist/main.js']
|
|
14
|
+
for (const key of mainPaths) {
|
|
15
|
+
const fullPath = path.join(projectRoot, key)
|
|
16
|
+
if (await fs.pathExists(fullPath)) {
|
|
17
|
+
mainPath = fullPath
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!mainPath) {
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
const files = [mainPath]
|
|
13
24
|
console.log('Start analyzing, project root:', projectRoot)
|
|
14
25
|
const { fileList: fileSet } = await nodeFileTrace(files, {
|
|
15
26
|
base: projectRoot,
|