-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rename package from `fbicodec_ts` to `@oazmi/fbicodec` - defined package exports in `deno.json`. - move to jsr imports - update dependencies: - `kitchensink`: `0.7.3` -> `0.7.5` - update dev dependency: - `dnt`: `0.40.0` -> `0.41.0`. - modify `build_npm.ts` so that: - deno testing shims are not created. - import mapping is no longer needed. but with the drawback of not being able to map my dependencies to my npm-release version of the package. - update other build scripts - move `/src/readme.md` and `/src/license.md` to root of repo. and update `gh-repo-ci.yml` continous integration to copy them from the root dir to the `/src/` dir.
- Loading branch information
Showing
16 changed files
with
190 additions
and
217 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ on: | |
branches: | ||
- main | ||
paths: | ||
- "src/readme.md" | ||
- "src/license.md" | ||
- "readme.md" | ||
- "license.md" | ||
|
||
permissions: | ||
contents: write | ||
|
@@ -18,18 +18,18 @@ jobs: | |
- name: clone repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: copy readme.md | ||
run: cp "src/readme.md" ".github/readme.md" | ||
- name: copy "/readme.md" to "/src/readme.md" | ||
run: cp "readme.md" "src/readme.md" | ||
|
||
- name: copy license.md | ||
run: cp "src/license.md" "license.md" | ||
- name: copy "/license.md" to "/src/license.md" | ||
run: cp "license.md" "src/license.md" | ||
|
||
- name: commit additions | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add --force ".github/readme.md" "license.md" | ||
git add --force "src/readme.md" "src/license.md" | ||
git commit -m "update file via \"github-repo-ci.yml\"" | ||
git push | ||
git rm --cached ".github/readme.md" "license.md" | ||
git rm --cached "src/readme.md" "src/license.md" | ||
git push |
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 |
---|---|---|
|
@@ -12,5 +12,5 @@ | |
/deno.d.ts | ||
|
||
# automatic file clones | ||
/.github/readme.md | ||
/license.md | ||
/src/readme.md | ||
/src/license.md |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { ensureFile } from "https://deno.land/[email protected]/fs/mod.ts" | ||
import { doubleCompileFiles } from "./build_tools.ts" | ||
import { doubleCompileFiles, ensureFile } from "./build_tools.ts" | ||
|
||
|
||
/** use: | ||
|
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { copy as copyFolder, ensureFile } from "https://deno.land/[email protected]/fs/mod.ts" | ||
import { dirname as pathDirname, join as pathJoin } from "https://deno.land/[email protected]/path/mod.ts" | ||
import { Application as typedocApp } from "npm:typedoc" | ||
import { TemporaryFiles, createNPMFiles, doubleCompileFiles, getDenoJson, mainEntrypoint, subEntrypoints } from "./build_tools.ts" | ||
import { Application as typedocApp } from "npm:[email protected]" | ||
import { | ||
TemporaryFiles, copyDir, createNPMFiles, doubleCompileFiles, | ||
ensureFile, getDenoJson, pathDirname, pathJoin, walkDir, | ||
} from "./build_tools.ts" | ||
|
||
|
||
/** use: | ||
|
@@ -12,6 +13,10 @@ const site_root = Deno.args[0] ?? "/" | |
const docs_output_dir = "./docs/" | ||
const docs_src_output_dir = "./docs/src/" | ||
const docs_dist_output_dir = "./docs/dist/" | ||
const example_files_dir = "./examples/" | ||
const extra_directories_to_copy: string[] = [ | ||
// "./examples/assets/", | ||
] | ||
|
||
|
||
interface CustomCSS_Artifacts extends TemporaryFiles { | ||
|
@@ -32,21 +37,24 @@ const createCustomCssFiles = async (base_dir: string = "./", content: string): P | |
} | ||
|
||
const npm_file_artifacts = await createNPMFiles("./") | ||
const { repository } = await getDenoJson() | ||
const { repository, exports } = await getDenoJson() | ||
const { ".": mainEntrypoint, ...subEntrypoints } = exports | ||
const custom_css_artifacts = await createCustomCssFiles("./temp/", ` | ||
table { border-collapse: collapse; } | ||
th { background-color: rgba(128, 128, 128, 0.50); } | ||
th, td { border: 0.1em solid rgba(0, 0, 0, 0.75); padding: 0.1em; } | ||
`) | ||
const custom_css_file_path = pathJoin(custom_css_artifacts.dir, custom_css_artifacts.files[0]) | ||
const typedoc_app = await typedocApp.bootstrapWithPlugins({ | ||
entryPoints: [mainEntrypoint, ...subEntrypoints], | ||
// even though the intermediate `package.json` created by `createNPMFiles` contains the `exports` field, `typedoc` can't figure out the entrypoints on its own. | ||
entryPoints: [mainEntrypoint, ...Object.values(subEntrypoints)], | ||
out: docs_output_dir, | ||
readme: "./src/readme.md", | ||
readme: "./readme.md", | ||
navigationLinks: { | ||
"github": repository.url.replace("git+", "").replace(".git", ""), | ||
"readme": site_root, | ||
"source": site_root + "src/mod.ts", | ||
"examples": site_root + "examples/index.html", | ||
"distribution": site_root + "dist/esm.js", | ||
}, | ||
skipErrorChecking: true, | ||
|
@@ -69,13 +77,13 @@ if (typedoc_project) { | |
|
||
// copy the source code to the docs' "src" subdirectory, so that it can be hosted on github pages similar to a cdn | ||
// assuming `site_root` is the root url of the hosted site, `${site_root}/src/*.ts` will contain all of the source typescript files | ||
await copyFolder("./src/", docs_src_output_dir, { overwrite: true }) | ||
await copyDir("./src/", docs_src_output_dir, { overwrite: true }) | ||
|
||
// copy the compiled distribution files in the docs' "dist" sub directory, so that it can be hosted on github pages similar to a cdn | ||
// assuming `site_root` is the root url of the hosted site, `${site_root}/dist/*.js` will contain various bundled javascript distributions | ||
const | ||
js_dist = (await doubleCompileFiles("./src/mod.ts", docs_dist_output_dir, {}, { minify: false }))[0], | ||
js_dist_minified = (await doubleCompileFiles("./src/mod.ts", docs_dist_output_dir, {}, { minify: true }))[0] | ||
js_dist = (await doubleCompileFiles("./src/mod.ts", docs_dist_output_dir, {}, { minify: false }, false))[0], | ||
js_dist_minified = (await doubleCompileFiles("./src/mod.ts", docs_dist_output_dir, {}, { minify: true }, false))[0] | ||
js_dist.path = pathJoin(pathDirname(js_dist.path), "./esm.js") | ||
js_dist_minified.path = pathJoin(pathDirname(js_dist_minified.path), "./esm.min.js") | ||
const output_dist_files = [js_dist, js_dist_minified] | ||
|
@@ -86,5 +94,50 @@ await Promise.all(output_dist_files.map( | |
} | ||
)) | ||
|
||
// compile example files, and copy them over | ||
const example_ts_files = [] | ||
const example_html_files = [] | ||
const example_misc_files = [] | ||
for await (const { path } of walkDir(example_files_dir, { exts: ["index.ts", "index.tsx", ".html", ".css"], includeDirs: false })) { | ||
if (path.endsWith(".ts") || path.endsWith(".tsx")) { example_ts_files.push(path) } | ||
else if (path.endsWith(".html")) { example_html_files.push(path) } | ||
else { example_misc_files.push(path) } | ||
} | ||
const example_ts_files_compiled = await doubleCompileFiles("", pathJoin(docs_output_dir, example_files_dir), | ||
{ | ||
entryPoints: example_ts_files, | ||
outbase: example_files_dir, | ||
bundle: true, | ||
splitting: true, | ||
platform: "browser", | ||
}, | ||
{ minify: true }, | ||
) | ||
console.log("writing the following transpiled files:", example_ts_files_compiled.map((out_file) => out_file.path)) | ||
await Promise.all(example_ts_files_compiled.map( | ||
async ({ text, path }, file_number) => { | ||
await ensureFile(path) | ||
await Deno.writeTextFile(path, text) | ||
} | ||
)) | ||
await Promise.all(example_html_files.map( | ||
async (path) => { | ||
const text = await Deno.readTextFile(path) | ||
const output_path = pathJoin(docs_output_dir, path) | ||
await ensureFile(output_path) | ||
await Deno.writeTextFile(output_path, text.replaceAll(/\.tsx?\"/gm, ".js\"")) | ||
} | ||
)) | ||
await Promise.all(extra_directories_to_copy.map( | ||
async (path) => { | ||
await copyDir(path, pathJoin(docs_output_dir, path), { overwrite: true }) | ||
} | ||
)) | ||
await Promise.all(example_misc_files.map( | ||
async (path) => { | ||
await copyDir(path, pathJoin(docs_output_dir, path), { overwrite: true }) | ||
} | ||
)) | ||
|
||
await npm_file_artifacts.cleanup() | ||
await custom_css_artifacts.cleanup() |
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 |
---|---|---|
@@ -1,34 +1,37 @@ | ||
import { emptyDir } from "https://deno.land/[email protected]/fs/mod.ts" | ||
import { basename as pathBasename, join as pathJoin } from "https://deno.land/[email protected]/path/mod.ts" | ||
import { build } from "https://deno.land/x/[email protected]/mod.ts" | ||
import { createPackageJson, createTSConfigJson, getDenoJson, mainEntrypoint, subEntrypoints } from "./build_tools.ts" | ||
import { createPackageJson, createTSConfigJson, dntBuild, emptyDir, getDenoJson, pathJoin } from "./build_tools.ts" | ||
|
||
|
||
const npm_dir = "./npm/" | ||
const deno_json_dir = "./" | ||
const deno_json = await getDenoJson(deno_json_dir) | ||
const library_name = deno_json.name ?? "library" | ||
const { | ||
name: library_name = "library", | ||
exports, | ||
node_packageManager, | ||
} = await getDenoJson(deno_json_dir) | ||
const mainEntrypoint = exports["."] | ||
|
||
const package_json = await createPackageJson(deno_json_dir, { | ||
scripts: { | ||
"build-dist": `npm run build-esm && npm run build-esm-minify && npm run build-iife && npm run build-iife-minify`, | ||
"build-esm": `npx esbuild "${mainEntrypoint}" --bundle --format=esm --outfile="./dist/${library_name}.esm.js"`, | ||
"build-esm-minify": `npx esbuild "${mainEntrypoint}" --bundle --minify --format=esm --outfile="./dist/${library_name}.esm.min.js"`, | ||
"build-iife": `npx esbuild "${mainEntrypoint}" --bundle --format=iife --outfile="./dist/${library_name}.iife.js"`, | ||
"build-iife-minify": `npx esbuild "${mainEntrypoint}" --bundle --minify --format=iife --outfile="./dist/${library_name}.iife.min.js"`, | ||
|
||
} | ||
}) | ||
const tsconfig_json = await createTSConfigJson(deno_json_dir) | ||
// we must delete the `exports` property, as it will override the correct version generated by `dntBuild`. | ||
delete package_json["exports"] | ||
|
||
await emptyDir(npm_dir) | ||
await build({ | ||
entryPoints: [ | ||
mainEntrypoint, | ||
...subEntrypoints.map(path => ({ name: "./" + pathBasename(path, ".ts"), path: path })), | ||
], | ||
await dntBuild({ | ||
entryPoints: Object.entries(exports).map(([export_path, source_path]) => ({ | ||
name: export_path, | ||
path: source_path, | ||
})), | ||
outDir: npm_dir, | ||
shims: { deno: true }, | ||
packageManager: deno_json.node_packageManager, | ||
shims: { deno: "dev" }, | ||
packageManager: node_packageManager, | ||
package: { | ||
...package_json | ||
}, | ||
|
@@ -38,28 +41,22 @@ await build({ | |
esModule: true, | ||
scriptModule: false, | ||
test: false, | ||
mappings: Object.fromEntries( | ||
["builtin_aliases_deps", "eightpack", "typedbuffer", "typedefs",].map((submodule_path) => { | ||
return [ | ||
"https://deno.land/x/[email protected]/" + submodule_path + ".ts", | ||
{ | ||
name: "kitchensink_ts", | ||
version: "^v0.7.3", | ||
subPath: submodule_path, | ||
} | ||
] | ||
}) | ||
) | ||
// override the test pattern, so that no tests are included, and no Deno.test shims are created for the entirety of the transpiled package. | ||
// see the details here: "https://github.com/denoland/dnt?tab=readme-ov-file#test-file-matching" | ||
testPattern: "TEST_NOTHING", | ||
// TODO: there's no need for mapping, as jsr imports are converted into npm-compatible packages on the fly. | ||
// however, I loose the ability to map it from my package's npm releases as a consequence. | ||
// consider whether or not I'd like to have my dependencies as jsr imports or npm imports. | ||
mappings: Object.fromEntries([]) | ||
}) | ||
|
||
// copy other files | ||
Deno.copyFileSync("./src/readme.md", pathJoin(npm_dir, "./src/readme.md")) | ||
Deno.copyFileSync("./src/readme.md", pathJoin(npm_dir, "readme.md")) | ||
Deno.copyFileSync("./src/license.md", pathJoin(npm_dir, "license.md")) | ||
Deno.copyFileSync("./.github/code_of_conduct.md", pathJoin(npm_dir, "code_of_conduct.md")) | ||
Deno.writeTextFileSync(pathJoin(npm_dir, ".gitignore"), "/node_modules/\n") | ||
Deno.writeTextFileSync(pathJoin(npm_dir, "tsconfig.json"), JSON.stringify(tsconfig_json)) | ||
Deno.writeTextFileSync(pathJoin(npm_dir, ".npmignore"), ` | ||
await Deno.copyFile("./readme.md", pathJoin(npm_dir, "readme.md")) | ||
await Deno.copyFile("./license.md", pathJoin(npm_dir, "license.md")) | ||
await Deno.copyFile("./.github/code_of_conduct.md", pathJoin(npm_dir, "code_of_conduct.md")) | ||
await Deno.writeTextFile(pathJoin(npm_dir, ".gitignore"), "/node_modules/\n") | ||
await Deno.writeTextFile(pathJoin(npm_dir, "tsconfig.json"), JSON.stringify(tsconfig_json)) | ||
await Deno.writeTextFile(pathJoin(npm_dir, ".npmignore"), ` | ||
code_of_conduct.md | ||
dist/ | ||
docs/ | ||
|
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 |
---|---|---|
@@ -1,32 +1,24 @@ | ||
/** some build specific utility functions */ | ||
import { ensureDir } from "https://deno.land/[email protected]/fs/mod.ts" | ||
import { join as pathJoin } from "https://deno.land/[email protected]/path/mod.ts" | ||
import { BuildOptions, PackageJson } from "https://deno.land/x/[email protected]/mod.ts" | ||
export type { | ||
BuildOptions as ESBuildOptions, | ||
OutputFile as ESOutputFile, | ||
TransformOptions as ESTransformOptions | ||
} from "https://deno.land/x/[email protected]/mod.js" | ||
export { build as dntBuild } from "jsr:@deno/[email protected]" | ||
export { copy as copyDir, emptyDir, ensureDir, ensureFile, walk as walkDir } from "jsr:@std/[email protected]" | ||
export { dirname as pathDirname, join as pathJoin, relative as relativePath } from "jsr:@std/[email protected]" | ||
import { | ||
BuildOptions as ESBuildOptions, | ||
OutputFile as ESOutputFile, | ||
TransformOptions as ESTransformOptions, | ||
build as esbuild, stop as esstop, transform as estransform | ||
} from "https://deno.land/x/[email protected]/mod.js" | ||
import { denoPlugins } from "https://deno.land/x/[email protected]/mod.ts" | ||
export { ensureDir, ensureFile, walk as walkDir } from "https://deno.land/[email protected]/fs/mod.ts" | ||
export { join as pathJoin, relative as relativePath } from "https://deno.land/[email protected]/path/mod.ts" | ||
export { stop as esstop } from "https://deno.land/x/[email protected]/mod.js" | ||
export type { | ||
BuildOptions as ESBuildOptions, | ||
OutputFile as ESOutputFile, | ||
TransformOptions as ESTransformOptions | ||
} from "https://deno.land/x/[email protected]/mod.js" | ||
} from "https://deno.land/x/[email protected]/mod.js" | ||
import { BuildOptions, PackageJson } from "jsr:@deno/[email protected]" | ||
import { denoPlugins } from "jsr:@luca/[email protected]" | ||
import { ensureDir } from "jsr:@std/[email protected]" | ||
import { join as pathJoin } from "jsr:@std/[email protected]" | ||
|
||
|
||
export const mainEntrypoint: string = "./src/mod.ts" | ||
export const subEntrypoints: string[] = [ | ||
"./src/binary_composition_steps.ts", | ||
"./src/binary_conditional_steps.ts", | ||
"./src/binary_primitive_steps.ts", | ||
"./src/typedefs.ts", | ||
] | ||
|
||
export interface LeftoverArtifacts { | ||
cleanup: () => Promise<void> | ||
} | ||
|
@@ -40,26 +32,33 @@ interface NPM_Artifacts extends TemporaryFiles { | |
files: ["package.json", "tsconfig.json"] | ||
} | ||
|
||
let deno_json: { [key: string]: any } | ||
const get_deno_json = async () => { return (await import("./deno.json", { with: { type: "json" } })).default } | ||
const add_leading_relative_path_slash = (path: string) => path.startsWith("./") ? path : "./" + path | ||
let deno_json: ReturnType<typeof get_deno_json> | ||
export const getDenoJson = async (base_dir: string = "./") => { | ||
deno_json ??= JSON.parse(await Deno.readTextFile(pathJoin(base_dir, "./deno.json"))) | ||
deno_json ??= (await import( | ||
add_leading_relative_path_slash(pathJoin(base_dir, "./deno.json")), | ||
{ with: { type: "json" } }) | ||
).default | ||
return deno_json | ||
} | ||
|
||
export const createPackageJson = async (deno_json_dir: string = "./", overrides: Partial<PackageJson> = {}): Promise<PackageJson> => { | ||
const { name, version, description, author, license, repository, bugs, devDependencies } = await getDenoJson(deno_json_dir) | ||
const { name, version, description, author, license, repository, bugs, exports, package_json } = await getDenoJson(deno_json_dir) | ||
// note that if you use dnt (deno-to-node), then you will have to delete the `exports` property, otherwise it will ruin the output. | ||
return { | ||
name: name ?? "", | ||
version: version ?? "0.0.0", | ||
description, author, license, repository, bugs, devDependencies, | ||
description, author, license, repository, bugs, exports, | ||
...package_json, | ||
...overrides | ||
} | ||
} | ||
|
||
export const createTSConfigJson = async (deno_json_dir: string = "./", overrides: Partial<{ compilerOptions: BuildOptions["compilerOptions"] }> = {}): Promise<{ "$schema": string, compilerOptions: BuildOptions["compilerOptions"] }> => { | ||
const { compilerOptions } = await getDenoJson(deno_json_dir) | ||
// remove "deno.ns" from compiler options, as it breaks `dnt` (I think) | ||
compilerOptions.lib = (compilerOptions.lib as string[]).filter((v) => v.toLowerCase() !== "deno.ns") | ||
compilerOptions.lib = (compilerOptions.lib).filter((v) => v.toLowerCase() !== "deno.ns") | ||
Object.assign(compilerOptions, | ||
{ | ||
target: "ESNext", | ||
|
@@ -74,7 +73,7 @@ export const createTSConfigJson = async (deno_json_dir: string = "./", overrides | |
"$schema": "https://json.schemastore.org/tsconfig", | ||
...overrides, | ||
compilerOptions, | ||
} | ||
} as any | ||
} | ||
|
||
export const createNPMFiles = async ( | ||
|
@@ -136,7 +135,7 @@ export const doubleCompileFiles = async ( | |
}) | ||
|
||
const bundled_files = await Promise.all(bundled_code.outputFiles.map( | ||
async ({ text, path }, file_number): Promise<ESOutputFile> => { | ||
async ({ text, path, hash }, file_number): Promise<ESOutputFile> => { | ||
const | ||
js_text = (await estransform(text, { | ||
minify: true, | ||
|
@@ -149,6 +148,7 @@ export const doubleCompileFiles = async ( | |
console.log("bundled file", file_number, "\n\t", "output path:", path, "\n\t", "binary size:", js_text_uint8.byteLength / 1024, "kb") | ||
return { | ||
path, | ||
hash, | ||
text: js_text, | ||
contents: js_text_uint8 | ||
} | ||
|
Oops, something went wrong.