/
ng-add.ts
37 lines (35 loc) 路 1.2 KB
/
ng-add.ts
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
import { chain, Rule, SchematicContext, Tree, SchematicsException } from '@angular-devkit/schematics';
import { NgAddOptions, PluginOptions } from './core/types';
import { getProject } from './core/utils';
import { ngAddQiniu } from './qiniu/ng-add';
import { ngAddUpyun } from './upyun/ng-add';
import { ngAddOSS } from './ali-oss/ng-add';
import { join } from 'path';
export const ngAdd = (options: NgAddOptions): Rule => {
return (tree: Tree, context: SchematicContext) => {
const project = getProject(tree, options.project);
const opt: PluginOptions = {
ngAdd: options,
projectName: project.name,
workspaceSchema: project.workspace,
outputPath: project.outputPath
};
// angular17 will add additional browser
opt.outputPath = join(opt.outputPath, 'browser');
const rules: Rule[] = [];
switch (options.type) {
case 'qiniu':
rules.push(ngAddQiniu(opt));
break;
case 'upyun':
rules.push(ngAddUpyun(opt));
break;
case 'ali-oss':
rules.push(ngAddOSS(opt));
break;
default:
throw new SchematicsException(`Invalid cloud type "${options.type}"`);
}
return chain(rules)(tree, context);
};
};