From f081e63c99b04ab824f8d658bb0bb494d496d22c Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 14 Jan 2021 17:20:32 -0600 Subject: [PATCH 1/4] chore(examples): debug example script --- tasks/examples.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tasks/examples.js b/tasks/examples.js index 143a502f3e67..203e3c366bdd 100644 --- a/tasks/examples.js +++ b/tasks/examples.js @@ -91,7 +91,7 @@ async function main() { packagesWithExamples.map(async (pkg) => { reporter.info(`Building examples in package \`${pkg.name}\``); - const { examples, filepath, name } = pkg; + const { examples, name } = pkg; const packageDir = path.join(BUILD_DIR, name, 'examples'); await fs.ensureDir(packageDir); @@ -120,13 +120,18 @@ async function main() { }); } + console.log(example.name, exampleBuildDir); + if (await fs.pathExists(exampleBuildDir)) { + console.log('build dir path exists'); await fs.copy(exampleBuildDir, exampleDir); return; } + console.log('build dir does not exist'); + await fs.copy(example.filepath, exampleDir, { - filter(src, dest) { + filter(src) { const relativePath = path.relative(example.filepath, src); if (relativePath.includes('node_modules')) { return false; From a389ed005231a893a77e07fed831f96510f4dcf6 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 14 Jan 2021 17:36:05 -0600 Subject: [PATCH 2/4] chore(examples): debug example script --- tasks/examples.js | 122 ++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/tasks/examples.js b/tasks/examples.js index 203e3c366bdd..9ace8fcf56c1 100644 --- a/tasks/examples.js +++ b/tasks/examples.js @@ -87,70 +87,74 @@ async function main() { (pkg) => Array.isArray(pkg.examples) && pkg.examples.length !== 0 ); - await Promise.all( - packagesWithExamples.map(async (pkg) => { - reporter.info(`Building examples in package \`${pkg.name}\``); - - const { examples, name } = pkg; - const packageDir = path.join(BUILD_DIR, name, 'examples'); - - await fs.ensureDir(packageDir); - - await Promise.all( - examples.map(async (example) => { - reporter.info( - `Building example \`${example.name}\` in package \`${pkg.name}\`` - ); - - const exampleDir = path.join(packageDir, example.name); - const exampleBuildDir = path.join(example.filepath, 'build'); - const packageJsonPath = path.join(example.filepath, 'package.json'); - const packageJson = await fs.readJson(packageJsonPath); - - await fs.ensureDir(exampleDir); - - if (packageJson.scripts.build) { - spawn.sync('yarn', ['install'], { - stdio: 'ignore', - cwd: example.filepath, - }); - spawn.sync('yarn', ['build'], { - stdio: 'ignore', - cwd: example.filepath, - }); - } + // await Promise.all( + // packagesWithExamples.map(async (pkg) => { + for (const pkg of packagesWithExamples) { + reporter.info(`Building examples in package \`${pkg.name}\``); - console.log(example.name, exampleBuildDir); + const { examples, name } = pkg; + const packageDir = path.join(BUILD_DIR, name, 'examples'); - if (await fs.pathExists(exampleBuildDir)) { - console.log('build dir path exists'); - await fs.copy(exampleBuildDir, exampleDir); - return; - } + await fs.ensureDir(packageDir); - console.log('build dir does not exist'); - - await fs.copy(example.filepath, exampleDir, { - filter(src) { - const relativePath = path.relative(example.filepath, src); - if (relativePath.includes('node_modules')) { - return false; - } - if (relativePath[0] === '.') { - return false; - } - return true; - }, - }); - reporter.success( - `Built example \`${example.name}\` in package \`${pkg.name}\`` - ); - }) + // await Promise.all( + // examples.map(async (example) => { + for (const example of examples) { + reporter.info( + `Building example \`${example.name}\` in package \`${pkg.name}\`` ); - reporter.success(`Built examples in package \`${pkg.name}\``); - }) - ); + const exampleDir = path.join(packageDir, example.name); + const exampleBuildDir = path.join(example.filepath, 'build'); + const packageJsonPath = path.join(example.filepath, 'package.json'); + const packageJson = await fs.readJson(packageJsonPath); + + await fs.ensureDir(exampleDir); + + if (packageJson.scripts.build) { + spawn.sync('yarn', ['install'], { + stdio: 'ignore', + cwd: example.filepath, + }); + spawn.sync('yarn', ['build'], { + stdio: 'inherit', + cwd: example.filepath, + }); + } + + console.log(example.name, exampleBuildDir); + + if (await fs.pathExists(exampleBuildDir)) { + console.log('build dir path exists'); + await fs.copy(exampleBuildDir, exampleDir); + return; + } + + console.log('build dir does not exist'); + + await fs.copy(example.filepath, exampleDir, { + filter(src) { + const relativePath = path.relative(example.filepath, src); + if (relativePath.includes('node_modules')) { + return false; + } + if (relativePath[0] === '.') { + return false; + } + return true; + }, + }); + reporter.success( + `Built example \`${example.name}\` in package \`${pkg.name}\`` + ); + } + // }) + // ); + + reporter.success(`Built examples in package \`${pkg.name}\``); + } + // }) + // ); const links = packagesWithExamples.reduce((html, pkg) => { const links = pkg.examples.reduce((acc, example) => { From 862d5f5e138a7e33f0e69fcfd0d074e2b408feb4 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 14 Jan 2021 18:20:29 -0600 Subject: [PATCH 3/4] chore(examples): debug example script --- tasks/examples.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/examples.js b/tasks/examples.js index 9ace8fcf56c1..8904253b6cc2 100644 --- a/tasks/examples.js +++ b/tasks/examples.js @@ -122,15 +122,15 @@ async function main() { }); } - console.log(example.name, exampleBuildDir); + console.log(pkg.name, example.name, exampleBuildDir); if (await fs.pathExists(exampleBuildDir)) { - console.log('build dir path exists'); + console.log(pkg.name, example.name, 'build dir path exists'); await fs.copy(exampleBuildDir, exampleDir); - return; + continue; } - console.log('build dir does not exist'); + console.log(pkg.name, example.name, 'build dir does not exist'); await fs.copy(example.filepath, exampleDir, { filter(src) { From 5ea4343b5cd440adce9adf3471658df340e607b7 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 14 Jan 2021 18:48:20 -0600 Subject: [PATCH 4/4] chore(examples): update to fail on subprocess exit code 1 --- packages/grid/examples/preview/package.json | 2 +- tasks/examples.js | 131 ++++++++++---------- 2 files changed, 68 insertions(+), 65 deletions(-) diff --git a/packages/grid/examples/preview/package.json b/packages/grid/examples/preview/package.json index 0943da3febbf..d8c2c791e094 100644 --- a/packages/grid/examples/preview/package.json +++ b/packages/grid/examples/preview/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "license": "Apache-2.0", "scripts": { - "build": "export PATH_PREFIX=\"/grid/examples/preview\" && parcel build -d build --public-url $PATH_PREFIX index.html", + "build": "parcel build -d build --public-url \"/grid/examples/preview\" index.html", "develop": "parcel index.html --no-cache" }, "devDependencies": { diff --git a/tasks/examples.js b/tasks/examples.js index 8904253b6cc2..d3b6239bc935 100644 --- a/tasks/examples.js +++ b/tasks/examples.js @@ -29,6 +29,7 @@ const IGNORE_EXAMPLE_DIRS = new Set([ 'styled-components', 'vue-cli', 'storybook', + 'sass-modules', ]); /** @@ -87,74 +88,76 @@ async function main() { (pkg) => Array.isArray(pkg.examples) && pkg.examples.length !== 0 ); - // await Promise.all( - // packagesWithExamples.map(async (pkg) => { - for (const pkg of packagesWithExamples) { - reporter.info(`Building examples in package \`${pkg.name}\``); - - const { examples, name } = pkg; - const packageDir = path.join(BUILD_DIR, name, 'examples'); + await Promise.all( + packagesWithExamples.map(async (pkg) => { + reporter.info(`Building examples in package \`${pkg.name}\``); + + const { examples, name } = pkg; + const packageDir = path.join(BUILD_DIR, name, 'examples'); + + await fs.ensureDir(packageDir); + + await Promise.all( + examples.map(async (example) => { + reporter.info( + `Building example \`${example.name}\` in package \`${pkg.name}\`` + ); + + const exampleDir = path.join(packageDir, example.name); + const exampleBuildDir = path.join(example.filepath, 'build'); + const packageJsonPath = path.join(example.filepath, 'package.json'); + const packageJson = await fs.readJson(packageJsonPath); + + await fs.ensureDir(exampleDir); + + if (packageJson.scripts.build) { + const installResult = spawn.sync('yarn', ['install'], { + stdio: 'ignore', + cwd: example.filepath, + }); + if (installResult.status !== 0) { + throw new Error( + `Error installing dependencies for ${pkg.name}:${example.name}` + ); + } + + const buildResult = spawn.sync('yarn', ['build'], { + stdio: 'ignore', + cwd: example.filepath, + }); + if (buildResult.status !== 0) { + throw new Error( + `Error building example ${example.name} for ${pkg.name}` + ); + } + } - await fs.ensureDir(packageDir); + if (await fs.pathExists(exampleBuildDir)) { + await fs.copy(exampleBuildDir, exampleDir); + return; + } - // await Promise.all( - // examples.map(async (example) => { - for (const example of examples) { - reporter.info( - `Building example \`${example.name}\` in package \`${pkg.name}\`` + await fs.copy(example.filepath, exampleDir, { + filter(src) { + const relativePath = path.relative(example.filepath, src); + if (relativePath.includes('node_modules')) { + return false; + } + if (relativePath[0] === '.') { + return false; + } + return true; + }, + }); + reporter.success( + `Built example \`${example.name}\` in package \`${pkg.name}\`` + ); + }) ); - const exampleDir = path.join(packageDir, example.name); - const exampleBuildDir = path.join(example.filepath, 'build'); - const packageJsonPath = path.join(example.filepath, 'package.json'); - const packageJson = await fs.readJson(packageJsonPath); - - await fs.ensureDir(exampleDir); - - if (packageJson.scripts.build) { - spawn.sync('yarn', ['install'], { - stdio: 'ignore', - cwd: example.filepath, - }); - spawn.sync('yarn', ['build'], { - stdio: 'inherit', - cwd: example.filepath, - }); - } - - console.log(pkg.name, example.name, exampleBuildDir); - - if (await fs.pathExists(exampleBuildDir)) { - console.log(pkg.name, example.name, 'build dir path exists'); - await fs.copy(exampleBuildDir, exampleDir); - continue; - } - - console.log(pkg.name, example.name, 'build dir does not exist'); - - await fs.copy(example.filepath, exampleDir, { - filter(src) { - const relativePath = path.relative(example.filepath, src); - if (relativePath.includes('node_modules')) { - return false; - } - if (relativePath[0] === '.') { - return false; - } - return true; - }, - }); - reporter.success( - `Built example \`${example.name}\` in package \`${pkg.name}\`` - ); - } - // }) - // ); - - reporter.success(`Built examples in package \`${pkg.name}\``); - } - // }) - // ); + reporter.success(`Built examples in package \`${pkg.name}\``); + }) + ); const links = packagesWithExamples.reduce((html, pkg) => { const links = pkg.examples.reduce((acc, example) => {