-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(bazel): create AIO example playgrounds for manual testing
After the bazel migration, AIO examples are no longer fully formed in the source tree.
- Loading branch information
1 parent
2dd8235
commit f37dd0f
Showing
26 changed files
with
393 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import shelljs from 'shelljs'; | ||
import yargs from 'yargs' | ||
import {hideBin} from 'yargs/helpers'; | ||
import {getNativeBinary as getNativeBazelBinary} from '@bazel/bazelisk'; | ||
|
||
shelljs.set('-e') | ||
shelljs.set('-v') | ||
|
||
/** | ||
* Create an example playground with shared example deps and optionally linked local | ||
* angular packages in the source tree under content/examples/example-playground. This | ||
* is a wrapper around the equivalent bazel binary but adds the --local option to link | ||
* local packages. | ||
* | ||
* Usage: node ./tools/examples/create-example-playground-wrapper.mjs <example> [options] | ||
* | ||
* Args: | ||
* example: name of the example | ||
* | ||
* Flags: | ||
* --local: use locally built angular packages | ||
*/ | ||
|
||
const options = yargs(hideBin(process.argv)) | ||
.command('$0 <example>', 'Set up a playground for <example> in the source tree for manual testing') | ||
.option('local', {default: false, type: 'boolean'}) | ||
.version(false) | ||
.strict() | ||
.argv; | ||
|
||
const cmd = [ | ||
getNativeBazelBinary(), | ||
'run', | ||
'//aio/tools/examples:create-example-playground', | ||
'--', | ||
`--example=${options.example}`, | ||
]; | ||
|
||
if (options.local) { | ||
cmd.splice(2, 0, '--config=aio_local_deps'); | ||
} | ||
|
||
shelljs.exec(cmd.join(' ')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import path from 'node:path'; | ||
import yargs from 'yargs'; | ||
import {hideBin} from 'yargs/helpers' | ||
import {constructExampleSandbox} from './example-sandbox.mjs'; | ||
|
||
if (!process.env.BUILD_WORKSPACE_DIRECTORY) { | ||
console.error( | ||
'Not running script as part of `bazel run`.' | ||
) | ||
process.exit(1); | ||
} | ||
const sourceRoot = process.env.BUILD_WORKSPACE_DIRECTORY; | ||
const runfilesRoot = path.join(process.env.RUNFILES, 'angular'); | ||
const playgroundRoot = path.join(sourceRoot, 'aio', 'content', 'example-playground'); | ||
|
||
/** | ||
* Create an example playground with shared example deps and optionally linked local | ||
* angular packages in the source tree under content/examples/example-playground. This | ||
* script is intended to only be run under bazel as it has the localPackage arguments | ||
* hardcoded into the binary via starlark. | ||
* | ||
* Usage: bazel run //aio/tools/examples:create-example-playground -- --example=<example> | ||
* | ||
* Args: | ||
* example: name of the example | ||
*/ | ||
|
||
async function main(args) { | ||
const options = | ||
yargs(args) | ||
// Note: localPackage not listed above in usage as it's hardcoded in by the nodejs_binary | ||
.option('localPackage', { | ||
array: true, | ||
type: 'string', | ||
default: [], | ||
describe: 'Locally built package to substitute, in the form `packageName#packagePath`' | ||
}) | ||
.option('example', { | ||
type: 'string', | ||
describe: 'Name of the example' | ||
}) | ||
.demandOption('example') | ||
.strict() | ||
.version(false) | ||
.argv; | ||
|
||
const localPackages = options.localPackage.reduce((pkgs, pkgNameAndPath) => { | ||
const [pkgName, pkgPath] = pkgNameAndPath.split('#'); | ||
pkgs[pkgName] = path.resolve(pkgPath); | ||
return pkgs; | ||
}, {}); | ||
|
||
const exampleName = options.example; | ||
|
||
// Note: the example sources plus boilerplate are merged into a target named after the example | ||
const fullExamplePath = path.join(runfilesRoot, 'aio', 'content', 'examples', exampleName, exampleName); | ||
|
||
const destPath = path.join(playgroundRoot, exampleName); | ||
const nodeModules = path.join(runfilesRoot, '..', 'aio_example_deps', 'node_modules'); | ||
|
||
await constructExampleSandbox(fullExamplePath, destPath, nodeModules, localPackages); | ||
|
||
console.log(`A playground folder for ${exampleName} has been set up at\n\n ${destPath}\n`); | ||
} | ||
|
||
(async () => await main(hideBin(process.argv)))(); |
Oops, something went wrong.