1
1
/*eslint-env node*/
2
2
'use strict' ;
3
3
4
+ const glob = require ( 'glob' ) ;
5
+ const detectInstalled = require ( 'detect-installed' ) ;
6
+ const util = require ( 'util' ) ;
7
+ const path = require ( 'path' ) ;
8
+ const execFile = util . promisify ( require ( 'child_process' ) . execFile ) ;
9
+
4
10
//const RSVP = require('rsvp');
5
11
const DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
6
12
@@ -28,9 +34,12 @@ module.exports = {
28
34
* http://ember-cli-deploy.com/docs/v1.0.x/pipeline-hooks/
29
35
*/
30
36
31
- //configure(context) {
32
- // let configProp = this.readConfig('foo'); // this is how you access plugin config
33
- //},
37
+ configure ( context ) {
38
+ var claspInstalled = detectInstalled . sync ( 'clasp' ) ;
39
+ if ( ! claspInstalled ) {
40
+ throw new Error ( '@google/clasp must be installed and you must be logged in' ) ;
41
+ }
42
+ } ,
34
43
35
44
//setup(context) {
36
45
// // Return an object with values you'd like merged in to the context to be accessed by other pipeline hooks and plugins
@@ -52,7 +61,20 @@ module.exports = {
52
61
//didPrepare(context) {},
53
62
54
63
//willUpload(context) {},
55
- //upload(context) {},
64
+ upload ( /*context*/ ) {
65
+ var distDir = this . readConfig ( 'distDir' ) ;
66
+ var claspConfigFiles = glob . sync ( `${ distDir } /**/.clasp.json` ) ;
67
+ var promises = [ ] ;
68
+ claspConfigFiles . forEach ( ( configFile ) => {
69
+ var claspProjectDir = path . dirname ( configFile ) ;
70
+ process . chdir ( claspProjectDir ) ;
71
+ var claspPromise = execFile ( 'clasp' , 'push' ) . then ( ( { stdout } /*, stderr*/ ) => {
72
+ this . log ( stdout ) ;
73
+ } ) ;
74
+ promises . push ( claspPromise ) ;
75
+ } ) ;
76
+ return Promise . all ( promises ) ;
77
+ } ,
56
78
//didUpload(context) {},
57
79
58
80
//willActivate(context) {},
0 commit comments