Skip to content

Commit

Permalink
build(): Add build:samples script
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Jul 10, 2019
1 parent fc3dd67 commit 6a6c62d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 51 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const clean = require('gulp-clean');
const deleteEmpty = require('delete-empty');
const childProcess = require('child_process');
const log = require('fancy-log');
const clc = require('cli-color');

const { promisify } = require('util');

const exec = promisify(childProcess.exec);

const SAMPLE = path.join(__dirname, 'sample');

const packages = {
common: ts.createProject('packages/common/tsconfig.json'),
Expand Down Expand Up @@ -101,9 +110,49 @@ function getFolders(dir) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}
gulp.task('move', function() {
const getDirs = base => getFolders(base).map(path => `${base}/${path}`);

const getDirs = base => getFolders(base).map(path => `${base}/${path}`);

gulp.task('install:samples', async () => {
const directories = getDirs(SAMPLE);

const promises = directories.map(async dir => {
log.info(
`Installing dependencies of ${clc.magenta(dir.replace(__dirname, ''))}`,
);
try {
await exec(`npm install --no-shrinkwrap --prefix ${dir}`);
} catch (err) {
log.error(`Failed installing dependencies of ${dir}`);
throw err;
}
});

await Promise.all(promises);
});

gulp.task('build:samples', async () => {
const directories = getDirs(SAMPLE);

const promises = directories.map(async dir => {
log.info(
`Building ${clc.magenta(dir.replace(__dirname, ''))}`,
);
try {
await exec(`npm run build --prefix ${dir}`);
} catch (err) {
log.error(`Failed building ${clc.magenta(dir)}:`);
if(err.stdout) {
log.error(err.stdout);
}
throw err;
}
});

return await Promise.all(promises);
});

gulp.task('move', function() {
const examplesDirs = getDirs('sample');
const integrationDirs = getDirs('integration');
const directories = examplesDirs.concat(integrationDirs);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "npm run clean && gulp build",
"prebuild:dev": "rm -rf node_modules/@nestjs",
"build:dev": "gulp build --dist node_modules/@nestjs && gulp move",
"build:samples": "gulp install:samples && npm run build:dev && gulp build:samples",
"postinstall": "opencollective",
"prerelease": "gulp copy-misc && gulp build --dist node_modules/@nestjs",
"publish": "npm run prerelease && npm run build && ./node_modules/.bin/lerna publish --force-publish --access public --exact -m \"chore(@nestjs) publish %s release\"",
Expand Down Expand Up @@ -103,6 +104,7 @@
"coveralls": "3.0.4",
"csv-write-stream": "2.0.0",
"delete-empty": "3.0.0",
"fancy-log": "^1.3.3",
"fastify-static": "2.5.0",
"gulp": "4.0.1",
"gulp-clang-format": "1.0.27",
Expand Down

0 comments on commit 6a6c62d

Please sign in to comment.