@plugin-light/cli 1.0.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.
@@ -0,0 +1,100 @@
1
+ function getNpmTipTemplate({
2
+ prefix,
3
+ link,
4
+ postfix,
5
+ feedbackTitle,
6
+ feedbackList,
7
+ }) {
8
+ return `${colorFactory(96)}${prefix} (${colorFactory(94)} ${link} ${colorFactory(96)}) ${postfix}${colorFactory()}\n\n`
9
+ + `${colorFactory(96)}${feedbackTitle}${colorFactory()}\n`
10
+ + `${feedbackList
11
+ .map(feedback => `${colorFactory(96)}>${colorFactory(94)} ${feedback} ${colorFactory()}`)
12
+ .join('\n')
13
+ }\n`;
14
+ }
15
+
16
+
17
+ function getNpmTips({
18
+ packageName,
19
+ packageLink,
20
+ packagePostfix,
21
+ packagePostfixEn,
22
+ feedbackList,
23
+ }) {
24
+ const content = isUtf8Encoding()
25
+ ? getNpmTipTemplate({
26
+ prefix: `感谢您使用${packageName}`,
27
+ link: packageLink,
28
+ postfix: `${packagePostfix}!`,
29
+ feedbackTitle: '如有任何疑问或建议,可通过下述渠道向我们反馈:',
30
+ feedbackList,
31
+ })
32
+ : getNpmTipTemplate({
33
+ prefix: `Thank you for using ${packageName}`,
34
+ link: packageLink,
35
+ postfix: `${packagePostfixEn}!`,
36
+ feedbackTitle: 'If you have any issue or advice, you can give us feedback:',
37
+ feedbackList,
38
+ });
39
+
40
+
41
+ return content;
42
+ }
43
+
44
+
45
+ function colorFactory(color) {
46
+ if (!process.stdout.hasColors()) {
47
+ return '';
48
+ }
49
+ return `\u001B[${color ?? 0}m`;
50
+ }
51
+
52
+ function isUtf8Encoding() {
53
+ const { env: { LANG, LC_CTYPE } } = process;
54
+ const language = (LANG ?? LC_CTYPE ?? '').toLowerCase();
55
+
56
+ if (language.includes('utf-8') || language.includes('utf8')) {
57
+ return true;
58
+ }
59
+
60
+ if (process.platform === 'win32') {
61
+ return true;
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ function isShowInfo() {
68
+ return true;
69
+ }
70
+
71
+ function npmInstallTip({
72
+ packageName,
73
+ packageLink,
74
+ packagePostfix,
75
+ packagePostfixEn,
76
+ feedbackList,
77
+ }) {
78
+ const content = getNpmTips({
79
+ packageName,
80
+ packageLink,
81
+ packagePostfix,
82
+ packagePostfixEn,
83
+ feedbackList,
84
+ });
85
+
86
+ if (isShowInfo(content)) {
87
+ console.log(content);
88
+ }
89
+ }
90
+
91
+ npmInstallTip({
92
+ packageName: 'Press UI',
93
+ packageLink: 'https://git.aow.com/pmd-mobile/support/press-ui',
94
+ packagePostfix: '组件库',
95
+ packagePostfixEn: 'component library',
96
+ feedbackList: [
97
+ 'https://git.aow.com/pmd-mobile/support/press-ui/issues',
98
+ 'https://github.com/novlan1',
99
+ ],
100
+ });
@@ -0,0 +1,59 @@
1
+ const { execSync } = require('child_process');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const { traverseFolder } = require('t-comm');
6
+
7
+
8
+ function genPureReleaseDir({
9
+ targetRoot,
10
+ targetPackages,
11
+ sourcePackages,
12
+ toDeleteFiles,
13
+ }) {
14
+ execSync(`rm -rf ${targetRoot} \
15
+ rm -rf ${targetPackages} \
16
+ && mkdir -p ${targetPackages} \
17
+ && cp -r ${sourcePackages}/* ${targetPackages} \
18
+ && cp -r ${sourcePackages}/package.json ${path.dirname(targetPackages)} \
19
+ && cp -r ${sourcePackages}/.npmrc ${targetPackages} \
20
+ && rm -rf ${targetPackages}/node_modules`, {
21
+ stdio: 'inherit',
22
+ });
23
+
24
+
25
+ traverseFolder((file) => {
26
+ // const name = path.basename(file);
27
+ const reg = new RegExp(`press-[\\w-]+/(${toDeleteFiles.join('|')})`);
28
+ if (reg.test(file)) {
29
+ fs.unlinkSync(file);
30
+ console.log('已删除文件: ', file);
31
+ }
32
+ }, targetPackages);
33
+ }
34
+
35
+
36
+ function copyReadme({
37
+ sourceReadme,
38
+ targetReadme,
39
+ sourceChangelog,
40
+ targetChangelog,
41
+ }) {
42
+ const content = fs.readFileSync(sourceReadme, {
43
+ encoding: 'utf-8',
44
+ });
45
+
46
+ fs.writeFileSync(targetReadme, content, { encoding: 'utf-8' });
47
+
48
+ const changeLogContent = fs.readFileSync(sourceChangelog, {
49
+ encoding: 'utf-8',
50
+ });
51
+
52
+ fs.writeFileSync(targetChangelog, changeLogContent, { encoding: 'utf-8' });
53
+ }
54
+
55
+
56
+ module.exports = {
57
+ genPureReleaseDir,
58
+ copyReadme,
59
+ };
@@ -0,0 +1,31 @@
1
+ const { execSync } = require('child_process');
2
+
3
+
4
+ const PRE_RELEASE_VERSION = /\d+\.\d+\.\d+-(\w+).\d+/;
5
+
6
+
7
+ function getPreReleaseTag(version) {
8
+ const match = version.match(PRE_RELEASE_VERSION);
9
+ if (!match || !match[1]) return '';
10
+ return match[1];
11
+ }
12
+
13
+ function release({
14
+ version,
15
+ targetPackages,
16
+ }) {
17
+ const publishTag = getPreReleaseTag(version);
18
+ let publishScript = 'npm publish';
19
+ if (publishTag) {
20
+ publishScript = `npm publish --tag ${publishTag}`;
21
+ }
22
+
23
+ execSync(`cd ${targetPackages} && ${publishScript}`, {
24
+ stdio: 'inherit',
25
+ });
26
+ }
27
+
28
+
29
+ module.exports = {
30
+ release,
31
+ };
@@ -0,0 +1,39 @@
1
+ const { readFileSync, writeFileSync } = require('t-comm');
2
+
3
+
4
+ function getNewVersion({
5
+ rootPackageJson,
6
+ }) {
7
+ const pkg = readFileSync(rootPackageJson, true);
8
+ return pkg.version;
9
+ }
10
+
11
+ function changeVersion({
12
+ rootPackageJson,
13
+ packageJson,
14
+ }) {
15
+ const newVersion = getNewVersion({ rootPackageJson });
16
+
17
+ const pkg = readFileSync(packageJson, true);
18
+ console.log(`[VERSION] The new version is ${newVersion}`);
19
+ pkg.version = newVersion;
20
+
21
+ writeFileSync(packageJson, pkg, true);
22
+ return newVersion;
23
+ }
24
+
25
+
26
+ function changeRootVersion({
27
+ version,
28
+ rootPackageJson,
29
+ }) {
30
+ const content = readFileSync(rootPackageJson, true);
31
+ content.version = version;
32
+ writeFileSync(rootPackageJson, content, true);
33
+ }
34
+
35
+
36
+ module.exports = {
37
+ changeVersion,
38
+ changeRootVersion,
39
+ };
@@ -0,0 +1,114 @@
1
+ const fs = require('fs');
2
+
3
+ const { hyphenate, getPureCompName, getFullCompName } = require('t-comm');
4
+
5
+ const COMP_PREFIX = 'press-';
6
+
7
+ const ACT_GOODS_LIST_COMPONENTS = [
8
+ 'act-input-q-q',
9
+ 'act-select-award',
10
+ 'act-store-item',
11
+ 'act-benefit-item',
12
+ 'act-goods-list',
13
+ 'act-goods-item',
14
+ 'act-goods-tab',
15
+ 'act-merchant-item',
16
+ ];
17
+
18
+
19
+ const DEMO_DIR_MAP = {
20
+ PRESS: 'press',
21
+ GP: 'gp',
22
+ ACT: 'act',
23
+ ACT_DETAIL: 'act-detail',
24
+ ACT_LIST: 'act-list',
25
+ ACT_EXCHANGE: 'act-exchange',
26
+ };
27
+
28
+ const ACT_TYPES = [
29
+ 'act',
30
+ 'exchange',
31
+ 'goods',
32
+ 'goods-list',
33
+ ];
34
+
35
+
36
+ const isActComponent = component => component.startsWith('press-act-') || component.startsWith('act-');
37
+
38
+
39
+ function getActPageDir(component, config) {
40
+ if (config) {
41
+ const componentMap = Object.values(config).reduce((acc, item) => {
42
+ const { list } = item;
43
+ list.forEach((item) => {
44
+ acc[hyphenate(item.name)] = item;
45
+ });
46
+ return acc;
47
+ }, {});
48
+
49
+ const cur = componentMap[component];
50
+ const { subPackage = DEMO_DIR_MAP.PRESS } = cur || {};
51
+
52
+ return subPackage;
53
+ }
54
+
55
+ if (!isActComponent(component)) {
56
+ return DEMO_DIR_MAP.PRESS;
57
+ }
58
+
59
+ if (isActDetailComponent(component)) {
60
+ return DEMO_DIR_MAP.ACT_DETAIL;
61
+ }
62
+
63
+ if (isActGoodsListComponent(component)) {
64
+ return DEMO_DIR_MAP.ACT_LIST;
65
+ }
66
+
67
+ return DEMO_DIR_MAP.ACT;
68
+ }
69
+
70
+ /**
71
+ * goods detail 组件是根据前缀判断的
72
+ */
73
+ function isActDetailComponent(component) {
74
+ component = component.replace(/^press-/, '');
75
+
76
+ if (component.startsWith('act-goods-detail')
77
+ ) {
78
+ return true;
79
+ }
80
+ return false;
81
+ }
82
+
83
+ /**
84
+ * goods list 组件是枚举的
85
+ */
86
+ function isActGoodsListComponent(component) {
87
+ component = component.replace(/^press-/, '');
88
+
89
+ if (ACT_GOODS_LIST_COMPONENTS.includes(component)) {
90
+ return true;
91
+ }
92
+ return false;
93
+ }
94
+
95
+
96
+ const IS_INNER_DOCS = fs.existsSync('./docs/docs/.vuepress/config.js');
97
+
98
+
99
+ module.exports = {
100
+ hyphenate,
101
+ getFullCompName,
102
+ getPureCompName,
103
+
104
+ isActComponent,
105
+ isActDetailComponent,
106
+ isActGoodsListComponent,
107
+
108
+ getActPageDir,
109
+ COMP_PREFIX,
110
+ ACT_TYPES,
111
+
112
+ DEMO_DIR_MAP,
113
+ IS_INNER_DOCS,
114
+ };