@@ -5,6 +5,15 @@ const ts = require('gulp-typescript');
55const sourcemaps = require ( 'gulp-sourcemaps' ) ;
66const clean = require ( 'gulp-clean' ) ;
77const deleteEmpty = require ( 'delete-empty' ) ;
8+ const childProcess = require ( 'child_process' ) ;
9+ const log = require ( 'fancy-log' ) ;
10+ const clc = require ( 'cli-color' ) ;
11+
12+ const { promisify } = require ( 'util' ) ;
13+
14+ const exec = promisify ( childProcess . exec ) ;
15+
16+ const SAMPLE = path . join ( __dirname , 'sample' ) ;
817
918const packages = {
1019 common : ts . createProject ( 'packages/common/tsconfig.json' ) ,
@@ -101,9 +110,49 @@ function getFolders(dir) {
101110 return fs . statSync ( path . join ( dir , file ) ) . isDirectory ( ) ;
102111 } ) ;
103112}
104- gulp . task ( 'move' , function ( ) {
105- const getDirs = base => getFolders ( base ) . map ( path => `${ base } /${ path } ` ) ;
106113
114+ const getDirs = base => getFolders ( base ) . map ( path => `${ base } /${ path } ` ) ;
115+
116+ gulp . task ( 'install:samples' , async ( ) => {
117+ const directories = getDirs ( SAMPLE ) ;
118+
119+ const promises = directories . map ( async dir => {
120+ log . info (
121+ `Installing dependencies of ${ clc . magenta ( dir . replace ( __dirname , '' ) ) } ` ,
122+ ) ;
123+ try {
124+ await exec ( `npm install --no-shrinkwrap --prefix ${ dir } ` ) ;
125+ } catch ( err ) {
126+ log . error ( `Failed installing dependencies of ${ dir } ` ) ;
127+ throw err ;
128+ }
129+ } ) ;
130+
131+ await Promise . all ( promises ) ;
132+ } ) ;
133+
134+ gulp . task ( 'build:samples' , async ( ) => {
135+ const directories = getDirs ( SAMPLE ) ;
136+
137+ const promises = directories . map ( async dir => {
138+ log . info (
139+ `Building ${ clc . magenta ( dir . replace ( __dirname , '' ) ) } ` ,
140+ ) ;
141+ try {
142+ await exec ( `npm run build --prefix ${ dir } ` ) ;
143+ } catch ( err ) {
144+ log . error ( `Failed building ${ clc . magenta ( dir ) } :` ) ;
145+ if ( err . stdout ) {
146+ log . error ( err . stdout ) ;
147+ }
148+ throw err ;
149+ }
150+ } ) ;
151+
152+ return await Promise . all ( promises ) ;
153+ } ) ;
154+
155+ gulp . task ( 'move' , function ( ) {
107156 const examplesDirs = getDirs ( 'sample' ) ;
108157 const integrationDirs = getDirs ( 'integration' ) ;
109158 const directories = examplesDirs . concat ( integrationDirs ) ;
0 commit comments