-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
101 lines (82 loc) · 2.72 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
/* jshint node: true */
'use strict';
var DeployPluginBase = require('ember-cli-deploy-plugin');
var RSVP = require('rsvp');
var exec = require('child_process').exec;
var glob = require('glob');
var nodeModulesPath = require('node-modules-path');
var path = require('path');
var fs = require('fs');
var getDisabledPluginsMap = function(context) {
if (context && context.config && context.config.pipeline) {
return context.config.pipeline.disabled;
}
return {};
};
var userHasDisabledBuildPlugin = function(context) {
return getDisabledPluginsMap(context).build;
};
module.exports = {
name: 'ember-cli-deploy-create-react-app',
createDeployPlugin: function(options) {
var Plugin = DeployPluginBase.extend({
name: options.name,
requiredConfig: ['publicURL'],
defaultConfig: {},
configure: function(context) {
this.warnIfBuildPluginNotDisabled(context);
},
warnIfBuildPluginNotDisabled(context) {
if (userHasDisabledBuildPlugin(context)) {
return;
}
var modulesPath = nodeModulesPath(process.cwd());
var buildPluginPath = path.join(modulesPath, 'ember-cli-deploy-build');
if (fs.existsSync(buildPluginPath)) {
this.warn('The ember build plugin must be disabled.');
this.warn('Add the following to your config/deploy.js file:');
this.warn('```', {color: 'red'});
this.logCode('ENV.pipeline = {');
this.logCode(' disabled: {');
this.logCode(' build: true');
this.logCode(' }');
this.logCode('};');
this.warn('```', {color: 'red'});
}
},
warn(message) {
this.log(message, {color: 'red'});
},
logCode(message) {
this.log(message, {color: 'green'});
},
build: function(context) {
var self = this;
var options = {};
return new RSVP.Promise(function(resolve, reject) {
const buildProcess = exec('PUBLIC_URL=' + self.readConfig('publicURL') + ' yarnpkg run build', options, function(error, stdout, stderr) {
if (error) {
reject(error);
return;
}
var files = glob.sync('**/**/*', {cwd: 'build'});
if (files && files.length) {
files.forEach(function(path) {
self.log('✔ ' + path, { verbose: true });
});
} else {
self.log('No files :(');
}
resolve({
distDir: 'build',
distFiles: files
});
});
buildProcess.stdout.pipe(process.stdout);
buildProcess.stderr.pipe(process.stderr);
})
}
});
return new Plugin();
}
};