-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
executable file
·133 lines (106 loc) · 4.36 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
"use strict";
var fs = require('fs'),
path = require('path'),
gulp = require('gulp'),
gutil = require('gulp-util'),
nForceDeployer = require('./bin/build/nForceDeployer'),
nforce = require('nforce');
// load the nforce-metadata plugin
require('nforce-metadata')(nforce);
require('gulp-force-developer').registerForGulp(gulp, gutil);
// ----------------------------------------------------------------
// Read configuration from package.json (if possible).
const packageFile = './package.json';
var sfdcEnvironment_DEV = {},
sfdcEnvironment_TEST = {},
sfdcForceDeveloperConfig = {};
if (fs.existsSync(packageFile) === true) {
var config = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
if (config.sfdcEnvironment !== undefined) {
if (config.sfdcEnvironment.development !== undefined)
sfdcEnvironment_DEV = config.sfdcEnvironment.development;
if (config.sfdcEnvironment.test !== undefined)
sfdcEnvironment_TEST = config.sfdcEnvironment.test;
}
if (config.forceDeveloperConfig !== undefined)
sfdcForceDeveloperConfig = config.forceDeveloperConfig;
}
// ----------------------------------------------------------------
const defaultOutputPackageZip = './.package/package.zip',
defaultRedirectUri = 'http://localhost:3000/oauth/_callback';
var salesforcePackageFile = process.env.SFDC_PACKAGEFILE || sfdcForceDeveloperConfig.outputPackageZip || defaultOutputPackageZip,
oauthRedirectUri_TEST = process.env.SFDC_TEST_OAUTH_REDIRECTURI || sfdcEnvironment_TEST.redirectUri || defaultRedirectUri,
oauthClientId_TEST = process.env.SFDC_TEST_OAUTH_CLIENTID || sfdcEnvironment_TEST.oauthClientId,
oauthSecretId_TEST = process.env.SFDC_TEST_OAUTH_SECRETID || sfdcEnvironment_TEST.oauthSecretId,
username_TEST = process.env.SFDC_TEST_USERNAME || sfdcEnvironment_TEST.username,
password_TEST = process.env.SFDC_TEST_PASSWORD || sfdcEnvironment_TEST.password,
token_TEST = process.env.SFDC_TEST_TOKEN || sfdcEnvironment_TEST.token,
oauthRedirectUri_DEV = process.env.SFDC_DEV_OAUTH_REDIRECTURI || sfdcEnvironment_DEV.redirectUri || defaultRedirectUri,
oauthClientId_DEV = process.env.SFDC_DEV_OAUTH_CLIENTID || sfdcEnvironment_DEV.oauthClientId,
oauthSecretId_DEV = process.env.SFDC_DEV_OAUTH_SECRETID || sfdcEnvironment_DEV.oauthSecretId,
username_DEV = process.env.SFDC_DEV_USERNAME || sfdcEnvironment_DEV.username,
password_DEV = process.env.SFDC_DEV_PASSWORD || sfdcEnvironment_DEV.password,
token_DEV = process.env.SFDC_DEV_TOKEN || sfdcEnvironment_DEV.token;
/// TODO: Add validation.
// ----------------------------------------------------------------
// REGISTER GULP TASKS
gulp.task('nforce-deploy-test', function() {
var org = nforce.createConnection({
clientId: oauthClientId_TEST,
clientSecret: oauthSecretId_TEST,
redirectUri: oauthRedirectUri_TEST,
username: username_TEST,
password: password_TEST,
securityToken: token_TEST,
metaOpts: { // options for nforce-metadata
interval: 2000 // poll interval can be specified (optional)
},
plugins: ['meta'] // loads the plugin in this connection
});
return nForceDeployer.executeAllTests(org, path.resolve(salesforcePackageFile));
});
gulp.task('nforce-deploy', function() {
var org = nforce.createConnection({
clientId: oauthClientId_DEV,
clientSecret: oauthSecretId_DEV,
redirectUri: oauthRedirectUri_DEV,
username: username_DEV,
password: password_DEV,
securityToken: token_DEV,
metaOpts: { // options for nforce-metadata
interval: 2000 // poll interval can be specified (optional)
},
plugins: ['meta'] // loads the plugin in this connection
});
return nForceDeployer.deploy(org, path.resolve(salesforcePackageFile));
});
// Deploys the most recent changes to DEV
gulp.task('default', gulp.series(
'force-package-config',
'force-package',
'force-zip',
'nforce-deploy',
'force-commit'
));
// Deploys the full package to DEV
gulp.task('deploy-all', gulp.series(
'force-package-config',
'force-package-all',
'force-zip',
'nforce-deploy',
'force-commit'
));
// Clears the filechange cache
gulp.task('reset', gulp.series(
'force-reset'
));
// Execute a full test against the TEST instance.
// - Does not commit any changes.
gulp.task('test', gulp.series(
'force-package-config',
'force-package-all',
'force-zip',
'nforce-deploy-test'
));
// Ensures a failure result code is returned on error.
gulp.on('error', process.exit.bind(process, 1));