Skip to content

Commit 50107ca

Browse files
piaolingxueReplicate Test Bot
andauthored
Feature/support local registry (#115)
* supoort local registry Signed-off-by: Replicate Test Bot <noreply@replicate.com> * supoort local registry Signed-off-by: Replicate Test Bot <noreply@replicate.com> * support custom template uri Signed-off-by: Replicate Test Bot <noreply@replicate.com> --------- Signed-off-by: Replicate Test Bot <noreply@replicate.com> Co-authored-by: Replicate Test Bot <noreply@replicate.com>
1 parent 746ab84 commit 50107ca

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

src/common/load/loadApplication.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface IParams {
3939
parameters?: object; // s.yaml文件接收的入参
4040
appName?: string; // s.yaml文件里的项目名称
4141
access?: string; // s.yaml文件里的密钥
42+
uri?: string; // 自定义应用模板地址
4243
}
4344

4445
async function preInit({ temporaryPath, applicationPath }) {
@@ -68,15 +69,23 @@ class LoadApplication {
6869
constructor(config: IParams) {
6970
this.config = config;
7071
}
71-
async byUrl() {
72-
const { source, registry, target } = this.config;
72+
async byUri() {
73+
const { source, uri, target } = this.config;
7374
const applicationPath = path.resolve(target, source);
7475
return this.handleDecompressFile({
75-
zipball_url: registry,
76+
template_uri: uri,
7677
applicationPath,
7778
name: this.config.name,
7879
});
7980
}
81+
async byUrl() {
82+
const { source, registry, target } = this.config;
83+
const applicationPath = path.resolve(target, source);
84+
await downloadRequest(registry, applicationPath, {
85+
extract: true,
86+
});
87+
return applicationPath;
88+
}
8089
async loadType() {
8190
const { registry } = this.config;
8291
if (registry === RegistryEnum.serverless || registry === RegistryEnum.serverlessOld) {
@@ -109,7 +118,7 @@ class LoadApplication {
109118
const newName = this.config.name || name;
110119
const applicationPath = path.resolve(this.config.target, newName);
111120
return this.handleDecompressFile({
112-
zipball_url,
121+
template_uri: zipball_url,
113122
applicationPath,
114123
name: newName,
115124
});
@@ -133,17 +142,17 @@ class LoadApplication {
133142
const newName = this.config.name || name;
134143
const applicationPath = path.join(this.config.target, newName);
135144
return this.handleDecompressFile({
136-
zipball_url,
145+
template_uri: zipball_url,
137146
applicationPath,
138147
name: newName,
139148
});
140149
}
141-
async handleDecompressFile({ zipball_url, applicationPath, name }) {
150+
async handleDecompressFile({ template_uri, applicationPath, name }) {
142151
const answer = await this.checkFileExists(applicationPath, name);
143152
if (!answer) return applicationPath;
144153
const temporaryPath = `${applicationPath}${new Date().getTime()}`;
145154
this.temporaryPath = temporaryPath;
146-
await downloadRequest(zipball_url, temporaryPath, {
155+
await downloadRequest(template_uri, temporaryPath, {
147156
extract: true,
148157
strip: 1,
149158
});
@@ -440,16 +449,19 @@ async function loadApplication(
440449
config.parameters = oldsource.parameters;
441450
config.appName = oldsource.appName;
442451
config.access = oldsource.access;
452+
config.uri = oldsource.uri;
443453
}
444454

445455
const instance = new LoadApplication(config);
446456

457+
if (config.uri) {
458+
// 支持 自定义
459+
return await instance.byUri();
460+
}
447461
if (config.registry) {
448462
if (config.registry !== RegistryEnum.github && config.registry !== RegistryEnum.serverless) {
449463
// 支持 自定义
450-
let res = await instance.byUrl();
451-
setConfigYaml('registry', RegistryEnum.serverless)
452-
return res;
464+
return await instance.byUrl();
453465
}
454466
}
455467
let appPath: string;

0 commit comments

Comments
 (0)