Repository navigation
feat(author): build the one-file tool in the package, not on the organisation's site #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,58 @@ | ||
| import { execFileSync } from 'node:child_process' | ||
| import { readFile, rm } from 'node:fs/promises' | ||
| import { join, resolve } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
|
|
||
| /** | ||
| * The command line as one file, `h5p-author.mjs`, and `h5p-author-LICENSES.txt`, every package | ||
| * bundled into it with its licence, since MIT and BSD-3-Clause ask their notices to travel with | ||
| * copies (#247). Route 3 of the skill runs the file with nothing installed, from an unzipped bundle. | ||
| * The organisation's site serves it, copied from this package from the first release that ships | ||
| * it, so that the npm package, and its provenance, cover the bytes a chat runs. Everything it | ||
| * imports is bundled in by Vite, with copies | ||
| * of the two package.json files it reads its versions from where neither is beside it | ||
| * (h5p-toolkit#198). It takes `--libraries`: the pinned pack is not with it. | ||
| * | ||
| * `pnpm build:tool` builds the player's plan, which it imports, first; `prepack` runs that. | ||
| * `node scripts/build-tool.mjs [folder]` writes the two files in `folder`, by default `dist/`. | ||
| */ | ||
| // Packing runs Vite 8, which needs Node 20.19, or 22.12 and later, on the workspace's floor, 22.12: | ||
| // said here before Vite fails to load. The package's own `engines` stays `>=22`, since installing | ||
| // it runs none of this. | ||
| const [major, minor] = process.versions.node.split('.').map(Number) | ||
| if (major < 22 || (major === 22 && minor < 12)) { | ||
| throw new Error(`Packing builds the one-file tool with Vite 8, and the workspace needs Node 22.12 or later for it; this is Node ${process.versions.node}`) | ||
| } | ||
| const { build } = await import('vite') | ||
|
|
||
| const root = resolve(import.meta.dirname, '..') | ||
| const folder = resolve(process.argv[2] ?? join(root, 'dist')) | ||
| const TOOL = 'h5p-author.mjs' | ||
| const LICENSES = 'h5p-author-LICENSES.txt' | ||
|
|
||
| for (const file of [TOOL, LICENSES]) await rm(join(folder, file), { force: true }) | ||
| await build({ | ||
| configFile: false, | ||
| root, | ||
| logLevel: 'warn', | ||
| publicDir: false, | ||
| build: { | ||
| ssr: join(root, 'bin', TOOL), | ||
| outDir: folder, | ||
| emptyOutDir: false, | ||
| copyPublicDir: false, | ||
| minify: false, | ||
| license: { fileName: LICENSES }, | ||
| reportCompressedSize: false, | ||
| rolldownOptions: { output: { entryFileNames: TOOL, format: 'es', codeSplitting: false } } | ||
| }, | ||
| ssr: { noExternal: true, target: 'node' } | ||
| }) | ||
|
|
||
| // The tool says its own versions, as a model checking it first asks: this package's and its pack's. | ||
| const version = async (/** @type {string} */ path) => JSON.parse(await readFile(path, 'utf8')).version | ||
| const pack = fileURLToPath(import.meta.resolve('@missing-elements/h5p-libraries/package.json')) | ||
| const expected = `@missing-elements/h5p-author ${await version(join(root, 'package.json'))}, library pack ${await version(pack)}` | ||
| const printed = execFileSync(process.execPath, [join(folder, TOOL), '--version'], { encoding: 'utf8' }).trim() | ||
| if (printed !== expected) throw new Error(`${TOOL} --version printed "${printed}", not "${expected}"`) | ||
| console.log(`Built ${join(folder, TOOL)}: ${printed}`) |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.