-
Notifications
You must be signed in to change notification settings - Fork 2
/
taskfile.ts
184 lines (176 loc) · 8.73 KB
/
taskfile.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { Workflow, Task, Activities, isAcitvityClass, Activity, EachTeamplate, ActivityTemplate } from '@tsdi/activities';
import * as path from 'path';
import { PackModule, NodeActivityContext, ShellActivityOption, JsonReplaceActivityOption } from '@tsdi/pack';
import { Type, isString } from '@tsdi/ioc';
import { ServerActivitiesModule } from '@tsdi/platform-server-activities';
import * as through from 'through2';
// build with command `tsdi build --setvs=version --deploy`
@Task({
deps: [
PackModule,
ServerActivitiesModule
],
baseURL: __dirname,
template: <ActivityTemplate>[
{
activity: Activities.if,
condition: (ctx: NodeActivityContext) => {
let unp = ctx.platform.getEnvArgs().unp;
return isString(unp) && /\d+.\d+.\d+/.test(unp);
},
body: <ShellActivityOption>{
activity: 'shell',
shell: (ctx: NodeActivityContext) => {
let packages = ctx.platform.getFolders('packages').filter(f => !/(orm|simples)$/.test(f));
let version = ctx.platform.getEnvArgs().unp;
let cmds = [];
packages.forEach(fd => {
let objs = require(path.join(fd, 'package.json'));
if (objs && objs.name) {
cmds.push(`npm unpublish ${objs.name}@${version}`)
}
});
console.log(cmds);
return cmds;
}
}
},
{
activity: Activities.elseif,
condition: (ctx: NodeActivityContext) => ctx.platform.getEnvArgs().build !== 'false',
body: [
{
activity: Activities.if,
condition: (ctx: NodeActivityContext) => ctx.platform.getEnvArgs().setvs,
body: [{
activity: 'asset',
name: 'version-setting',
src: 'packages/**/package.json',
dist: 'packages',
pipes: [
<JsonReplaceActivityOption>{
activity: 'jsonReplace',
fields: (json, ctx) => {
let chgs = new Map<string, any>();
let version = ctx.platform.getEnvArgs().setvs;
chgs.set('version', version);
let iocVersion: string = ctx.platform.getPackage().devDependencies['@tsdi/ioc'];
iocVersion = iocVersion.replace(/^(\^|=|~)/ig, '');
Object.keys(json.peerDependencies || {}).forEach(key => {
if (/^@mvx/.test(key)) {
chgs.set('peerDependencies.' + key, '~' + version);
}
});
Object.keys(json.dependencies || {}).forEach(key => {
if (/^@mvx/.test(key)) {
chgs.set('dependencies.' + key, '~' + version);
}
});
Object.keys(json.devDependencies || {}).forEach(key => {
if (/^@mvx/.test(key)) {
chgs.set('devDependencies.' + key, '~' + version);
}
});
Object.keys(json.peerDependencies || {}).forEach(key => {
if (/^@tsdi/.test(key)) {
chgs.set('peerDependencies.' + key, '~' + iocVersion);
}
});
Object.keys(json.dependencies || {}).forEach(key => {
if (/^@tsdi/.test(key)) {
chgs.set('dependencies.' + key, '~' + iocVersion);
}
});
Object.keys(json.devDependencies || {}).forEach(key => {
if (/^@tsdi/.test(key)) {
chgs.set('devDependencies.' + key, '~' + iocVersion);
}
});
return chgs;
}
}]
},
{
activity: 'asset',
src: 'package.json',
dist: '.',
pipes: [
<JsonReplaceActivityOption>{
activity: 'jsonReplace',
fields: (json, ctx) => {
let version = ctx.platform.getEnvArgs().setvs;
return { version: version };
}
}]
}]
},
{
activity: 'shell',
parallel: true,
shell: (ctx: NodeActivityContext) => {
let pks = ctx.platform.getFolders('packages').filter(f => !/(orm|identity-server|simples|package)$/.test(f))
return pks.map(p => `cd ${p} && tsdi build`);
}
},
{
activity: 'asset',
src: 'dist/**/*.d.ts',
pipes: [
() => through.obj(function (file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
return callback('doesn\'t support Streams');
}
let contents: string = file.contents.toString('utf8');
let sets: string[] = [];
contents = contents.replace(/set\s\w+\(.+\)\;/g, match => {
sets.push(match.substring(4, match.indexOf('(')));
return '';
});
contents = contents.replace(/get\s\w+\(\)\:\s/g, match => {
let field = match.substring(4, match.length - 4);
return `${sets.indexOf(field) >= 0 ? '' : 'readonly '}${field}:`;
});
file.contents = Buffer.from(contents);
callback(null, file);
})
],
dist: 'dist'
}
// <EachTeamplate>{
// activity: Activities.each,
// each: (ctx: NodeActivityContext) => ctx.platform.getFolders('packages').filter(f => !/(cli|orm|identity-server|simples)$/.test(f)),
// parallel: true,
// body: {
// activity: Activities.execute,
// action: async (ctx) => {
// let activitys = Object.values(require(path.join(ctx.body, 'taskfile.ts'))).filter(b => isAcitvityClass(b)) as Type<Activity<any>>[];
// // await ctx.getExector().execActivity(ctx, activitys);
// await Workflow.sequence(...activitys);
// }
// }
// }
]
},
{
activity: Activities.if,
condition: (ctx: NodeActivityContext) => ctx.platform.getEnvArgs().deploy,
body: <ShellActivityOption>{
activity: 'shell',
shell: (ctx: NodeActivityContext) => {
let packages = ctx.platform.getFolders('dist');
let cmd = 'npm publish --access=public'; // envArgs.deploy ? 'npm publish --access=public' : 'npm run build';
let shells = packages.map(fd => {
return `cd ${fd} && ${cmd}`;
});
console.log(shells);
return shells;
}
}
}
]
})
export class BuilderMVX {
}