mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
ci(gulp): support multi-application samples
This commit is contained in:
@@ -5,7 +5,7 @@ import { task } from 'gulp';
|
||||
import { resolve } from 'path';
|
||||
import { promisify } from 'util';
|
||||
import { samplePath } from '../config';
|
||||
import { getDirs } from '../util/task-helpers';
|
||||
import { containsPackageJson, getDirs } from '../util/task-helpers';
|
||||
|
||||
const exec = promisify(childProcess.exec);
|
||||
|
||||
@@ -16,15 +16,39 @@ async function executeNpmScriptInSamples(
|
||||
const directories = getDirs(samplePath);
|
||||
|
||||
for await (const dir of directories) {
|
||||
// Check if the sample is a multi-application sample
|
||||
const isSingleApplicationSample = containsPackageJson(dir);
|
||||
if (!isSingleApplicationSample) {
|
||||
// Application is a multi-application sample
|
||||
// Go down into the sub-directories
|
||||
const subDirs = getDirs(dir);
|
||||
for (const subDir of subDirs) {
|
||||
await executeNPMScriptInDirectory(subDir, script, appendScript);
|
||||
}
|
||||
} else {
|
||||
await executeNPMScriptInDirectory(dir, script, appendScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the provided NPM script in the specified directory
|
||||
* @param dir directory of the application
|
||||
* @param script script to execute
|
||||
* @param appendScript additional params appended to the script
|
||||
*/
|
||||
async function executeNPMScriptInDirectory(
|
||||
dir: string,
|
||||
script: string,
|
||||
appendScript?: string,
|
||||
) {
|
||||
const dirName = dir.replace(resolve(__dirname, '../../../'), '');
|
||||
log.info(`Running ${clc.blue(script)} in ${clc.magenta(dirName)}`);
|
||||
try {
|
||||
const result = await exec(
|
||||
`${script} --prefix ${dir} ${appendScript ? '-- ' + appendScript : ''}`,
|
||||
);
|
||||
log.info(
|
||||
`Finished running ${clc.blue(script)} in ${clc.magenta(dirName)}`,
|
||||
);
|
||||
log.info(`Finished running ${clc.blue(script)} in ${clc.magenta(dirName)}`);
|
||||
if (result.stderr) {
|
||||
log.error(result.stderr);
|
||||
}
|
||||
@@ -32,9 +56,7 @@ async function executeNpmScriptInSamples(
|
||||
log.error(result.stdout);
|
||||
}
|
||||
} catch (err) {
|
||||
log.error(
|
||||
`Failed running ${clc.blue(script)} in ${clc.magenta(dirName)}`,
|
||||
);
|
||||
log.error(`Failed running ${clc.blue(script)} in ${clc.magenta(dirName)}`);
|
||||
if (err.stderr) {
|
||||
log.error(err.stderr);
|
||||
}
|
||||
@@ -44,7 +66,6 @@ async function executeNpmScriptInSamples(
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task('install:samples', async () =>
|
||||
executeNpmScriptInSamples(
|
||||
|
||||
@@ -12,3 +12,12 @@ export function getFolders(dir: string) {
|
||||
export function getDirs(base: string) {
|
||||
return getFolders(base).map(path => `${base}/${path}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the directory contains a package.json file
|
||||
* @param dir Path to the dircetory
|
||||
* @returns True if the directory contains a package.json
|
||||
*/
|
||||
export function containsPackageJson(dir: string) {
|
||||
return readdirSync(dir).some(file => file === 'package.json');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user