Skip to content

Commit

Permalink
add final touches. ready to publish on https://jsr.io`
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-azmi committed Mar 3, 2024
1 parent dce90be commit 567adc9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
14 changes: 8 additions & 6 deletions build_docs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { copy as copyFolder, ensureFile } from "https://deno.land/std@0.204.0/fs/mod.ts"
import { dirname as pathDirname, join as pathJoin } from "https://deno.land/std@0.204.0/path/mod.ts"
import { Application as typedocApp } from "npm:typedoc"
import { TemporaryFiles, createNPMFiles, doubleCompileFiles, getDenoJson } from "./build_tools.ts"
import { Application as typedocApp } from "npm:typedoc@0.25.9"
import {
TemporaryFiles, copyFolder, createNPMFiles, doubleCompileFiles,
ensureFile, getDenoJson, pathDirname, pathJoin,
} from "./build_tools.ts"


/** use:
Expand Down Expand Up @@ -41,9 +42,10 @@ 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({
// 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,
Expand Down Expand Up @@ -75,7 +77,7 @@ await copyFolder("./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 = (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 }))[0]
js_dist.path = pathJoin(pathDirname(js_dist.path), "./esm.js")
js_dist_minified.path = pathJoin(pathDirname(js_dist_minified.path), "./esm.min.js")
Expand Down
21 changes: 8 additions & 13 deletions build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
exports,
node_packageManager,
} = await getDenoJson(deno_json_dir)
const { ".": mainEntrypoint, ...subEntrypoints } = exports
const mainEntrypoint = exports["."]

const package_json = await createPackageJson(deno_json_dir, {
scripts: {
Expand All @@ -17,22 +17,18 @@ const package_json = await createPackageJson(deno_json_dir, {
"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)

await emptyDir(npm_dir)
await dntBuild({
entryPoints: [
mainEntrypoint,
...Object.entries(subEntrypoints).map(([export_path, source_path]) => ({
name: export_path,
path: source_path,
})),
],
entryPoints: Object.entries(exports).map(([export_path, source_path]) => ({
name: export_path,
path: source_path,
})),
outDir: npm_dir,
shims: { deno: true },
shims: { deno: "dev" },
packageManager: node_packageManager,
package: {
...package_json
Expand All @@ -46,9 +42,8 @@ await dntBuild({
})

// copy other files
await Deno.copyFile("./src/readme.md", pathJoin(npm_dir, "./src/readme.md"))
await Deno.copyFile("./src/readme.md", pathJoin(npm_dir, "readme.md"))
await Deno.copyFile("./src/license.md", pathJoin(npm_dir, "license.md"))
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))
Expand Down
25 changes: 14 additions & 11 deletions build_tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** some build specific utility functions */
import { BuildOptions, PackageJson } from "https://deno.land/x/dnt@0.38.1/mod.ts"
import { BuildOptions, PackageJson } from "https://deno.land/x/dnt@0.40.0/mod.ts"
import {
BuildOptions as ESBuildOptions,
OutputFile as ESOutputFile,
Expand All @@ -9,9 +9,9 @@ import {
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@0.9.0"
import { ensureDir } from "jsr:@std/fs@0.218.2"
import { join as pathJoin } from "jsr:@std/path@0.218.2"
export { build as dntBuild } from "https://deno.land/x/dnt@0.38.1/mod.ts"
export { emptyDir, ensureDir, ensureFile } from "jsr:@std/fs@0.218.2"
export { join as pathJoin } from "jsr:@std/path@0.218.2"
export { build as dntBuild } from "https://deno.land/x/dnt@0.40.0/mod.ts"
export { copy as copyFolder, emptyDir, ensureDir, ensureFile } from "jsr:@std/fs@0.218.2"
export { dirname as pathDirname, join as pathJoin } from "jsr:@std/path@0.218.2"


export interface LeftoverArtifacts {
Expand Down Expand Up @@ -39,11 +39,13 @@ export const getDenoJson = async (base_dir: string = "./") => {
}

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, devDependencies } = await getDenoJson(deno_json_dir)
// note that if you use dnt (deno-to-node), then `exports` will get overwritten
return {
name: name ?? "",
version: version ?? "0.0.0",
description, author, license, repository, bugs, devDependencies,
description, author, license, repository,
bugs, devDependencies, exports,
...overrides
}
}
Expand Down Expand Up @@ -108,8 +110,9 @@ export const createNPMFiles = async (
export const doubleCompileFiles = async (
compile_file_path: string,
out_dir: string,
overrid_bundle_options: ESBuildOptions = {},
overrid_minify_options: ESTransformOptions = {},
override_bundle_options: ESBuildOptions = {},
override_minify_options: ESTransformOptions = {},
stop: boolean = true
) => {
let t0 = performance.now(), t1: number

Expand All @@ -122,7 +125,7 @@ export const doubleCompileFiles = async (
format: "esm",
target: "esnext",
plugins: [...denoPlugins()],
...overrid_bundle_options,
...override_bundle_options,
write: false,
})

Expand All @@ -134,7 +137,7 @@ export const doubleCompileFiles = async (
platform: "browser",
format: "esm",
target: "esnext",
...overrid_minify_options
...override_minify_options
})).code,
js_text_uint8 = (new TextEncoder()).encode(js_text)
console.log("bundled file", file_number, "\n\t", "output path:", path, "\n\t", "binary size:", js_text_uint8.byteLength / 1024, "kb")
Expand All @@ -147,7 +150,7 @@ export const doubleCompileFiles = async (
}
))

esstop()
if (stop) { esstop() }
t1 = performance.now()
console.log("bundling time:", t1 - t0, "ms")
return bundled_files
Expand Down
5 changes: 4 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"publish": {
"include": [
"./src/",
"./readme.md",
"./license.md",
"./deno.json"
]
},
Expand Down Expand Up @@ -78,6 +80,7 @@
"build-npm": "deno run -A ./build_npm.ts",
"build-npm-dist": "cd \"./npm/\" && npm run build-dist",
"clean": "deno run -A ./clean.ts",
"test": "deno test -A"
"test": "deno test -A",
"publish-jsr": "deno publish"
}
}
12 changes: 7 additions & 5 deletions src/array2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export const transposeArray2D: TransposeArray2D_Signatures = <T>(arr2d: Array2D<
* @param insert_items optionally insert row-major based 2D array items the index of `start`.
* @returns a new row-major 2D array containing the deleted rows.
*
* @example delete `1` row from `arr2d` (starting at row-index `1`), and insert `2` new rows in its place
* @example
* delete `1` row from `arr2d` (starting at row-index `1`), and insert `2` new rows in its place.
* ```ts
* const arr2d: Array2DRowMajor<number> = [
* [1 , 2 , 3 , 4 , 5 ],
Expand Down Expand Up @@ -136,7 +137,8 @@ export const spliceArray2DMajor = <T>(arr2d: Array2DRowMajor<T>, start: number,
* @param insert_items optionally insert column-major based 2D array items the index of `start`.
* @returns a new column-major 2D array containing the deleted columns.
*
* @example delete `2` columns from `arr2d` (starting at column-index `1`), and insert `5` new columns in its place
* @example
* delete `2` columns from `arr2d` (starting at column-index `1`), and insert `5` new columns in its place.
* ```ts
* const arr2d: Array2DRowMajor<number> = [
* [1 , 2 , 3 , 4 , 5 ],
Expand Down Expand Up @@ -298,9 +300,9 @@ export const meshGrid = <T>(major_values: Array<T>, minor_values: Array<T>): [ma
* @param y_values the values to be used as the minor axis (columns) of the resulting 2D array
* @returns a 2D array with mapped values from `x_values` and `y_values`
*
* @example `z` is a function of `x` and `y` defined by: `z(x, y) = x + y`.
* to create a 2d grid of `z_values` using `x_values = [1, 2, 3]` and `y_values = [4, 5]`,
* we do the following:
* @example
* `z` is a function of `x` and `y` defined by: `z(x, y) = x + y`. <br>
* to create a 2d grid of `z_values` using `x_values = [1, 2, 3]` and `y_values = [4, 5]`, we do the following:
* ```ts
* const
* add = (x: number, y: number) => (x + y),
Expand Down

0 comments on commit 567adc9

Please sign in to comment.