-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.ts
141 lines (121 loc) · 3.24 KB
/
gulpfile.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
/*
* SPDX-FileCopyrightText: 2022 Siemens AG
*
* SPDX-License-Identifier: MIT
*/
import { parallel, series } from "gulp";
import del from 'del';
import log from "fancy-log"
import { spawn } from "cross-spawn"
import { execSync } from "child_process";
var semVer: string;
type mode = "development" | "production" | "stage"
interface IExtensionManifestOverride {
version?: string
}
export function clean() {
return del([
'dist/**/*',
'package/**/*'
],
{ force: true }
)
}
export function cleanNpm() {
return del('node_modules/**/*', {force: true})
}
function compile(mode: mode) {
return spawn('npx', ['webpack', '--mode', mode], {stdio: 'inherit'})
}
export function compile_dev() {
return compile("development")
}
export function compile_prod() {
return compile("production")
}
function createPackage(mode: mode) {
let extensionOverride: IExtensionManifestOverride = { version: semVer }
let overrideVersion = JSON.stringify( extensionOverride )
let parameters:string[] = [
"tfx",
"extension",
"create",
"--output-path", "package/",
"--override", overrideVersion,
"--manifest-globs", "azure-devops-extension.json"
]
switch (mode) {
case "development":
parameters.push("src/**/manifest.dev.json", "--overrides-file", "azure-devops-extension-dev.json")
break;
case "stage":
parameters.push("src/**/manifest.stage.json", "--overrides-file", "azure-devops-extension-stage.json")
break;
case "production":
parameters.push("src/**/manifest.json")
break;
default:
log.error(`Unknown mode: "${mode}"`)
break;
}
return spawn('npx', parameters, {stdio: 'inherit'})
}
function createPackageProd() {
return createPackage("production")
}
function createPackageDev() {
return createPackage("development")
}
function createPackageStage() {
return createPackage("stage")
}
export async function version() {
let result;
try {
result = execSync('gitversion', {encoding: "utf-8"});
} catch (error) {
log.error(result)
log.error(error)
return await Promise.reject(error)
}
semVer = JSON.parse(result)?.SemVer
log.info(`SemVer: ${semVer}`)
if(!semVer) {
return await Promise.reject("Failed to calculate SemVer")
}
if(process.env.TF_BUILD) {
log.info(`##vso[task.setvariable variable=SemVer]${semVer}`)
}
return await Promise.resolve()
}
export const stage = series(
parallel(
version,
series(
clean,
compile_dev
)
),
createPackageStage
);
export const dev = series(
parallel(
version,
series(
clean,
compile_dev
)
),
createPackageDev
);
const prod = series(
parallel(
version,
series(
clean,
compile_prod
)
),
createPackageProd
);
export default prod