rigjs
Version:
A multi-repos dev tool based on yarn and git.Rigjs is intended to be the simplest way to develop,share and deliver codes between different developers or different projects.
152 lines (135 loc) • 3.4 kB
text/typescript
import DirLevel from '@/classes/cicd/DirLevel';
import Endpoint, {EndpointDict} from '@/classes/cicd/Endpoint';
import fs from 'fs';
import qs from 'querystring';
import {redactParamsStr} from '@/utils/redact';
const JSON5 = require('json5');
export enum CloudType {
alicloud = 'alicloud',
}
export enum FrameworkType {
vue = 'vue',
}
/**
* Bundle source
*/
interface DeploySource {
root_path: string
}
/**
* Deploy target
*/
export interface DeployTarget {
id: string;
type: CloudType;
bucket: string;
region: string;
access_key: string;
access_secret: string;
root_path: '/';
bucket_root_path: '/';//equals to root_path
web_entry_path: '/';
uri_rewrite: {
original?: string;
original_regexp?: string;
final?: string;
} | undefined;
/**
* Edge provider for `rig publish` (回源改写 + 刷缓存).
* - 'cdn' (default): traditional Aliyun CDN, BatchSetCdnDomainConfig.
* - 'esa': Aliyun ESA (Edge Security Acceleration), site-scoped rewrite rules.
*/
edge_provider?: 'cdn' | 'esa';
/**
* ESA OpenAPI endpoint. Only used when edge_provider === 'esa'.
* Defaults to 'esa.cn-hangzhou.aliyuncs.com'.
*/
esa_endpoint?: string;
/**
* ESA site name (registrable zone, e.g. 'terncloud.com'). Only used when
* edge_provider === 'esa'. If omitted, derived from the endpoint domain's
* last two labels.
*/
esa_site_name?: string;
}
/**
* @interface DirGroup
* Only dynamic Dirlevel can use DirGroup
*/
export interface DirGroup {
name: string,
/**
* Name in DirLevel,
*/
level: string,
includes: string[],
}
export interface Define {
[replace: string]: String;
}
export interface DefineDict {
[group: string]: Define;
}
/**
* Whole CI/CD config
* @property tree_schema string fafafa
*/
export interface CICDConfig {
/**
* fafafafa
*/
tree_schema: string;
path_schema: string;
web_type: 'hash'|'history'|'mpa';
source: DeploySource;
target: DeployTarget | DeployTarget[];
endpoints: EndpointDict;
groups: DirGroup[];
}
class CICD {
/**
* schema of the directory tree
* @type {string}
*/
treeSchema: string;
web_type: 'hash' | 'history'|'mpa' = 'hash';
/**
* DirLevel shows every level of the directory structure
* @type {DirLevel[]}
*/
schema: DirLevel[];
/**
* endpoints contains build info and deploy info.
* @type {Endpoint[]}
*/
endpoints: Endpoint[];
source: DeploySource;
target: DeployTarget | DeployTarget[];
groups: DirGroup[];
constructor(config: CICDConfig) {
this.treeSchema = config.tree_schema || config.path_schema;
this.web_type = config.web_type || 'hash';
this.schema = DirLevel.createSchema(this.treeSchema);
this.endpoints = Endpoint.createEndpointArr(config, this.schema);
this.source = config.source;
this.target = config.target;
this.groups = config.groups;
}
static createByDefault(cmd: any) {
//replace params
let pkgStr = fs.readFileSync(`${process.cwd()}/package.rig.json5`).toString();
const paramsStr = cmd.params;
console.log('paramsStr', redactParamsStr(paramsStr));
const params = qs.parse(paramsStr);
//替换动态变量
Object.keys(params).forEach(key => {
const regStr = `\\$\\{${key}\\}`;
const regex = new RegExp(regStr, 'g');
pkgStr = pkgStr.replace(regex, params[key] as string);
});
return new CICD(JSON5.parse(pkgStr).cicd);
}
matchEndpoints(cmdDirStrArr: string[]) {
}
}
export default CICD;