-
Notifications
You must be signed in to change notification settings - Fork 2
/
initiation.mjs
96 lines (85 loc) · 2.32 KB
/
initiation.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env zx
import * as fs from 'node:fs';
import * as semver from 'semver';
const PACKAGE_PATH = './package.json';
const FATHERRC_PATH = './.fatherrc.ts';
const INDEX_FILE_PATH = './src/index.ts';
const SDK_PACKAGE_NAME = process.env.SDK_PACKAGE_NAME;
const SDK_YUNTI_NAME = process.env.SDK_YUNTI_NAME;
const GRAPH_API_ENDPOINT = process.env.GRAPH_API_ENDPOINT;
const GRAPH_CLIENT_ENDPOINT = process.env.GRAPH_CLIENT_ENDPOINT;
const SDK_RELEASE_TYPE = process.env.SDK_RELEASE_TYPE;
const SDK_RELEASE_REGISTRY = process.env.SDK_RELEASE_REGISTRY;
const NPM_REGISTRY = process.env.NPM_REGISTRY || 'https://registry.npmjs.org/';
if (!SDK_PACKAGE_NAME) {
console.error('env SDK_PACKAGE_NAME is required')
process.exit(1)
}
if (!SDK_YUNTI_NAME) {
console.error('env SDK_YUNTI_NAME is required')
process.exit(1)
}
if (!GRAPH_API_ENDPOINT) {
console.error('env GRAPH_API_ENDPOINT is required')
process.exit(1)
}
if (!GRAPH_CLIENT_ENDPOINT) {
console.error('env GRAPH_CLIENT_ENDPOINT is required')
process.exit(1)
}
let version = '1.0.0';
try {
const preVersion = await $`npm view ${SDK_PACKAGE_NAME || 'antd'} version --registry ${NPM_REGISTRY}`;
console.log(preVersion)
if (!preVersion.stdout) {
process.exit(1)
}
version = semver.inc(preVersion.stdout || '1.0.0', SDK_RELEASE_TYPE || 'patch');
} catch (error) {
console.error(`failed to view ${SDK_PACKAGE_NAME} version`)
if (!error.message.includes('404')) {
process.exit(1)
}
}
fs.writeFileSync(
PACKAGE_PATH,
fs
.readFileSync(PACKAGE_PATH)
.toString()
.replace(
`"name": "@yuntijs/bff-sdk-name"`,
`"name": "${SDK_PACKAGE_NAME}"`
)
.replace(
`"version": "1.0.0"`,
`"version": "${version}"`
)
.replace(
`"library": "BffSDKLibrary"`,
`"library": "${SDK_YUNTI_NAME}"`
)
.replace(
`"registry": "https://registry.npmjs.org/"`,
`"registry": "${SDK_RELEASE_REGISTRY || 'https://registry.npmjs.org/'}"`
)
)
fs.writeFileSync(
FATHERRC_PATH,
fs
.readFileSync(FATHERRC_PATH)
.toString()
.replace(
`name: "BffSDKLibrary"`,
`name: "${SDK_YUNTI_NAME}"`
)
)
fs.writeFileSync(
INDEX_FILE_PATH,
fs
.readFileSync(INDEX_FILE_PATH)
.toString()
.replace(
`'<replace>grqph_client_endpoint</replace>'`,
`'${GRAPH_CLIENT_ENDPOINT}'`
)
)