-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
110 lines (87 loc) · 5.77 KB
/
index.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
'use strict';
var _ = require('lodash'),
gulp = require('gulp'),
gutil = require('gulp-util'),
fileExists = require('file-exists'),
file = require('gulp-file'),
Q = require('Q');
var spawn = require('child_process').spawn;
var PLUGIN_NAME = 'config-transform';
function setup(options) {
if (!options.msBuildPath) {
if (options.netVersion != '4' && options.netVersion != '2')
throw new gutil.PluginError(PLUGIN_NAME, 'Option "netVersion" is required and must be "2" or "4".');
if (options.framework != 'x64' && options.netVersion != 'x86')
throw new gutil.PluginError(PLUGIN_NAME, 'Option "framework" is required and must be "x86" or "x64".');
if (options.netVersion == 4) {
if (options.framework == 'x64') {
options.msBuildPath = 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\msbuild.exe'
} else if (options.framework == 'x86') {
options.msBuildPath = 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe'
}
} else if (options.netVersion == 2) {
if (options.framework == 'x64') {
options.msBuildPath = 'C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\msbuild.exe'
} else if (options.framework == 'x86') {
options.msBuildPath = 'C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\msbuild.exe'
}
}
}
if (!fileExists(options.msBuildPath))
throw new gutil.PluginError(PLUGIN_NAME, 'MSBuild at path: "' + options.msBuildPath + '" does not exist.');
if (!options.assemblyFile) {
if (fileExists('C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v10.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v10.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v14.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v14.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files)\\MSBuild\\Microsoft\\VisualStudio\\v10.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v10.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v14.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v14.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else if (fileExists('C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\Web\\Microsoft.Web.Publishing.Tasks.dll'))
options.assemblyFile = 'C:\\Program Files\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\Web\\Microsoft.Web.Publishing.Tasks.dll';
else
throw new gutil.PluginError(PLUGIN_NAME, 'Cannot find "assemblyFile" does not exist. Please specify the path of the "Microsoft.Web.Publishing.Tasks.dll" file.');
} else if (!fileExists(options.assemblyFile))
throw new gutil.PluginError(PLUGIN_NAME, 'AssemblyFile at path: "' + options.assemblyFile + '" does not exist.');
if (!fileExists(options.config))
throw new gutil.PluginError(PLUGIN_NAME, 'Web.config at path: "' + options.config + '" does not exist.');
if (!fileExists(options.transform))
throw new gutil.PluginError(PLUGIN_NAME, 'Transform file at path: "' + options.transform + '" does not exist.');
}
function createProj(options) {
var deferred = Q.defer();
var _project = '<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><UsingTask TaskName="TransformXml" AssemblyFile="{assemblyFile}"/><Target Name="Transform"><TransformXml Source="{source}" Transform="{transform}" Destination="{destination}"/></Target></Project>';
_project = _project.replace('{assemblyFile}', options.assemblyFile)
.replace('{source}', options.config)
.replace('{transform}', options.transform)
.replace('{destination}', options.destination);
file('_msbuild.proj', _project, { src: true })
.pipe(gulp.dest('.'))
.on('end', function() {
deferred.resolve();
});
return deferred.promise;
}
function transform(options) {
var _options = _.extend({
config: './web.config',
transform: 'web.Debug.Config',
destination: './wwwroot/web.config',
netVersion: '4',
framework: 'x64',
msBuildPath: undefined,
assemblyFile: undefined
}, options);
setup(_options);
return createProj(_options).then(function() {
spawn(_options.msBuildPath, ['./_msbuild.proj', '/t:Transform'], {stdio: 'inherit'});
}).done();
}
module.exports = transform;