diff --git a/README.md b/README.md index edaa692a..cb8b00be 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ npm run build Copies of the source of Enact and other related libraries are placed into the `raw/` directory. If you need to link local copies, link them into that directory. E.g.: +`parse-docs` also clones `enactjs/samples` (branch `develop`) into `raw/samples`. Embedded samples are +configured in `src/config/sampleEmbeds.json` and built by `make-runner` into `public/`. + ## Check Broken Links To check the broken links, follow the steps below: @@ -54,4 +57,4 @@ To check the broken links, follow the steps below: 1. `npm run parse-docs` 2. `npm run parse-pages` 3. `npm run build` -4. `npm run check-links` \ No newline at end of file +4. `npm run check-links` diff --git a/scripts/make-runner.mjs b/scripts/make-runner.mjs index ff8a32a1..f0695dd8 100644 --- a/scripts/make-runner.mjs +++ b/scripts/make-runner.mjs @@ -1,15 +1,35 @@ import fs from 'fs'; +import path from 'path'; import parseArgs from 'minimist'; import shell from 'shelljs'; import {errorExit} from './utils.mjs'; import allLibraries from '../src/data/libraryDescription.json' with {type: 'json'}; +import sampleEmbeds from '../src/config/sampleEmbeds.json' with {type: 'json'}; + +await import('./prepare-raw.mjs'); + +const rootDir = path.resolve(import.meta.dirname, '..'); +const cliScript = path.join(rootDir, 'raw/cli/bin/enact.js'); + +// Resolves the enact cli command: +// (unset) / 'enact' -> the globally installed cli (default) +// any other value -> the pinned cli cloned into raw/cli, referenced by an +// absolute path so it resolves regardless of the cwd the +// build runs from (theme and sample dirs sit at different depths) +function resolveEnactCmd (cmd) { + if (!cmd || cmd === 'enact') { + return 'enact'; + } + + return `node "${cliScript}"`; +} const includes = ['core', 'moonstone', 'sandstone', 'limestone', 'agate'], themes = Object.keys(allLibraries).filter(name => includes.includes(name)); const args = parseArgs(process.argv), fast = args.fast, - enactCmd = args['enact-cmd'] || 'enact'; + enactCmd = resolveEnactCmd(args['enact-cmd']); if (!enactCmd && !shell.which('enact')) { errorExit('Sorry, this script requires the enact cli tool'); @@ -66,3 +86,28 @@ themes.forEach(theme => { fs.writeFileSync(`${ilibDst}/ilibmanifest.json`, JSON.stringify({files: copiedIlib})); } }); + +sampleEmbeds.forEach(({id, build}) => { + const {src, output} = build; + + if (!fs.existsSync(src)) { + return; + } + + if (!fs.existsSync(`${src}/node_modules`)) { + if (shell.exec('npm install', {cwd: src}).code !== 0) { + errorExit(`Error installing dependencies for ${id}. Aborting.`); + } + } + + if (fast && fs.existsSync(`${output}/index.html`)) { + // eslint-disable-next-line no-console + console.log(`Sample ${id} exists, skipping build. Use "npm run make-runner" to build`); + } else { + const relOut = path.relative(src, output).split(path.sep).join('/'); + const command = `${enactCmd} pack -p -o ${relOut}`; + if (shell.exec(command, {async: false, cwd: src}).code !== 0) { + errorExit(`Error building ${id}. Aborting.`); + } + } +}); diff --git a/scripts/prepare-raw.mjs b/scripts/prepare-raw.mjs index 05502192..592f6a36 100644 --- a/scripts/prepare-raw.mjs +++ b/scripts/prepare-raw.mjs @@ -40,6 +40,7 @@ const rebuild = args['rebuild-raw'], copyGitHub('enactjs/enact', 'raw/enact', rebuild, args['enact-branch'], args['ssh']); copyGitHub('enactjs/cli', 'raw/cli', rebuild, args['cli-branch'], args['ssh']); copyGitHub('enactjs/eslint-config-enact', 'raw/eslint-config-enact', rebuild, args['eslint-config-branch'], args['ssh']); +copyGitHub('enactjs/samples', 'raw/samples', rebuild, 'develop', args['ssh']); if (extraRepos) { const repos = extraRepos.split(','); diff --git a/src/components/Page/[...data].astro b/src/components/Page/[...data].astro index d0bbd06d..a345abe1 100644 --- a/src/components/Page/[...data].astro +++ b/src/components/Page/[...data].astro @@ -10,6 +10,7 @@ import { MemberObjectTypeDef, MemberProperties, ModuleImport, + SampleEmbedSection, } from '../index'; import {getJSONData, getMembers} from "./utils"; @@ -36,6 +37,7 @@ const [membersData, typeDefinitionsData] = getMembers(data);
Loading Live Preview
)} + diff --git a/src/components/SampleEmbed/SampleEmbed.jsx b/src/components/SampleEmbed/SampleEmbed.jsx new file mode 100644 index 00000000..25dcd609 --- /dev/null +++ b/src/components/SampleEmbed/SampleEmbed.jsx @@ -0,0 +1,13 @@ +import {withBase} from '../../utils/utils'; +import css from './SampleEmbed.module.css'; + +const SampleEmbed = ({src, title = 'Sample preview'}) => ( +