This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
package.js
101 lines (84 loc) · 3.28 KB
/
package.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
var through = require('through2');
var gutil = require('gulp-util');
var path = require('path');
var fs = require('fs-extra');
var check = require('validator');
var shell = require('shelljs');
var Q = require('q');
var os = require('os');
var cp = require('child_process');
var createError = function(msg) {
return new gutil.PluginError('PackageTask', msg);
}
var validateTask = function(folderName, task) {
var defer = Q.defer();
var vn = (task.name || folderName);
if (!task.id || !check.isUUID(task.id)) {
defer.reject(createError(vn + ': id is a required guid'));
};
if (!task.name || !check.isAlphanumeric(task.name)) {
defer.reject(createError(vn + ': name is a required alphanumeric string'));
}
if (!task.friendlyName || !check.isLength(task.friendlyName, 1, 40)) {
defer.reject(createError(vn + ': friendlyName is a required string <= 40 chars'));
}
if (!task.instanceNameFormat) {
defer.reject(createError(vn + ': instanceNameFormat is required'));
}
// resolve if not already rejected
defer.resolve();
return defer.promise;
};
function copyCommonModules(currentExtnRoot, commonDeps, commonSrc){
return through.obj(
function(taskJson, encoding, done) {
if (!fs.existsSync(taskJson)) {
new gutil.PluginError('PackageTask', 'Task json cannot be found: ' + taskJson.path);
}
if (taskJson.isNull() || taskJson.isDirectory()) {
this.push(taskJson);
return callback();
}
var taskDirPath = path.dirname(taskJson.path);
var folderName = path.basename(taskDirPath);
var jsonContents = taskJson.contents.toString();
var task = {};
try {
task = JSON.parse(jsonContents);
}
catch (err) {
done(createError(folderName + ' parse error: ' + err.message));
return;
}
var targetPath;
validateTask(folderName, task)
.then(function() {
// Copy the task to the layout folder.
targetPath = path.join(currentExtnRoot, "Src", "Tasks", task.name);
shell.mkdir('-p', targetPath);
shell.rm(path.join(targetPath, '*.csproj'));
shell.rm(path.join(targetPath, '*.md'));
// Statically link the required internal common modules.
var taskDeps;
if ((taskDeps = commonDeps[task.name])) {
taskDeps.forEach(function (dep) {
gutil.log('Linking ' + dep.module + ' into ' + task.name);
var src = path.join(commonSrc, dep.module, "Src/");
var dest = path.join(targetPath, dep.dest);
shell.mkdir('-p', dest);
fs.copy(src, dest, "*", function (err) {
if (err) return console.error(err)
})
})
}
return;
})
.then(function() {
done();
})
.fail(function(err) {
done(err);
})
});
}
exports.copyCommonModules = copyCommonModules;