@@ -4,6 +4,7 @@ import * as glob from 'glob';
44import { task } from 'gulp' ;
55import * as del from 'del' ;
66import * as runSequence from 'run-sequence' ;
7+ import * as s3 from 's3' ;
78import { argv } from 'yargs' ;
89
910
@@ -12,6 +13,9 @@ import { createTempTsConfig, getFolderInfo, runAppScriptsBuild, writePolyfills }
1213
1314import * as pAll from 'p-all' ;
1415
16+ import * as dotenv from 'dotenv' ;
17+ dotenv . config ( ) ;
18+
1519task ( 'demos.prepare' , ( done : Function ) => {
1620 runSequence ( 'demos.clean' , 'demos.polyfill' , 'demos.sass' , ( err : any ) => done ( err ) ) ;
1721} ) ;
@@ -95,9 +99,19 @@ function buildDemo(filePath: string) {
9599 const appNgModulePath = join ( dirname ( filePath ) , 'app.module.ts' ) ;
96100 const distDir = join ( distTestRoot , 'www' ) ;
97101
98- return runAppScriptsBuild ( appEntryPoint , appNgModulePath , ionicAngularDir , distDir , pathToWriteFile , ionicAngularDir , sassConfigPath , copyConfigPath ) . then ( ( ) => {
102+ return runAppScriptsBuild (
103+ appEntryPoint ,
104+ appNgModulePath ,
105+ ionicAngularDir ,
106+ distDir ,
107+ pathToWriteFile ,
108+ ionicAngularDir ,
109+ sassConfigPath ,
110+ copyConfigPath
111+ ) . then ( ( ) => {
99112 const end = Date . now ( ) ;
100113 console . log ( `${ filePath } took a total of ${ ( end - start ) / 1000 } seconds to build` ) ;
114+ uploadToS3 ( pathToWriteFile ) ;
101115 } ) ;
102116}
103117
@@ -112,6 +126,78 @@ function chunkArrayInGroups(arr, size) {
112126 return result ;
113127}
114128
129+ function uploadToS3 ( path ) {
130+ // fail silently if envars not present
131+ if ( ! process . env . AWS_KEY || ! process . env . AWS_SECRET ) {
132+ return new Promise ( ( resolve ) => { resolve ( ) ; } ) ;
133+ }
134+
135+ let client = s3 . createClient ( {
136+ s3Options : {
137+ accessKeyId : process . env . AWS_KEY ,
138+ secretAccessKey : process . env . AWS_SECRET
139+ } ,
140+ } ) ;
141+
142+ // get demo name from path
143+ let demo = path . split ( '/' ) [ path . split ( '/' ) . length - 2 ] ;
144+
145+ let params = {
146+ localDir : path . replace ( 'tsconfig.json' , '' ) ,
147+ deleteRemoved : true ,
148+ s3Params : {
149+ Bucket : "ionic-demos" ,
150+ Prefix : demo ,
151+ } ,
152+ } ;
153+
154+ var uploader = client . uploadDir ( params ) ;
155+
156+ return new Promise ( ( resolve , reject ) => {
157+ uploader . on ( 'error' , function ( err ) {
158+ console . error ( "s3 Upload Error:" , err . stack ) ;
159+ reject ( ) ;
160+ } ) ;
161+ uploader . on ( 'end' , function ( ) {
162+ console . log ( demo , " demo uploaded to s3" ) ;
163+ resolve ( ) ;
164+ } ) ;
165+ } ) ;
166+ }
167+
168+ task ( 'demos.download' , ( done : Function ) => {
169+ if ( ! process . env . AWS_KEY || ! process . env . AWS_SECRET ) {
170+ return new Promise ( ( resolve ) => { resolve ( ) ; } ) ;
171+ }
172+
173+ let client = s3 . createClient ( {
174+ s3Options : {
175+ accessKeyId : process . env . AWS_KEY ,
176+ secretAccessKey : process . env . AWS_SECRET
177+ } ,
178+ } ) ;
179+
180+ let params = {
181+ localDir : join ( process . cwd ( ) , 'dist' , 'demos' , 'src' ) ,
182+ s3Params : {
183+ Bucket : "ionic-demos" ,
184+ } ,
185+ } ;
186+
187+ let uploader = client . downloadDir ( params ) ;
188+
189+ return new Promise ( ( resolve , reject ) => {
190+ uploader . on ( 'error' , function ( err ) {
191+ console . error ( "s3 Download Error:" , err . stack ) ;
192+ reject ( ) ;
193+ } ) ;
194+ uploader . on ( 'end' , function ( ) {
195+ console . log ( "Demos downloaded from s3" ) ;
196+ resolve ( ) ;
197+ } ) ;
198+ } ) ;
199+ } )
200+
115201task ( 'demos.clean' , ( done : Function ) => {
116202 // this is a super hack, but it works for now
117203 if ( argv . skipClean ) {
0 commit comments