mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
ci: add stackblitz templates (#49841)
* ci: add stackblitz templates
ref: https://github.com/ant-design/ant-design/pull/49647#issuecomment-2197884871
* chore: update ignore
* chore: fix
* chore: fix ci
* chore: update
* chore: update
* chore: 节约 ci 资源
* Revert "chore: 节约 ci 资源"
This reverts commit 0a3bb297f3
.
This commit is contained in:
parent
1d84cca4e3
commit
85c31f1c43
15
.github/workflows/pkg.pr.new.yml
vendored
15
.github/workflows/pkg.pr.new.yml
vendored
@ -20,4 +20,17 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- run: npx pkg-pr-new publish
|
# ========== Prepare examples ==========
|
||||||
|
- name: Clear examples
|
||||||
|
run: rm -rf examples
|
||||||
|
|
||||||
|
- name: Clone examples
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ant-design/ant-design-examples
|
||||||
|
path: examples
|
||||||
|
|
||||||
|
- name: Modify examples
|
||||||
|
run: npx tsx scripts/prepare-examples.ts
|
||||||
|
|
||||||
|
- run: npx pkg-pr-new publish --template './examples/examples/*'
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -76,3 +76,4 @@ __image_snapshots__/
|
|||||||
.node
|
.node
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
examples/
|
||||||
|
81
scripts/prepare-examples.ts
Normal file
81
scripts/prepare-examples.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import fg from 'fast-glob';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import path from 'path';
|
||||||
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
import isPlainObject from 'lodash/isPlainObject';
|
||||||
|
|
||||||
|
import rootPkg from '../package.json';
|
||||||
|
|
||||||
|
const examples = fg.sync(['examples/examples/**/package.json'], {
|
||||||
|
cwd: process.cwd(),
|
||||||
|
onlyFiles: true,
|
||||||
|
ignore: ['**/node_modules/**', '.git'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const _order = ['dependencies', 'devDependencies', 'peerDependencies'] as const;
|
||||||
|
|
||||||
|
function detectRootDepsVersion(pkgName: string) {
|
||||||
|
const _pkg: any = rootPkg;
|
||||||
|
|
||||||
|
for (let i = 0; i < _order.length; i++) {
|
||||||
|
const depKey = _order[i];
|
||||||
|
if (_pkg?.[depKey]?.[pkgName]) {
|
||||||
|
return _pkg[depKey][pkgName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncVersion(pkgJson = {}, deps: string[] = []) {
|
||||||
|
const _pkgJson: any = cloneDeep(pkgJson);
|
||||||
|
|
||||||
|
_order.forEach((key) => {
|
||||||
|
const _processDeps = _pkgJson[key];
|
||||||
|
|
||||||
|
if (isPlainObject(_processDeps)) {
|
||||||
|
Object.keys(_processDeps).forEach((dep) => {
|
||||||
|
if (deps.includes(dep)) {
|
||||||
|
_processDeps[dep] = detectRootDepsVersion(dep) ?? _processDeps[dep];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return _pkgJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
function modifyPackageJson(pkgJson: any) {
|
||||||
|
if (typeof pkgJson === 'object' && pkgJson !== null) {
|
||||||
|
return {
|
||||||
|
...syncVersion(
|
||||||
|
pkgJson,
|
||||||
|
['@ant-design/cssinjs'], // need to sync version
|
||||||
|
),
|
||||||
|
private: true,
|
||||||
|
author: 'antd GitHub CI',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
for (let i = 0; i < examples.length; i++) {
|
||||||
|
const example = examples[i];
|
||||||
|
|
||||||
|
const pkgJson = fs.readJsonSync(example);
|
||||||
|
const newPkgJson = modifyPackageJson(pkgJson) ?? pkgJson;
|
||||||
|
|
||||||
|
// unique named package.json
|
||||||
|
newPkgJson.name = path.basename(path.dirname(example));
|
||||||
|
|
||||||
|
const rewritePath = process.env.CI ? example : `${example}.tmp`; // ignored
|
||||||
|
|
||||||
|
fs.writeJsonSync(rewritePath, newPkgJson, { spaces: 2 });
|
||||||
|
|
||||||
|
globalThis.console.log(`🔮 [prepare-examples] ${pkgJson.name} has been prepared.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. git clone --depth=1 git@github.com:ant-design/ant-design-examples.git examples
|
||||||
|
* 2. npx tsx scripts/prepare-examples.ts
|
||||||
|
*/
|
||||||
|
main();
|
Loading…
Reference in New Issue
Block a user