-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (62 loc) · 2.16 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
/*eslint-env node*/
/* global Promise */
'use strict';
const glob = require('glob');
const util = require('util');
const path = require('path');
const execFile = util.promisify(require('child_process').execFile);
const fs = require('fs');
//const RSVP = require('rsvp');
const DeployPluginBase = require('ember-cli-deploy-plugin');
module.exports = {
name: 'ember-cli-deploy-clasp',
createDeployPlugin: function(options) {
let DeployPlugin = DeployPluginBase.extend({
name: options.name,
/*
* Define any config validation here
*
* http://ember-cli-deploy.com/docs/v1.0.x/creating-a-plugin/#validating-plugin-config
*/
defaultConfig: {
distDir: function(context) {
return context.distDir;
}
},
requiredConfig: ['distDir'],
/*
* Implement any pipeline hooks here
*
* http://ember-cli-deploy.com/docs/v1.0.x/pipeline-hooks/
*/
upload(/*context*/) {
var distDir = this.readConfig('distDir');
var claspConfigFiles = glob.sync(`${distDir}/**/.clasp.json`);
var promises = [];
claspConfigFiles.forEach((configFile) => {
var claspProjectDir = path.dirname(configFile);
process.chdir(claspProjectDir);
this.log(`Running \`clasp push\` and \`clasp version\` in ${claspProjectDir}`);
var claspPromise = execFile('clasp', ['push', '-f']).then(({ stdout , stderr }) => {
this.log(stdout);
this.log(stderr);
if (stderr && stderr.includes('Push failed')) {
throw new Error(stderr);
}
}).then(() => execFile('clasp', ['version', '"Pushed by ember-cli-deploy-clasp"']).then(({ stdout , stderr }) => {
this.log(stdout);
this.log(stderr);
})).then(() => {
if (fs.existsSync('.upload-message')) {
var uploadMessage = fs.readFileSync('.upload-message', 'utf8');
this.log(`\x1b[33m${uploadMessage}\x1b[0m`);
}
});
promises.push(claspPromise);
});
return Promise.all(promises);
}
});
return new DeployPlugin();
}
};