Skip to content

Commit ef192e9

Browse files
authored
feat: iceworks-cli@3.4.7 add componentType to material data (#222)
* feat: add componentType to material data * chore: ci publish support beta version * fix: ci scripts * fix: ci error * fix: componentType consider peerDeps * chore: version
1 parent 612139d commit ef192e9

File tree

7 files changed

+123
-98
lines changed

7 files changed

+123
-98
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [10.x]
12+
node-version: [12.x]
1313

1414
steps:
1515
- uses: actions/checkout@v2
@@ -27,5 +27,6 @@ jobs:
2727
- run: npm run publish:packages
2828
env:
2929
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
30+
DING_WEBHOOK: ${{secrets.DING_WEBHOOK}}
3031
- name: Upload coverage to Codecov
3132
uses: codecov/codecov-action@v1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"fs-extra": "^8.1.0",
3030
"glob": "^7.1.6",
3131
"husky": "^4.2.3",
32+
"ice-npm-utils": "^2.1.2",
3233
"jest": "^25.1.0",
3334
"jest-extended": "^0.11.5",
3435
"lerna": "^3.22.1",

packages/iceworks-cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 3.4.7
4+
5+
- [feat] 物料数据里增加 componentType(antd/fusion) 字段
6+
37
## 3.4.6
48

59
- [chore] 允许 pkg.scaffoldConfig 覆盖自动检测的 languageType 字段

packages/iceworks-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iceworks",
3-
"version": "3.4.6",
3+
"version": "3.4.7",
44
"description": "Iceworks CLI for develop project/material-collection/component.",
55
"main": "bin/iceworks.js",
66
"bin": {

packages/iceworks-cli/src/command/generate/generateMaterialData.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,17 @@ export default async function generateMaterialData(pkgPath, materialType, materi
5151
log.warn('getProjectLanguageType warning', err.message);
5252
}
5353

54+
// antd、fusion
55+
let componentType;
56+
try {
57+
componentType = await getProjectComponentType(pkg);
58+
} catch (err) {
59+
log.warn('getProjectComponentType warning', err.message);
60+
}
61+
5462
const materialData = {
5563
languageType,
64+
componentType,
5665
homepage,
5766
description: pkg.description,
5867
repository: pkg.repository?.url || pkg.repository,
@@ -146,3 +155,21 @@ async function getProjectLanguageType(projectPath, pkgData) {
146155
return 'ts';
147156
}
148157
}
158+
159+
160+
async function getProjectComponentType(pkgData) {
161+
const { dependencies = {}, devDependencies = {}, peerDependencies = {} } = pkgData;
162+
const deps = { ...devDependencies, ...peerDependencies, ...dependencies };
163+
164+
if (deps.antd) {
165+
return 'antd';
166+
}
167+
168+
if (deps['@alifd/next'] || deps['@alife/next'] || deps['@icedesign/base']) {
169+
return 'fusion';
170+
}
171+
172+
if (deps['@alifd/meet']) {
173+
return 'fusion-mobile';
174+
}
175+
}

scripts/getPackageInfos.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

scripts/publish.ts

Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,98 @@
1-
/**
2-
* Scripts to check unpublished version and run publish
3-
*/
1+
import { execSync } from 'child_process';
2+
import { existsSync, readdirSync } from 'fs';
43
import { join } from 'path';
5-
import { spawnSync } from 'child_process';
6-
import { IPackageInfo, getPackageInfos } from './getPackageInfos';
4+
import * as fse from 'fs-extra';
5+
import * as axios from 'axios';
6+
import { getVersions } from 'ice-npm-utils';
77

8-
if (process.env.BRANCH_NAME !== 'master') {
9-
console.log('No Publish', process.env.BRANCH_NAME);
10-
process.exit(0);
8+
// Set by github actions
9+
const branchName = process.env.BRANCH_NAME;
10+
const rootDir = join(__dirname, '../');
11+
const REGISTRY = 'https://registry.npmjs.org/';
12+
13+
if (!branchName) {
14+
throw new Error('Only support publish in GitHub Actions env');
1115
}
1216

13-
function publish(pkg: string, version: string, directory: string): void {
14-
console.log('[PUBLISH]', `${pkg}@${version}`);
17+
(async () => {
18+
const packageDirs = getPackagesPaths(join(rootDir, 'packages'));
19+
20+
for (const pkgDir of packageDirs) {
21+
// eslint-disable-next-line no-await-in-loop
22+
await publishPackage(pkgDir);
23+
}
24+
25+
})().catch(err => {
26+
console.error(err);
27+
process.exit(1);
28+
});
29+
30+
async function publishPackage(packageDir) {
31+
const pkgData = await fse.readJSON(join(packageDir, 'package.json'));
32+
const { version, name } = pkgData;
33+
const npmTag = branchName === 'master' ? 'latest' : 'beta';
34+
35+
const versionExist = await checkVersionExist(name, version, REGISTRY);
36+
if (versionExist) {
37+
console.log(`${name}@${version} 已存在,无需发布。`);
38+
return;
39+
}
40+
41+
const isProdVersion = /^\d+\.\d+\.\d+$/.test(version);
42+
if (branchName === 'master' && !isProdVersion) {
43+
throw new Error(`禁止在 master 分支发布非正式版本 ${version}`);
44+
}
45+
46+
if (branchName !== 'master' && isProdVersion) {
47+
console.log(`非 master 分支 ${branchName},不发布正式版本 ${version}`);
48+
return;
49+
}
1550

16-
spawnSync('npm', [
17-
'publish',
18-
// use default registry
19-
], {
51+
console.log('start publish', version, npmTag);
52+
execSync('npm install', {
53+
cwd: packageDir,
2054
stdio: 'inherit',
21-
cwd: directory,
2255
});
56+
execSync(`npm publish --tag ${npmTag}`, {
57+
cwd: packageDir,
58+
stdio: 'inherit',
59+
});
60+
61+
console.log('start notify');
62+
const response = await axios.default({
63+
url: process.env.DING_WEBHOOK,
64+
method: 'post',
65+
headers: {
66+
'Content-Type': 'application/json;charset=utf-8',
67+
},
68+
data: {
69+
msgtype: 'markdown',
70+
markdown: {
71+
title: `${name}@${version} 发布成功`,
72+
text: `${name}@${version} 发布成功`,
73+
},
74+
},
75+
});
76+
console.log('notify success', response.data);
2377
}
2478

25-
// Entry
26-
console.log('[PUBLISH] Start:');
27-
28-
Promise.all([
29-
getPackageInfos(join(__dirname, '../packages'))
30-
]).then((result: IPackageInfo[][]) => {
31-
32-
let publishedCount = 0;
33-
// Publish
34-
for (let i = 0; i < result.length; i++) {
35-
const packageInfos: IPackageInfo[] = result[i];
36-
for (let j = 0; j < packageInfos.length; j++) {
37-
const { name, directory, localVersion, shouldPublish } = packageInfos[j];
38-
if (shouldPublish) {
39-
publishedCount++;
40-
console.log(`--- ${name}@${localVersion} ---`);
41-
publish(name, localVersion, directory);
42-
}
43-
}
79+
80+
async function checkVersionExist(name: string, version: string, registry?: string): Promise<boolean> {
81+
try {
82+
const versions = await getVersions(name, registry);
83+
return versions.indexOf(version) !== -1;
84+
} catch (err) {
85+
console.error('checkVersionExist error', err);
86+
return false;
4487
}
45-
console.log(`[PUBLISH] Complete (count=${publishedCount}).`)
46-
});
88+
}
89+
90+
function getPackagesPaths(dir) {
91+
const packagesPaths: string[] = readdirSync(dir).map(dirname => {
92+
return join(dir, dirname);
93+
}).filter((dirpath) => {
94+
return existsSync(join(dirpath, 'package.json'));
95+
});
96+
97+
return packagesPaths;
98+
}

0 commit comments

Comments
 (0)