-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskfile.ts
156 lines (150 loc) · 6.82 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
import { Type, isString, lang } from '@tsdi/ioc';
import { Workflow, Task, Activities, isAcitvityClass, Activity } from '@tsdi/activities';
import * as path from 'path';
import { PackModule, NodeActivityContext, JsonReplaceActivityOption } from '@tsdi/pack';
import { ServerActivitiesModule } from '@tsdi/platform-server-activities';
import * as through from 'through2';
@Task({
deps: [
PackModule,
ServerActivitiesModule
],
baseURL: __dirname,
template: [
{
activity: 'if',
condition: (ctx: NodeActivityContext) => {
let unp = ctx.platform.getEnvArgs().unp;
return isString(unp) && /\d+.\d+.\d+/.test(unp);
},
body: {
activity: 'shell',
shell: (ctx: NodeActivityContext) => {
let packages = ctx.platform.getFolders('packages');
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: 'elseif',
condition: (ctx: NodeActivityContext) => ctx.platform.getEnvArgs().build !== 'false',
body: [
{
activity: 'if',
// condition: {
// activity: 'exists',
// expect: `ctx.platform.getEnvArgs().setvs`
// },
condition: `!!ctx.platform.getEnvArgs().setvs`,
// 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);
Object.keys(json.peerDependencies || {}).forEach(key => {
if (/^@tsdi/.test(key)) {
chgs.set('peerDependencies.' + key, '~' + version);
}
});
Object.keys(json.dependencies || {}).forEach(key => {
if (/^@tsdi/.test(key)) {
chgs.set('dependencies.' + key, '~' + version);
}
});
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: 'each',
each: (ctx: NodeActivityContext) => ctx.platform.getFolders('packages').filter(f => !f.endsWith('component') && !f.endsWith('unit-karma')),
// parallel: true,
body: {
activity: 'execute',
action: async (ctx) => {
let activitys = Object.values(require(path.join(ctx.getInput(), 'taskfile.ts'))).filter(b => isAcitvityClass(b)) as Type<Activity<any>>[];
// await ctx.getExector().runActivity(ctx, activitys);
await Workflow.run(lang.first(activitys));
}
}
},
{
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'
}
]
},
{
activity: 'if',
condition: (ctx: NodeActivityContext) => ctx.platform.getEnvArgs().deploy,
body: {
activity: 'shell',
shell: (ctx: NodeActivityContext) => {
let packages = ctx.platform.getFolders('dist');
let cmd = 'npm publish --access=public --registry="https://registry.npmjs.org"'; // 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 BuilderTsIoc {
}