@coze/cli 0.0.2 → 0.0.3
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/cli.mjs +1 -957
- package/dist/index.mjs +1 -263
- package/package.json +1 -1
- package/dist/cli.js +0 -36
- package/dist/commands/base.js +0 -28
- package/dist/commands/login.js +0 -18
- package/dist/commands/logout.js +0 -20
- package/dist/helpers/constants.js +0 -44
- package/dist/helpers/logger.js +0 -21
- package/dist/helpers/package.js +0 -33
- package/dist/helpers/request.js +0 -24
- package/dist/helpers/types.js +0 -2
- package/dist/index.js +0 -2
- package/dist/npm.js +0 -109
- package/dist/oauth.js +0 -61
package/dist/index.mjs
CHANGED
|
@@ -1,263 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
5
|
-
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
|
|
6
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react__ from "@rsbuild/plugin-react";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less__ from "@rsbuild/plugin-less";
|
|
8
|
-
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
9
|
-
import "prettier";
|
|
10
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rslib_core__ from "@rslib/core";
|
|
11
|
-
import * as __WEBPACK_EXTERNAL_MODULE_commander__ from "commander";
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- ignore */ function addCommand({ program, spec, runAuth }) {
|
|
13
|
-
const command = program.command(spec.name);
|
|
14
|
-
command.description(spec.description);
|
|
15
|
-
(spec.arguments ?? []).forEach((argument)=>{
|
|
16
|
-
command.addArgument(argument);
|
|
17
|
-
});
|
|
18
|
-
(spec.options ?? []).forEach((option)=>{
|
|
19
|
-
command.addOption(option);
|
|
20
|
-
});
|
|
21
|
-
if (spec.action) command.action(async (...args)=>{
|
|
22
|
-
if (spec.auth && runAuth) await runAuth();
|
|
23
|
-
await spec.action?.(...args);
|
|
24
|
-
});
|
|
25
|
-
(spec.subCommands ?? []).forEach((subCommand)=>{
|
|
26
|
-
addCommand({
|
|
27
|
-
program: command,
|
|
28
|
-
spec: subCommand,
|
|
29
|
-
runAuth
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
const logger = {
|
|
34
|
-
info (...messages) {
|
|
35
|
-
console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].blue('[INFO]'), ...messages);
|
|
36
|
-
},
|
|
37
|
-
success (...messages) {
|
|
38
|
-
console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].green('[SUCCESS]'), ...messages);
|
|
39
|
-
},
|
|
40
|
-
warning (...messages) {
|
|
41
|
-
console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow('[WARNING]'), ...messages);
|
|
42
|
-
},
|
|
43
|
-
error (...messages) {
|
|
44
|
-
console.error(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red('[ERROR]'), ...messages);
|
|
45
|
-
},
|
|
46
|
-
debug (...messages) {
|
|
47
|
-
if (process.env.DEBUG) console.log(__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].magenta('[DEBUG]'), ...messages);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* @coze/a-b -> __coze__a_b
|
|
52
|
-
* @coze-ui/a-b -> __coze_ui__a_b
|
|
53
|
-
* a-b -> a_b
|
|
54
|
-
*/ function pkgName2RemoteName(pkgName) {
|
|
55
|
-
const hasScope = pkgName.startsWith('@');
|
|
56
|
-
const parts = pkgName.split('/');
|
|
57
|
-
return `${hasScope ? `__${parts[0].slice(1)}__` : parts[0]}${parts.slice(1).join('_')}`.replace(/-/g, '_');
|
|
58
|
-
}
|
|
59
|
-
// @module-federation/rsbuild-plugin only support cjs
|
|
60
|
-
const config_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
|
|
61
|
-
const pluginModuleFederation = config_require('@module-federation/rsbuild-plugin').pluginModuleFederation;
|
|
62
|
-
const { isEmpty, merge } = __WEBPACK_EXTERNAL_MODULE_lodash__["default"];
|
|
63
|
-
const CONFIG_FILE_NAME = 'ui.config';
|
|
64
|
-
const CONFIG_FILE_EXTNAME = [
|
|
65
|
-
'.js',
|
|
66
|
-
'.ts',
|
|
67
|
-
'.tsx',
|
|
68
|
-
'.mjs',
|
|
69
|
-
'.mts',
|
|
70
|
-
'.cjs',
|
|
71
|
-
'.cts'
|
|
72
|
-
];
|
|
73
|
-
const CDN_MAP = {
|
|
74
|
-
boe: '//lf0-fast-deliver-inner.bytedance.net/obj/eden-internal/ibo-lgvj/ljhwZthlaukjlkulzlp/',
|
|
75
|
-
cn: '//lf3-static.bytednsdoc.com/obj/eden-cn/ibo-lgvj/ljhwZthlaukjlkulzlp/'
|
|
76
|
-
};
|
|
77
|
-
function defineConfig(config) {
|
|
78
|
-
return config;
|
|
79
|
-
}
|
|
80
|
-
async function loadConfig({ cwd = process.cwd(), path }) {
|
|
81
|
-
const configFilePath = resolveConfigPath(cwd, path);
|
|
82
|
-
const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadConfig)({
|
|
83
|
-
cwd: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configFilePath),
|
|
84
|
-
path: configFilePath
|
|
85
|
-
});
|
|
86
|
-
content._privateMeta = {
|
|
87
|
-
configFilePath
|
|
88
|
-
};
|
|
89
|
-
return content;
|
|
90
|
-
}
|
|
91
|
-
function getShareRslibConfig(uiConfig, libConfig) {
|
|
92
|
-
const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
|
|
93
|
-
const pkgJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, 'package.json'), 'utf-8'));
|
|
94
|
-
const umdName = pkgName2RemoteName(pkgJson.name);
|
|
95
|
-
const entries = resolveExports(uiConfig);
|
|
96
|
-
const tsconfigPath = resolveTsconfigPath(projectDir);
|
|
97
|
-
const libs = [];
|
|
98
|
-
const formats = [
|
|
99
|
-
'cjs',
|
|
100
|
-
'esm',
|
|
101
|
-
'umd',
|
|
102
|
-
'mf'
|
|
103
|
-
];
|
|
104
|
-
Object.entries(entries).forEach(([dist, src])=>{
|
|
105
|
-
for (const format of formats){
|
|
106
|
-
// mf should use exposes instead of multiple entries
|
|
107
|
-
if ('mf' === format && '.' !== dist) continue;
|
|
108
|
-
const config = {
|
|
109
|
-
dts: {
|
|
110
|
-
bundle: false
|
|
111
|
-
},
|
|
112
|
-
format,
|
|
113
|
-
output: {
|
|
114
|
-
distPath: {
|
|
115
|
-
root: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join('dist', format, dist)
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
source: {
|
|
119
|
-
tsconfigPath,
|
|
120
|
-
entry: {
|
|
121
|
-
index: src
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
shims: {
|
|
125
|
-
cjs: {
|
|
126
|
-
'import.meta.url': true
|
|
127
|
-
},
|
|
128
|
-
esm: {
|
|
129
|
-
__filename: true,
|
|
130
|
-
__dirname: true,
|
|
131
|
-
require: true
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
// each entry should have unique name
|
|
135
|
-
umdName: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(umdName, dist).replace(/\//g, '_')
|
|
136
|
-
};
|
|
137
|
-
if ('mf' === format) {
|
|
138
|
-
// default use boe
|
|
139
|
-
const cdn = CDN_MAP[process.env.REGION ?? ''] ?? CDN_MAP.boe;
|
|
140
|
-
const singleton = [
|
|
141
|
-
'react',
|
|
142
|
-
'react-dom'
|
|
143
|
-
];
|
|
144
|
-
let shared = uiConfig.shared ?? {};
|
|
145
|
-
if (isEmpty(shared) && null !== uiConfig.shared) for (const type of [
|
|
146
|
-
'dependencies',
|
|
147
|
-
'peerDependencies'
|
|
148
|
-
])Object.entries(pkgJson[type]).forEach(([name])=>{
|
|
149
|
-
shared[name] = {
|
|
150
|
-
singleton: singleton.includes(name)
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
merge(config, {
|
|
154
|
-
output: {
|
|
155
|
-
assetPrefix: `${cdn}${__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(`${pkgJson.name}@${pkgJson.version}`, 'dist/mf', dist)}`
|
|
156
|
-
},
|
|
157
|
-
plugins: [
|
|
158
|
-
pluginModuleFederation({
|
|
159
|
-
name: umdName,
|
|
160
|
-
exposes: entries,
|
|
161
|
-
shared
|
|
162
|
-
})
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
} else if ('umd' === format) merge(config, {
|
|
166
|
-
output: {
|
|
167
|
-
minify: true,
|
|
168
|
-
injectStyles: true
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
libs.push(merge(config, libConfig));
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
return merge({
|
|
175
|
-
lib: libs,
|
|
176
|
-
plugins: [
|
|
177
|
-
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react__.pluginReact)(),
|
|
178
|
-
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less__.pluginLess)()
|
|
179
|
-
]
|
|
180
|
-
}, uiConfig.rslib ?? {}, {
|
|
181
|
-
_privateMeta: uiConfig._privateMeta
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function resolveConfigPath(root, customConfig) {
|
|
185
|
-
if (customConfig) {
|
|
186
|
-
const customConfigPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(customConfig) ? customConfig : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, customConfig);
|
|
187
|
-
if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(customConfigPath)) {
|
|
188
|
-
if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].statSync(customConfigPath).isFile()) return customConfigPath;
|
|
189
|
-
root = customConfigPath;
|
|
190
|
-
} else throw new Error(`${CONFIG_FILE_NAME} not found in ${customConfigPath}`);
|
|
191
|
-
}
|
|
192
|
-
const configFilePath = CONFIG_FILE_EXTNAME.map((extname)=>`${__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, CONFIG_FILE_NAME)}${extname}`).find((p)=>__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(p));
|
|
193
|
-
if (configFilePath) return configFilePath;
|
|
194
|
-
throw new Error(`${CONFIG_FILE_NAME} not found in ${root}`);
|
|
195
|
-
}
|
|
196
|
-
function resolveTsconfigPath(root) {
|
|
197
|
-
// Preferred tsconfig.build.json
|
|
198
|
-
if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(root, 'tsconfig.build.json'))) return 'tsconfig.build.json';
|
|
199
|
-
return 'tsconfig.json';
|
|
200
|
-
}
|
|
201
|
-
function resolveMainEntry(projectDir) {
|
|
202
|
-
const mainEntry = CONFIG_FILE_EXTNAME.map((extname)=>`index${extname}`).find((e)=>__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, `src/${e}`)));
|
|
203
|
-
return mainEntry;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* The `exports` field in `package.json` must adhere to the following format:
|
|
207
|
-
*
|
|
208
|
-
* ```
|
|
209
|
-
* exports: {
|
|
210
|
-
* ".": {
|
|
211
|
-
* ...
|
|
212
|
-
* "src": "./src/index.tsx"
|
|
213
|
-
* },
|
|
214
|
-
* "./button": {
|
|
215
|
-
* ...
|
|
216
|
-
* "src": "./src/button/index.tsx"
|
|
217
|
-
* }
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*/ function resolveExports(uiConfig) {
|
|
221
|
-
const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
|
|
222
|
-
const srcEntry = resolveMainEntry(projectDir);
|
|
223
|
-
if (!srcEntry) throw new Error('entry not found, maybe you forget the "src/index.ts"?');
|
|
224
|
-
const pkgJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectDir, 'package.json'), 'utf-8'));
|
|
225
|
-
let exposes = {};
|
|
226
|
-
Object.entries(pkgJson.exports ?? {}).forEach(([key, config])=>{
|
|
227
|
-
if (!config.src) {
|
|
228
|
-
logger.warning([
|
|
229
|
-
`exports.${key} does't have "src", the builder will ignore this export.`,
|
|
230
|
-
`you should add "src" field, such as:\n`,
|
|
231
|
-
'exports: {\n',
|
|
232
|
-
` "${key}": {\n`,
|
|
233
|
-
' "src": "./src/index.tsx"\n',
|
|
234
|
-
' }\n',
|
|
235
|
-
'}'
|
|
236
|
-
].join(''));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
// mfplugin doesn't support "./"
|
|
240
|
-
const k = './' === key ? '.' : key;
|
|
241
|
-
exposes[k] = config.src;
|
|
242
|
-
});
|
|
243
|
-
// use default export
|
|
244
|
-
if (isEmpty(exposes)) exposes['.'] = `./src/${srcEntry}`;
|
|
245
|
-
return exposes;
|
|
246
|
-
}
|
|
247
|
-
/* eslint-disable security/detect-non-literal-fs-filename -- ignore */ const buildAction = async (options = {})=>{
|
|
248
|
-
const uiConfig = await loadConfig({
|
|
249
|
-
path: options.dir
|
|
250
|
-
});
|
|
251
|
-
const projectDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(uiConfig._privateMeta.configFilePath);
|
|
252
|
-
// esm/cjs/umd/mf
|
|
253
|
-
const prevCwd = process.cwd();
|
|
254
|
-
try {
|
|
255
|
-
process.chdir(projectDir);
|
|
256
|
-
const rslibConfig = getShareRslibConfig(uiConfig, options.libConfig);
|
|
257
|
-
await (0, __WEBPACK_EXTERNAL_MODULE__rslib_core__.build)(rslibConfig);
|
|
258
|
-
} catch (e) {} finally{
|
|
259
|
-
process.chdir(prevCwd);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
new __WEBPACK_EXTERNAL_MODULE_commander__.Option('-d, --dir <componentDir>', 'the path of component');
|
|
263
|
-
export { addCommand, buildAction, defineConfig };
|
|
1
|
+
function a({program:o,spec:n,runAuth:t}){let c=o.command(n.name);c.description(n.description),(n.arguments??[]).forEach(a=>{c.addArgument(a)}),(n.options??[]).forEach(a=>{c.addOption(a)}),n.action&&c.action(async(...a)=>{n.auth&&t&&await t(),await n.action?.(...a)}),(n.subCommands??[]).forEach(o=>{a({program:c,spec:o,runAuth:t})})}export{a as addCommand};
|
package/package.json
CHANGED
package/dist/cli.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { OauthClient } from './oauth';
|
|
3
|
-
import { NpmConfig } from './npm';
|
|
4
|
-
import { logoutSpec } from './commands/logout';
|
|
5
|
-
import { loginSpec } from './commands/login';
|
|
6
|
-
import { addCommand } from './commands/base';
|
|
7
|
-
const program = new Command();
|
|
8
|
-
program
|
|
9
|
-
.name('coze')
|
|
10
|
-
.version(process.env.PACKAGE_VERSION)
|
|
11
|
-
.description('A command-line tool for component development');
|
|
12
|
-
let DEV_COMMANDS = [];
|
|
13
|
-
if (import.meta.env.PUBLIC_INHOUSE) {
|
|
14
|
-
const uiCommands = await import('./commands/ui');
|
|
15
|
-
DEV_COMMANDS = [uiCommands.uiSpec];
|
|
16
|
-
}
|
|
17
|
-
[loginSpec, logoutSpec, ...DEV_COMMANDS].forEach(spec => {
|
|
18
|
-
const runAuth = async () => {
|
|
19
|
-
// refresh token
|
|
20
|
-
const npmConfig = new NpmConfig();
|
|
21
|
-
const { region, registryUrl, scope } = await npmConfig.loadConfig();
|
|
22
|
-
const oauthClient = new OauthClient(region);
|
|
23
|
-
await oauthClient.activate(npmConfig);
|
|
24
|
-
// add env
|
|
25
|
-
process.env.REGION = region;
|
|
26
|
-
process.env.REGISTRY = registryUrl;
|
|
27
|
-
process.env.SCOPE = scope;
|
|
28
|
-
};
|
|
29
|
-
addCommand({
|
|
30
|
-
spec,
|
|
31
|
-
program,
|
|
32
|
-
runAuth,
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
program.parse(process.argv);
|
|
36
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/commands/base.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export function addCommand({ program, spec, runAuth, }) {
|
|
2
|
-
var _a, _b, _c;
|
|
3
|
-
const command = program.command(spec.name);
|
|
4
|
-
command.description(spec.description);
|
|
5
|
-
((_a = spec.arguments) !== null && _a !== void 0 ? _a : []).forEach((argument) => {
|
|
6
|
-
command.addArgument(argument);
|
|
7
|
-
});
|
|
8
|
-
((_b = spec.options) !== null && _b !== void 0 ? _b : []).forEach((option) => {
|
|
9
|
-
command.addOption(option);
|
|
10
|
-
});
|
|
11
|
-
if (spec.action) {
|
|
12
|
-
command.action(async (...args) => {
|
|
13
|
-
var _a;
|
|
14
|
-
if (spec.auth && runAuth) {
|
|
15
|
-
await runAuth();
|
|
16
|
-
}
|
|
17
|
-
await ((_a = spec.action) === null || _a === void 0 ? void 0 : _a.call(spec, ...args));
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
((_c = spec.subCommands) !== null && _c !== void 0 ? _c : []).forEach(subCommand => {
|
|
21
|
-
addCommand({
|
|
22
|
-
program: command,
|
|
23
|
-
spec: subCommand,
|
|
24
|
-
runAuth,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=base.js.map
|
package/dist/commands/login.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Option } from 'commander';
|
|
2
|
-
import { OauthClient } from '../oauth';
|
|
3
|
-
import { NpmConfig } from '../npm';
|
|
4
|
-
import { REGION_VALUES } from '../helpers/constants';
|
|
5
|
-
export async function loginAction({ region }) {
|
|
6
|
-
const npmConfig = new NpmConfig({ region });
|
|
7
|
-
const authClient = new OauthClient(region);
|
|
8
|
-
await authClient.activate(npmConfig);
|
|
9
|
-
}
|
|
10
|
-
export const loginSpec = {
|
|
11
|
-
name: 'login',
|
|
12
|
-
description: 'log in to the hub',
|
|
13
|
-
action: loginAction,
|
|
14
|
-
options: [
|
|
15
|
-
new Option('-r, --region <name>', 'the region of hub').choices(REGION_VALUES),
|
|
16
|
-
],
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=login.js.map
|
package/dist/commands/logout.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Option } from 'commander';
|
|
2
|
-
import { OauthClient } from '../oauth';
|
|
3
|
-
import { NpmConfig } from '../npm';
|
|
4
|
-
import { REGION_VALUES } from '../helpers/constants';
|
|
5
|
-
export async function logoutAction({ region, scope, source, }) {
|
|
6
|
-
const npmConfig = new NpmConfig({ region, scope, source });
|
|
7
|
-
const authClient = new OauthClient(region);
|
|
8
|
-
await authClient.deactivate(npmConfig);
|
|
9
|
-
}
|
|
10
|
-
export const logoutSpec = {
|
|
11
|
-
name: 'logout',
|
|
12
|
-
description: 'log out of the hub',
|
|
13
|
-
action: logoutAction,
|
|
14
|
-
options: [
|
|
15
|
-
new Option('-r, --region <name>', 'the region of hub').choices(REGION_VALUES),
|
|
16
|
-
new Option('-s, --scope <name>', 'the scope of package'),
|
|
17
|
-
new Option('-b, --source <name>', 'the business source'),
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=logout.js.map
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export var Region;
|
|
2
|
-
(function (Region) {
|
|
3
|
-
Region["CN"] = "cn";
|
|
4
|
-
// I18N = 'i18n',
|
|
5
|
-
})(Region || (Region = {}));
|
|
6
|
-
let REGISTRY_HOST = {
|
|
7
|
-
[Region.CN]: 'npm-hub.coze.cn',
|
|
8
|
-
// [Region.I18N]: 'npm-hub.coze.com',
|
|
9
|
-
};
|
|
10
|
-
let CLIENT_ID_MAP = {
|
|
11
|
-
[Region.CN]: '13474932957575400683007237571476.app.coze',
|
|
12
|
-
};
|
|
13
|
-
let ISSUER_MAP = {
|
|
14
|
-
[Region.CN]: 'https://api.coze.cn',
|
|
15
|
-
};
|
|
16
|
-
let REGION_VALUES = Object.values(Region);
|
|
17
|
-
let isLocalDev = () => false;
|
|
18
|
-
if (import.meta.env.PUBLIC_INHOUSE) {
|
|
19
|
-
let DevRegion;
|
|
20
|
-
(function (DevRegion) {
|
|
21
|
-
DevRegion["LOCAL"] = "local";
|
|
22
|
-
DevRegion["CN_BOE"] = "boe";
|
|
23
|
-
})(DevRegion || (DevRegion = {}));
|
|
24
|
-
REGISTRY_HOST = {
|
|
25
|
-
...REGISTRY_HOST,
|
|
26
|
-
[DevRegion.CN_BOE]: 'npm-hub-boe.bytedance.net',
|
|
27
|
-
[DevRegion.LOCAL]: 'localhost:3000',
|
|
28
|
-
};
|
|
29
|
-
CLIENT_ID_MAP = {
|
|
30
|
-
...CLIENT_ID_MAP,
|
|
31
|
-
[DevRegion.CN_BOE]: '70653688608994412341629476687797.app.coze',
|
|
32
|
-
[DevRegion.LOCAL]: '70653688608994412341629476687797.app.coze',
|
|
33
|
-
};
|
|
34
|
-
ISSUER_MAP = {
|
|
35
|
-
...ISSUER_MAP,
|
|
36
|
-
[DevRegion.CN_BOE]: 'https://api-bot-boe.bytedance.net',
|
|
37
|
-
[DevRegion.LOCAL]: 'https://api-bot-boe.bytedance.net',
|
|
38
|
-
};
|
|
39
|
-
REGION_VALUES = Object.values({ ...DevRegion, ...Region });
|
|
40
|
-
isLocalDev = (region) => region === DevRegion.LOCAL;
|
|
41
|
-
}
|
|
42
|
-
export const DEFAULT_REGION = Region.CN;
|
|
43
|
-
export { REGION_VALUES, isLocalDev, REGISTRY_HOST, CLIENT_ID_MAP, ISSUER_MAP };
|
|
44
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/helpers/logger.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import colors from 'picocolors';
|
|
2
|
-
export const logger = {
|
|
3
|
-
info(...messages) {
|
|
4
|
-
console.log(colors.blue('[INFO]'), ...messages);
|
|
5
|
-
},
|
|
6
|
-
success(...messages) {
|
|
7
|
-
console.log(colors.green('[SUCCESS]'), ...messages);
|
|
8
|
-
},
|
|
9
|
-
warning(...messages) {
|
|
10
|
-
console.log(colors.yellow('[WARNING]'), ...messages);
|
|
11
|
-
},
|
|
12
|
-
error(...messages) {
|
|
13
|
-
console.error(colors.red('[ERROR]'), ...messages);
|
|
14
|
-
},
|
|
15
|
-
debug(...messages) {
|
|
16
|
-
if (process.env.DEBUG) {
|
|
17
|
-
console.log(colors.magenta('[DEBUG]'), ...messages);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/helpers/package.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- ignore */
|
|
2
|
-
/* eslint-disable security/detect-non-literal-fs-filename -- ignore */
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
export function resolvePackageJson(projectDir) {
|
|
6
|
-
const pkgJsonFilePath = path.join(projectDir, 'package.json');
|
|
7
|
-
if (!fs.existsSync(pkgJsonFilePath)) {
|
|
8
|
-
throw new Error(`package.json not found in ${projectDir}`);
|
|
9
|
-
}
|
|
10
|
-
const content = fs.readFileSync(pkgJsonFilePath, 'utf-8');
|
|
11
|
-
return JSON.parse(content);
|
|
12
|
-
}
|
|
13
|
-
export function resolvePackageDir(dir = '') {
|
|
14
|
-
if (path.isAbsolute(dir)) {
|
|
15
|
-
return dir;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return path.join(process.cwd(), dir);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @coze/a-b -> __coze__a_b
|
|
23
|
-
* @coze-ui/a-b -> __coze_ui__a_b
|
|
24
|
-
* a-b -> a_b
|
|
25
|
-
*/
|
|
26
|
-
export function pkgName2RemoteName(pkgName) {
|
|
27
|
-
const hasScope = pkgName.startsWith('@');
|
|
28
|
-
const parts = pkgName.split('/');
|
|
29
|
-
return `${hasScope ? `__${parts[0].slice(1)}__` : parts[0]}${parts
|
|
30
|
-
.slice(1)
|
|
31
|
-
.join('_')}`.replace(/-/g, '_');
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=package.js.map
|
package/dist/helpers/request.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import { logger } from './logger';
|
|
5
|
-
export async function loadRequestConfig() {
|
|
6
|
-
const configPath = path.join(os.homedir(), '.coze-hub', 'request.js');
|
|
7
|
-
if (!fs.existsSync(configPath)) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
try {
|
|
11
|
-
const fileContent = fs.readFileSync(configPath, 'utf8');
|
|
12
|
-
const moduleWrapper = new Function('module', 'exports', fileContent);
|
|
13
|
-
const module = { exports: {} };
|
|
14
|
-
await moduleWrapper(module, module.exports);
|
|
15
|
-
const config = module.exports;
|
|
16
|
-
logger.info('loadRequestConfig', config);
|
|
17
|
-
return config;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
logger.warning('Failed to load request config:', error);
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=request.js.map
|
package/dist/helpers/types.js
DELETED
package/dist/index.js
DELETED
package/dist/npm.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import npmDefinitions from '@npmcli/config/lib/definitions/index.js';
|
|
2
|
-
import Config from '@npmcli/config';
|
|
3
|
-
import { logger } from './helpers/logger';
|
|
4
|
-
import { DEFAULT_REGION, isLocalDev, REGISTRY_HOST, } from './helpers/constants';
|
|
5
|
-
const { shorthands, definitions, flatten } = npmDefinitions;
|
|
6
|
-
const CONFIG_TYPE = 'user';
|
|
7
|
-
const REFRESH_TOKEN_KEY = 'refresh_token';
|
|
8
|
-
const DEFAULT_PACKAGE_SCOPE = 'coze-kit';
|
|
9
|
-
const DEFAULT_BUSINESS_SOURCE = 'coze';
|
|
10
|
-
export class NpmConfig {
|
|
11
|
-
constructor({ projectDir, scope, region, source } = {}) {
|
|
12
|
-
this.config = {
|
|
13
|
-
scope: scope !== null && scope !== void 0 ? scope : DEFAULT_PACKAGE_SCOPE,
|
|
14
|
-
authToken: '',
|
|
15
|
-
refreshToken: '',
|
|
16
|
-
registryUrl: '',
|
|
17
|
-
region,
|
|
18
|
-
source: source !== null && source !== void 0 ? source : DEFAULT_BUSINESS_SOURCE,
|
|
19
|
-
};
|
|
20
|
-
const dir = projectDir !== null && projectDir !== void 0 ? projectDir : process.cwd();
|
|
21
|
-
this.proxy = new Config({
|
|
22
|
-
npmPath: dir,
|
|
23
|
-
definitions,
|
|
24
|
-
shorthands,
|
|
25
|
-
flatten,
|
|
26
|
-
cwd: dir,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
get registryScope() {
|
|
30
|
-
return `@${this.config.scope}:registry`;
|
|
31
|
-
}
|
|
32
|
-
get registryUrl() {
|
|
33
|
-
const registryHost = REGISTRY_HOST[this.region];
|
|
34
|
-
return isLocalDev(this.region)
|
|
35
|
-
? `http://${registryHost}/`
|
|
36
|
-
: `https://${registryHost}/`;
|
|
37
|
-
}
|
|
38
|
-
get registryAuthUrl() {
|
|
39
|
-
const registryHost = REGISTRY_HOST[this.region];
|
|
40
|
-
return `//${registryHost}/:_authToken`;
|
|
41
|
-
}
|
|
42
|
-
get refreshKey() {
|
|
43
|
-
return `${this.config.source}_${REFRESH_TOKEN_KEY}`;
|
|
44
|
-
}
|
|
45
|
-
get region() {
|
|
46
|
-
// has specified region
|
|
47
|
-
if (this.config.region) {
|
|
48
|
-
return this.config.region;
|
|
49
|
-
}
|
|
50
|
-
const registry = this.proxy.get(this.registryScope);
|
|
51
|
-
if (!registry) {
|
|
52
|
-
return DEFAULT_REGION;
|
|
53
|
-
}
|
|
54
|
-
const registryHost = new URL(registry).host;
|
|
55
|
-
for (const [region, host] of Object.entries(REGISTRY_HOST)) {
|
|
56
|
-
if (registryHost === host) {
|
|
57
|
-
return region;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return DEFAULT_REGION;
|
|
61
|
-
}
|
|
62
|
-
async loadConfig() {
|
|
63
|
-
var _a;
|
|
64
|
-
if (this.proxy.loaded) {
|
|
65
|
-
return this.config;
|
|
66
|
-
}
|
|
67
|
-
await this.proxy.load();
|
|
68
|
-
const token = (_a = this.proxy.get(this.registryAuthUrl, CONFIG_TYPE)) !== null && _a !== void 0 ? _a : '';
|
|
69
|
-
Object.assign(this.config, {
|
|
70
|
-
region: this.region,
|
|
71
|
-
registryUrl: this.proxy.get(this.registryScope) || this.registryUrl,
|
|
72
|
-
authToken: token,
|
|
73
|
-
refreshToken: this.proxy.get(this.refreshKey, CONFIG_TYPE) || '',
|
|
74
|
-
});
|
|
75
|
-
return this.config;
|
|
76
|
-
}
|
|
77
|
-
async storeToken(tokenSet) {
|
|
78
|
-
// clear other region info
|
|
79
|
-
for (const [region] of Object.entries(REGISTRY_HOST)) {
|
|
80
|
-
if (region !== this.region) {
|
|
81
|
-
this.proxy.delete(this.registryScope, CONFIG_TYPE);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
this.proxy.set(this.registryScope, this.registryUrl, CONFIG_TYPE);
|
|
85
|
-
this.proxy.set(this.registryAuthUrl, `${this.config.source}:${tokenSet.access_token || ''}`, CONFIG_TYPE);
|
|
86
|
-
this.proxy.set(this.refreshKey, tokenSet.refresh_token || '', CONFIG_TYPE);
|
|
87
|
-
await this.proxy.save(CONFIG_TYPE);
|
|
88
|
-
Object.assign(this.config, {
|
|
89
|
-
authToken: tokenSet.access_token,
|
|
90
|
-
refreshToken: tokenSet.refresh_token,
|
|
91
|
-
});
|
|
92
|
-
logger.success(`token saved for registry: ${this.registryUrl}`);
|
|
93
|
-
}
|
|
94
|
-
async clearToken() {
|
|
95
|
-
this.proxy.delete(this.registryScope, CONFIG_TYPE);
|
|
96
|
-
this.proxy.delete(this.registryAuthUrl, CONFIG_TYPE);
|
|
97
|
-
this.proxy.delete(this.refreshKey, CONFIG_TYPE);
|
|
98
|
-
await this.proxy.save(CONFIG_TYPE);
|
|
99
|
-
Object.assign(this.config, {
|
|
100
|
-
authToken: '',
|
|
101
|
-
refreshToken: '',
|
|
102
|
-
});
|
|
103
|
-
logger.success(`token cleared for registry: ${this.registryUrl}`);
|
|
104
|
-
}
|
|
105
|
-
getProxy() {
|
|
106
|
-
return this.proxy;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=npm.js.map
|