-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gulpfile.js
159 lines (135 loc) · 5.43 KB
/
Gulpfile.js
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
var gulp = require('gulp');
var exec = require('child_process').exec;
var minimist = require('minimist');
var semver = require('semver');
var fs = require('fs');
var glob = require('glob');
// Default version data. Should be replaced as soon as the get-version task runs.
var version = {
"Major": 0,
"Minor": 0,
"Patch": 1,
"MajorMinorPatch": "0.0.1",
};
var args = minimist(process.argv);
var channelsContent = fs.readFileSync('channels.json', 'utf8');
var channels = JSON.parse(channelsContent);
if (args.channel) {
var channel = channels[args.channel];
} else {
var channel = channels['default'];
}
console.log('Selected Channel is: ' + channel.id);
gulp.task('get-version', function (callback) {
if (args.overrideversion && semver.valid(args.overrideversion)) {
console.log("Using override to get version numbers.");
version.MajorMinorPatch = args.overrideversion;
version.Major = semver.major(args.overrideversion);
version.Minor = semver.minor(args.overrideversion);
version.Patch = semver.patch(args.overrideversion);
callback();
} else if (process.env.GITVERSION_MajorMinorPatch) {
console.log("Environment variables to get version numbers.");
version.MajorMinorPatch = process.env.GITVERSION_MajorMinorPatch;
version.Major = semver.major(process.env.GITVERSION_MajorMinorPatch);
version.Minor = semver.minor(process.env.GITVERSION_MajorMinorPatch);
version.Patch = semver.patch(process.env.GITVERSION_MajorMinorPatch);
callback();
} else {
console.log("Running GitVersion to get version numbers.");
exec('gitversion', function(err, stdout, stderr) {
version = JSON.parse(stdout);
callback(err);
});
}
});
function stampTaskJson(path, taskName) {
var taskDefinitionContents = fs.readFileSync(path, 'utf8');
var taskDefinition = JSON.parse(taskDefinitionContents);
var channelTaskSetup = channel.tasks[taskName]
taskDefinition.id = channelTaskSetup.id;
taskDefinition.name = channelTaskSetup.name;
taskDefinition.friendlyName = channelTaskSetup.friendlyName;
taskDefinition.version = {
"Major": version.Major,
"Minor": version.Minor,
"Patch": version.Patch
};
taskDefinitionContents = JSON.stringify(taskDefinition, null, '\t');
fs.writeFileSync(path, taskDefinitionContents);
}
gulp.task('stamp-manifest', ['get-version'], function (callback) {
var manifestContents = fs.readFileSync('src\\vss-extension.json', 'utf8');
var manifest = JSON.parse(manifestContents);
manifest.id = channel.id;
manifest.name = channel.name;
manifest.version = version.MajorMinorPatch;
manifestContents = JSON.stringify(manifest, null, '\t');
fs.writeFileSync('src\\vss-extension.json', manifestContents);
callback();
});
gulp.task('stamp-export-solution-task', ['get-version'], function (callback) {
stampTaskJson('src\\tasks\\vsts-mscrm-export-solution\\task.json', 'vsts-mscrm-export-solution');
callback();
});
gulp.task('stamp-import-solution-task', ['get-version'], function (callback) {
stampTaskJson('src\\tasks\\vsts-mscrm-import-solution\\task.json', 'vsts-mscrm-import-solution');
callback();
});
gulp.task('stamp-pack-solution-task', ['get-version'], function (callback) {
stampTaskJson('src\\tasks\\vsts-mscrm-pack-solution\\task.json', 'vsts-mscrm-pack-solution');
callback();
});
gulp.task('stamp-extract-solution-task', ['get-version'], function (callback) {
stampTaskJson('src\\tasks\\vsts-mscrm-extract-solution\\task.json', 'vsts-mscrm-extract-solution');
callback();
});
gulp.task('stamp', ['stamp-manifest', 'stamp-export-solution-task', 'stamp-import-solution-task', 'stamp-pack-solution-task', 'stamp-extract-solution-task'], function(callback) {
callback();
});
gulp.task('pack', ['stamp'], function (callback) {
exec('node_modules\\.bin\\tfx.cmd extension create --root src', function (err, stdout, stderr) {
if (err) {
console.log(stderr);
callback(err);
} else {
console.log(stdout);
callback();
}
});
});
gulp.task('publish', function (callback) {
var globPattern = '**/readify.' + channel.id + '-*.vsix';
glob(globPattern, function (err, files) {
var vsix = files[0];
var token = args.token;
exec('node_modules\\.bin\\tfx.cmd extension publish --vsix ' + vsix + ' --token ' + token, function (err, stdout, stderr) {
if (err) {
console.log(stderr);
callback(err);
} else {
console.log(stdout);
callback();
}
});
});
});
gulp.task('share', function (callback) {
var globPattern = '**/readify.' + channel.id + '-*.vsix';
glob(globPattern, function (err, files) {
var vsix = files[0];
var publisher = args.publisher;
var token = args.token;
var sharewith = args.sharewith;
exec('node_modules\\.bin\\tfx.cmd extension share --publisher ' + publisher + ' --vsix ' + vsix + ' --token ' + token + ' --share-with ' + sharewith, function (err, stdout, stderr) {
if (err) {
console.log(stderr);
callback(err);
} else {
console.log(stdout);
callback();
}
});
});
});
gulp.task('default', ['pack']);