-
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.
- add a few missing doc comments to boost jsr score.
- in `/examples/1_html/build.ts`: - add option for dry-running the build script (no writes done to filesystem). - make sure that the output directory is first emptied.
- Loading branch information
Showing
3 changed files
with
27 additions
and
15 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { denoPlugins } from "jsr:@luca/[email protected]" | ||
import { emptyDir } from "jsr:@std/fs" | ||
import { fromFileUrl } from "jsr:@std/path" | ||
import esbuild from "npm:esbuild" | ||
import { resolveAsUrl } from "../../src/deps.ts" | ||
|
@@ -7,6 +8,7 @@ import { HtmlLoader } from "./loader.ts" | |
|
||
|
||
const | ||
dryrun = false, | ||
this_dir_path = resolveAsUrl("./", import.meta.url), | ||
html_file_path = resolveAsUrl("./input/index.html", this_dir_path), | ||
html_file_content = await (await fetch(html_file_path)).text() | ||
|
@@ -46,13 +48,16 @@ other_output_files.forEach((js_file, index) => { | |
console.log(js_file.text) | ||
}) | ||
|
||
const abs_output_dir = fromFileUrl(resolveAsUrl("./output/", this_dir_path)) | ||
console.log(`clearing out the output directory: "${abs_output_dir}"`) | ||
if (!dryrun) { await emptyDir(abs_output_dir) } | ||
await writeOutputFiles([ | ||
{ | ||
path: html_in_js_compiled.path.replace(/\.js$/, ".html"), | ||
text: html_compiled_text | ||
}, ...other_output_files | ||
], { | ||
dir: "./output/", | ||
dir: abs_output_dir, | ||
log: "verbose", | ||
dryrun: false, | ||
dryrun, | ||
}) |
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 |
---|---|---|
|
@@ -8,15 +8,14 @@ | |
|
||
import { ensureFile } from "jsr:@std/[email protected]" | ||
import { console_log, ensureEndSlash, pathToPosixPath, promise_all, resolvePathFactory } from "./deps.ts" | ||
import type { AbsolutePath, Path, RelativePath } from "./typedefs.ts" | ||
|
||
|
||
/** get the current working directory (`Deno.cwd`) in posix path format. */ | ||
export const getCwdPath = (): string => { return ensureEndSlash(pathToPosixPath(Deno.cwd())) } | ||
export const getCwdPath = (): AbsolutePath => { return ensureEndSlash(pathToPosixPath(Deno.cwd())) } | ||
|
||
/** resolve a file path so that it becomes absolute, with unix directory separator ("/"). | ||
* TODO: refactor the name `pathResolve` to `resolvePath` | ||
*/ | ||
export const pathResolve: ((...segments: string[]) => string) = resolvePathFactory(getCwdPath) | ||
/** resolve a file path so that it becomes absolute, with unix directory separator ("/"). */ | ||
export const resolvePath: ((...segments: Path[]) => AbsolutePath) = resolvePathFactory(getCwdPath) | ||
|
||
/** the tuple description of a writable (or appendable) file. | ||
* - the first entry of the array must describe the destination path of the file, | ||
|
@@ -26,7 +25,7 @@ export const pathResolve: ((...segments: string[]) => string) = resolvePathFacto | |
* such as `"append"` the new text, or permit the creation (`"create"`) of new file if it doesn't exist, etc... | ||
*/ | ||
export type WritableFileConfig = [ | ||
destination: string, | ||
destination: RelativePath, | ||
content: string | Uint8Array, | ||
options?: Deno.WriteFileOptions, | ||
] | ||
|
@@ -36,7 +35,7 @@ export interface CreateFilesConfig { | |
/** the desired output directory. | ||
* if a relative path is provided, then it will be resolved as a path relative to Deno's current working directory. (which is generally where `deno.json` resides.) | ||
*/ | ||
dir?: string | ||
dir?: Path | ||
|
||
/** select logging level: | ||
* - `false` or `"none"`: skip logging. | ||
|
@@ -56,7 +55,7 @@ export interface CreateFilesConfig { | |
|
||
/** the in-memory output file description generated by `esbuild`. */ | ||
export interface EsbuildOutputFile { | ||
path: string | ||
path: AbsolutePath | ||
text?: string | ||
contents?: Uint8Array | ||
hash?: string | ||
|
@@ -85,7 +84,7 @@ export const createFiles = async (virtual_files: Array<WritableFileConfig>, conf | |
// writing text or binary files | ||
logBasic(log, "[in-fs] writing additional text/binary files to your build directory") | ||
await promise_all(virtual_files.map(async ([dst_path, content, options]) => { | ||
const abs_dst = pathResolve(dir, dst_path) | ||
const abs_dst = resolvePath(dir, dst_path) | ||
logVerbose(log, `[in-fs] writing file to: "${abs_dst}"`, "with the configuration:", options) | ||
if (!dryrun) { | ||
await ensureFile(abs_dst) | ||
|
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