@weborigami/origami 0.0.73 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/main.js +12 -0
  2. package/package.json +5 -7
  3. package/src/builtins.js +62 -0
  4. package/src/builtinsTree.js +36 -0
  5. package/src/calc/calc.js +61 -0
  6. package/src/cli/cli.js +6 -4
  7. package/src/{misc → common}/assertTreeIsDefined.js +4 -1
  8. package/src/common/constructHref.js +20 -0
  9. package/src/common/constructSiteTree.js +34 -0
  10. package/src/common/fetchAndHandleExtension.js +26 -0
  11. package/src/{misc → common}/getTreeArgument.js +11 -5
  12. package/src/common/processUnpackedContent.js +4 -13
  13. package/src/common/utilities.d.ts +0 -1
  14. package/src/common/utilities.js +3 -30
  15. package/src/deprecated.js +140 -0
  16. package/src/{common → dev}/ExplorableSiteTransform.js +1 -1
  17. package/src/{misc → dev}/OriCommandTransform.js +2 -2
  18. package/src/{builtins/@code.js → dev/code.js} +2 -2
  19. package/src/{builtins/@debug.js → dev/debug.js} +4 -7
  20. package/src/dev/dev.js +9 -0
  21. package/src/{builtins/@explore.js → dev/explore.js} +22 -28
  22. package/src/{misc → dev}/explore.js.inline +4 -4
  23. package/src/{misc → dev}/explore.ori +3 -3
  24. package/src/{builtins/@log.js → dev/log.js} +1 -1
  25. package/src/{builtins/@serve.js → dev/serve.js} +5 -8
  26. package/src/{builtins/@svg.js → dev/svg.js} +9 -6
  27. package/src/{misc → dev}/treeDot.js +0 -3
  28. package/src/{builtins/@watch.js → dev/watch.js} +8 -6
  29. package/src/handlers/handlerExports.js +16 -0
  30. package/src/handlers/handlers.js +37 -0
  31. package/src/{builtins → handlers}/js.handler.js +1 -1
  32. package/src/{builtins → handlers}/json.handler.js +9 -1
  33. package/src/handlers/mjs.handler.js +2 -0
  34. package/src/{builtins → handlers}/ori.handler.js +5 -7
  35. package/src/{builtins → handlers}/oridocument.handler.js +1 -1
  36. package/src/{builtins → handlers}/wasm.handler.js +1 -1
  37. package/src/{builtins → handlers}/yaml.handler.js +8 -1
  38. package/src/handlers/yml.handler.js +2 -0
  39. package/src/help/help.js +103 -0
  40. package/src/help/help.yaml +425 -0
  41. package/src/{builtins/@image → image}/format.js +2 -2
  42. package/src/{builtins/@image → image}/formatFn.js +1 -1
  43. package/src/image/image.js +2 -0
  44. package/src/{builtins/@image → image}/resize.js +2 -2
  45. package/src/{builtins/@image → image}/resizeFn.js +1 -1
  46. package/src/internal.js +24 -0
  47. package/src/{builtins/@js.js → js.js} +7 -6
  48. package/src/{builtins/@node.js → node.js} +1 -6
  49. package/src/{builtins/@basename.js → origami/basename.js} +2 -2
  50. package/src/{builtins/@config.js → origami/config.js} +1 -4
  51. package/src/{builtins/@json.js → origami/json.js} +2 -5
  52. package/src/{builtins/@jsonParse.js → origami/jsonParse.js} +0 -3
  53. package/src/{builtins/@once.js → origami/once.js} +2 -2
  54. package/src/{builtins/@ori.js → origami/ori.js} +4 -7
  55. package/src/origami/origami.js +29 -0
  56. package/src/{builtins/@pack.js → origami/pack.js} +2 -2
  57. package/src/{builtins/@project.js → origami/project.js} +7 -11
  58. package/src/{builtins/@regexMatch.js → origami/regexMatch.js} +1 -1
  59. package/src/origami/repeat.js +5 -0
  60. package/src/{builtins/@shell.js → origami/shell.js} +0 -3
  61. package/src/{builtins/@stdin.js → origami/stdin.js} +0 -3
  62. package/src/{builtins/@string.js → origami/string.js} +2 -2
  63. package/src/{builtins/@unpack.js → origami/unpack.js} +2 -2
  64. package/src/{builtins/@yaml.js → origami/yaml.js} +2 -5
  65. package/src/{builtins/@yamlParse.js → origami/yamlParse.js} +0 -3
  66. package/src/protocols/explore.js +19 -0
  67. package/src/{builtins/@files.js → protocols/files.js} +2 -5
  68. package/src/protocols/http.js +18 -0
  69. package/src/protocols/https.js +18 -0
  70. package/src/protocols/httpstree.js +19 -0
  71. package/src/protocols/httptree.js +19 -0
  72. package/src/protocols/inherited.js +18 -0
  73. package/src/protocols/new.js +42 -0
  74. package/src/{builtins/@package.js → protocols/package.js} +2 -2
  75. package/src/protocols/scope.js +14 -0
  76. package/src/server/constructResponse.js +5 -5
  77. package/src/{builtins/@siteAudit.js → site/audit.js} +4 -4
  78. package/src/{builtins/@crawl.js → site/crawler/crawl.js} +3 -6
  79. package/src/{crawler → site/crawler}/findPaths.js +2 -3
  80. package/src/{crawler → site/crawler}/utilities.js +2 -3
  81. package/src/{builtins/@index.js → site/index.js} +2 -5
  82. package/src/{builtins/@jsonKeys.js → site/jsonKeys.js} +5 -5
  83. package/src/{builtins/@rss.js → site/rss.js} +2 -5
  84. package/src/site/site.js +9 -0
  85. package/src/{builtins/@sitemap.js → site/sitemap.js} +8 -12
  86. package/src/{builtins/@static.js → site/static.js} +7 -7
  87. package/src/{builtins/@document.js → text/document.js} +2 -2
  88. package/src/{builtins/@inline.js → text/inline.js} +10 -13
  89. package/src/{builtins/@mdHtml.js → text/mdHtml.js} +7 -10
  90. package/src/text/origamiHighlightDefinition.js +53 -0
  91. package/src/text/text.js +4 -0
  92. package/src/{builtins/@addNextPrevious.js → tree/addNextPrevious.js} +7 -2
  93. package/src/{builtins/@cache.js → tree/cache.js} +2 -5
  94. package/src/{builtins/@clean.js → tree/clear.js} +4 -4
  95. package/src/{builtins/@concat.js → tree/concat.js} +2 -5
  96. package/src/{builtins/@copy.js → tree/copy.js} +3 -10
  97. package/src/{builtins/@deepMapFn.js → tree/deepMap.js} +13 -6
  98. package/src/{builtins/@deepMerge.js → tree/deepMerge.js} +4 -7
  99. package/src/{builtins/@deepReverse.js → tree/deepReverse.js} +8 -2
  100. package/src/tree/deepTake.js +26 -0
  101. package/src/{builtins/@deepValues.js → tree/deepValues.js} +2 -6
  102. package/src/{builtins/@defineds.js → tree/defineds.js} +7 -2
  103. package/src/{builtins/@filter.js → tree/filter.js} +3 -6
  104. package/src/{builtins/@first.js → tree/first.js} +2 -5
  105. package/src/{builtins/@fnTree.js → tree/fromFn.js} +3 -6
  106. package/src/{builtins/@globs.js → tree/globs.js} +3 -6
  107. package/src/tree/group.js +26 -0
  108. package/src/{builtins/@inners.js → tree/inners.js} +2 -5
  109. package/src/{builtins/@keys.js → tree/keys.js} +2 -5
  110. package/src/{builtins/@length.js → tree/length.js} +2 -2
  111. package/src/{builtins → tree}/map.d.ts +3 -6
  112. package/src/tree/map.js +154 -0
  113. package/src/{builtins/@mapFn.js → tree/mapFn.js} +14 -6
  114. package/src/{builtins/@match.js → tree/match.js} +2 -5
  115. package/src/{builtins/@merge.js → tree/merge.js} +2 -5
  116. package/src/tree/paginate.js +61 -0
  117. package/src/{builtins/@parent.js → tree/parent.js} +2 -5
  118. package/src/{builtins/@plain.js → tree/plain.js} +2 -5
  119. package/src/{builtins/@reverse.js → tree/reverse.js} +2 -5
  120. package/src/{builtins/@setDeep.js → tree/setDeep.js} +0 -3
  121. package/src/{builtins/@shuffle.js → tree/shuffle.js} +3 -9
  122. package/src/{builtins/@sortFn.js → tree/sort.js} +12 -17
  123. package/src/tree/take.js +19 -0
  124. package/src/tree/tree.js +49 -0
  125. package/src/{builtins/@values.js → tree/values.js} +2 -5
  126. package/exports/PathTransform.d.ts +0 -5
  127. package/exports/PathTransform.js +0 -20
  128. package/exports/buildExports.js +0 -112
  129. package/exports/exports.js +0 -148
  130. package/src/builtins/@builtins.js +0 -15
  131. package/src/builtins/@deepMap.js +0 -19
  132. package/src/builtins/@deepTake.js +0 -21
  133. package/src/builtins/@deepTakeFn.js +0 -21
  134. package/src/builtins/@equals.js +0 -6
  135. package/src/builtins/@exploreSite.js +0 -16
  136. package/src/builtins/@false.js +0 -1
  137. package/src/builtins/@fetch.js +0 -7
  138. package/src/builtins/@group.js +0 -20
  139. package/src/builtins/@groupFn.js +0 -33
  140. package/src/builtins/@help.js +0 -49
  141. package/src/builtins/@http.js +0 -19
  142. package/src/builtins/@https.js +0 -19
  143. package/src/builtins/@if.js +0 -28
  144. package/src/builtins/@inherited.js +0 -17
  145. package/src/builtins/@map.js +0 -19
  146. package/src/builtins/@math.js +0 -17
  147. package/src/builtins/@not.js +0 -6
  148. package/src/builtins/@or.js +0 -6
  149. package/src/builtins/@paginate.js +0 -18
  150. package/src/builtins/@paginateFn.js +0 -58
  151. package/src/builtins/@repeat.js +0 -8
  152. package/src/builtins/@sort.js +0 -23
  153. package/src/builtins/@table.js +0 -69
  154. package/src/builtins/@take.js +0 -20
  155. package/src/builtins/@takeFn.js +0 -20
  156. package/src/builtins/@tree.js +0 -4
  157. package/src/builtins/@treeHttp.js +0 -19
  158. package/src/builtins/@treeHttps.js +0 -19
  159. package/src/builtins/@true.js +0 -1
  160. package/src/builtins/mjs.handler.js +0 -2
  161. package/src/builtins/yml.handler.js +0 -2
  162. package/src/builtins/~.js +0 -9
  163. package/src/cli/showUsage.js +0 -86
  164. package/src/common/CommandModulesTransform.d.ts +0 -5
  165. package/src/common/CommandModulesTransform.js +0 -39
  166. package/src/common/arrowsMapFn.js +0 -35
  167. package/src/misc/origamiHighlightDefinition.js +0 -36
  168. /package/src/{misc → common}/assertTreeIsDefined.d.ts +0 -0
  169. /package/src/{common → dev}/ExplorableSiteTransform.d.ts +0 -0
  170. /package/src/{misc → dev}/OriCommandTransform.d.ts +0 -0
  171. /package/src/{builtins/@breakpoint.js → dev/breakpoint.js} +0 -0
  172. /package/src/{builtins/@changes.js → dev/changes.js} +0 -0
  173. /package/src/{misc → dev}/explore.css +0 -0
  174. /package/src/{builtins → handlers}/css.handler.js +0 -0
  175. /package/src/{builtins → handlers}/htm.handler.js +0 -0
  176. /package/src/{builtins → handlers}/html.handler.js +0 -0
  177. /package/src/{builtins → handlers}/jpeg.handler.js +0 -0
  178. /package/src/{builtins → handlers}/jpg.handler.js +0 -0
  179. /package/src/{builtins → handlers}/md.handler.js +0 -0
  180. /package/src/{builtins → handlers}/txt.handler.js +0 -0
  181. /package/src/{builtins → handlers}/xhtml.handler.js +0 -0
  182. /package/src/{builtins/@naturalOrder.js → origami/naturalOrder.js} +0 -0
  183. /package/src/{builtins/@post.js → origami/post.js} +0 -0
  184. /package/src/{builtins/@regexMatchFn.js → origami/regexMatchFn.js} +0 -0
  185. /package/src/{builtins/@slash.js → origami/slash.js} +0 -0
  186. /package/src/{builtins/@version.js → origami/version.js} +0 -0
  187. /package/src/{crawler → site/crawler}/crawlResources.js +0 -0
  188. /package/src/{builtins/@redirect.js → site/redirect.js} +0 -0
  189. /package/src/{builtins/@slug.js → site/slug.js} +0 -0
  190. /package/src/{builtins/@indent.js → text/indent.js} +0 -0
  191. /package/src/{common → tree}/FilterTree.js +0 -0
  192. /package/src/{common → tree}/GlobTree.js +0 -0
  193. /package/src/{common → tree}/ShuffleTransform.js +0 -0
  194. /package/src/{builtins/@calendarTree.js → tree/calendar.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  import { Tree } from "@weborigami/async-tree";
2
- import ExplorableSiteTransform from "../common/ExplorableSiteTransform.js";
2
+ import getTreeArgument from "../common/getTreeArgument.js";
3
3
  import { isTransformApplied, transformObject } from "../common/utilities.js";
4
- import OriCommandTransform from "../misc/OriCommandTransform.js";
5
- import getTreeArgument from "../misc/getTreeArgument.js";
4
+ import ExplorableSiteTransform from "./ExplorableSiteTransform.js";
5
+ import OriCommandTransform from "./OriCommandTransform.js";
6
6
 
7
7
  /**
8
8
  * Add debugging features to the indicated tree.
@@ -16,7 +16,7 @@ import getTreeArgument from "../misc/getTreeArgument.js";
16
16
  export default async function debug(treelike) {
17
17
  // The debug command leaves the tree's existing scope intact; it does not
18
18
  // apply its own scope to the tree.
19
- let tree = await getTreeArgument(this, arguments, treelike, "@debug");
19
+ let tree = await getTreeArgument(this, arguments, treelike, "dev:debug");
20
20
 
21
21
  if (!isTransformApplied(DebugTransform, tree)) {
22
22
  tree = transformObject(DebugTransform, tree);
@@ -69,6 +69,3 @@ function DebugTransform(Base) {
69
69
  }
70
70
  };
71
71
  }
72
-
73
- debug.usage = `@debug <tree>\tAdd debug features to a tree`;
74
- debug.documentation = "https://weborigami.org/language/@debug.html";
package/src/dev/dev.js ADDED
@@ -0,0 +1,9 @@
1
+ export { default as breakpoint } from "./breakpoint.js";
2
+ export { default as changes } from "./changes.js";
3
+ export { default as code } from "./code.js";
4
+ export { default as debug } from "./debug.js";
5
+ export { default as explore } from "./explore.js";
6
+ export { default as log } from "./log.js";
7
+ export { default as serve } from "./serve.js";
8
+ export { default as svg } from "./svg.js";
9
+ export { default as watch } from "./watch.js";
@@ -1,29 +1,31 @@
1
1
  /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
2
  import { Tree, scope } from "@weborigami/async-tree";
3
3
  import { OrigamiFiles } from "@weborigami/language";
4
- import builtins from "../builtins/@builtins.js";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
5
7
  import { keySymbol } from "../common/utilities.js";
6
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
7
- import debug from "./@debug.js";
8
+ import { builtinsTree } from "../internal.js";
9
+ import debug from "./debug.js";
8
10
 
9
- const miscUrl = new URL("../misc", import.meta.url);
10
- const miscFiles = new OrigamiFiles(miscUrl);
11
- miscFiles.parent = builtins;
11
+ let templatePromise;
12
12
 
13
13
  /**
14
14
  * @this {AsyncTree|null}
15
15
  */
16
16
  export default async function explore(...keys) {
17
- assertTreeIsDefined(this, "explore");
17
+ assertTreeIsDefined(this, "origami:explore");
18
18
  if (!this) {
19
19
  return undefined;
20
20
  }
21
21
 
22
+ const tree = Tree.from(this);
23
+
22
24
  /** @type {any} */
23
25
  let result;
24
26
  if (keys.length > 0) {
25
27
  // Traverse the scope using the given keys.
26
- const debugTree = await debug.call(this, this);
28
+ const debugTree = await debug.call(tree, this);
27
29
  if (!debugTree) {
28
30
  return undefined;
29
31
  }
@@ -39,37 +41,23 @@ export default async function explore(...keys) {
39
41
  result = await Tree.traverse(debugScope, ...keys);
40
42
  } else {
41
43
  // Return the Explore page for the current scope.
42
- const templateFile = await miscFiles.get("explore.ori");
43
- const template = await templateFile.unpack();
44
-
45
- const data = await getScopeData(scope(this));
44
+ const data = await getScopeData(scope(tree));
45
+ templatePromise ??= loadTemplate();
46
+ const template = await templatePromise;
46
47
  const text = await template(data);
47
48
 
48
49
  result = new String(text);
49
- const tree = this;
50
50
  result.unpack = () => debug.call(tree, tree);
51
51
  }
52
52
 
53
53
  return result;
54
54
  }
55
55
 
56
- // To test if a given tree represents the builtins, we walk up the chain to see
57
- // if any of its prototypes are the builtins tree.
58
- function isBuiltins(tree) {
59
- while (tree) {
60
- if (tree === builtins) {
61
- return true;
62
- }
63
- tree = Object.getPrototypeOf(tree);
64
- }
65
- return false;
66
- }
67
-
68
56
  async function getScopeData(scope) {
69
57
  const trees = scope.trees ?? [scope];
70
58
  const data = [];
71
59
  for (const tree of trees) {
72
- if (isBuiltins(tree)) {
60
+ if (tree.parent === undefined) {
73
61
  // Skip builtins.
74
62
  continue;
75
63
  }
@@ -82,5 +70,11 @@ async function getScopeData(scope) {
82
70
  return data;
83
71
  }
84
72
 
85
- explore.usage = "@explore\tExplore the current scope in the browser";
86
- explore.documentation = "https://weborigami.org/language/@explore.html";
73
+ async function loadTemplate() {
74
+ const folderPath = path.resolve(fileURLToPath(import.meta.url), "..");
75
+ const folder = new OrigamiFiles(folderPath);
76
+ folder.parent = builtinsTree;
77
+ const templateFile = await folder.get("explore.ori");
78
+ const template = await templateFile.unpack();
79
+ return template;
80
+ }
@@ -3,9 +3,9 @@ let frame;
3
3
 
4
4
  const modes = {
5
5
  Content: "",
6
- Index: "!@index",
7
- YAML: "!@yaml",
8
- SVG: "!@svg",
6
+ Index: "!index",
7
+ YAML: "!yaml",
8
+ SVG: "!svg",
9
9
  };
10
10
 
11
11
  // Extract the path from the URL hash.
@@ -15,7 +15,7 @@ function getPathFromHash() {
15
15
 
16
16
  function getModeFromLocation() {
17
17
  const href = document.location.href;
18
- const match = /[\/](?<command>\!(?:@index|@yaml|@svg))$/.exec(href);
18
+ const match = /[\/](?<command>\!(?:index|yaml|svg))$/.exec(href);
19
19
  const command = match?.groups?.command ?? "";
20
20
  const mode =
21
21
  Object.keys(modes).find((key) => modes[key] === command) ?? "Content";
@@ -16,12 +16,12 @@
16
16
  <button id="buttonSVG">SVG</button>
17
17
  <button id="buttonYAML">YAML</button>
18
18
  </div>
19
- ${ @map(scope, (scopeTree) => `
19
+ ${ map(scope, (scopeTree) => `
20
20
  <ul>
21
21
  <h2>${ scopeTree/name }</h2>
22
- ${ @map(scopeTree/keys, (key) => `
22
+ ${ map(scopeTree/keys, (key) => `
23
23
  <li>
24
- <a href="./!@explore/${ key }" target="frame">${ key }</a>
24
+ <a href="./!explore/${ key }" target="frame">${ key }</a>
25
25
  </li>
26
26
  `) }
27
27
  </ul>
@@ -1,4 +1,4 @@
1
- import yaml from "./@yaml.js";
1
+ import yaml from "../origami/yaml.js";
2
2
 
3
3
  /**
4
4
  * Log the first argument to the console as a side effect and return the second
@@ -2,12 +2,12 @@ import { Tree } from "@weborigami/async-tree";
2
2
  import http from "node:http";
3
3
  import { createServer } from "node:net";
4
4
  import process from "node:process";
5
- import ExplorableSiteTransform from "../common/ExplorableSiteTransform.js";
5
+ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
6
6
  import { isTransformApplied, transformObject } from "../common/utilities.js";
7
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
8
7
  import { requestListener } from "../server/server.js";
9
- import debug from "./@debug.js";
10
- import watch from "./@watch.js";
8
+ import debug from "./debug.js";
9
+ import ExplorableSiteTransform from "./ExplorableSiteTransform.js";
10
+ import watch from "./watch.js";
11
11
 
12
12
  const defaultPort = 5000;
13
13
 
@@ -22,7 +22,7 @@ const defaultPort = 5000;
22
22
  * @this {AsyncTree|null}
23
23
  */
24
24
  export default async function serve(treelike, port) {
25
- assertTreeIsDefined(this, "serve");
25
+ assertTreeIsDefined(this, "dev:serve");
26
26
  let tree;
27
27
  if (treelike) {
28
28
  tree = Tree.from(treelike, { parent: this });
@@ -66,6 +66,3 @@ function findOpenPort(port) {
66
66
  .listen(port)
67
67
  );
68
68
  }
69
-
70
- serve.usage = `@serve <tree>, [port]\tStart a web server for the tree`;
71
- serve.documentation = "https://weborigami.org/language/@serve.html";
@@ -1,6 +1,6 @@
1
1
  import graphviz from "graphviz-wasm";
2
- import getTreeArgument from "../misc/getTreeArgument.js";
3
- import dot from "../misc/treeDot.js";
2
+ import getTreeArgument from "../common/getTreeArgument.js";
3
+ import dot from "./treeDot.js";
4
4
 
5
5
  let graphvizLoaded = false;
6
6
 
@@ -20,7 +20,13 @@ export default async function svg(treelike, options = {}) {
20
20
  await graphviz.loadWASM();
21
21
  graphvizLoaded = true;
22
22
  }
23
- const tree = await getTreeArgument(this, arguments, treelike, "@svg", true);
23
+ const tree = await getTreeArgument(
24
+ this,
25
+ arguments,
26
+ treelike,
27
+ "dev:svg",
28
+ true
29
+ );
24
30
  const dotText = await dot.call(this, tree, options);
25
31
  if (dotText === undefined) {
26
32
  return undefined;
@@ -32,6 +38,3 @@ export default async function svg(treelike, options = {}) {
32
38
  result.unpack = () => tree;
33
39
  return result;
34
40
  }
35
-
36
- svg.usage = `@svg <tree>\tRender a tree visually as in SVG format`;
37
- svg.documentation = "https://weborigami.org/language/@svg.html";
@@ -191,6 +191,3 @@ function stringDiff(first, second) {
191
191
  }
192
192
  return second.slice(i);
193
193
  }
194
-
195
- dot.usage = `dot <tree>\tRender a tree visually in dot language`;
196
- dot.documentation = "https://weborigami.org/cli/builtins.html#dot";
@@ -1,7 +1,7 @@
1
1
  import { Tree } from "@weborigami/async-tree";
2
2
  import { formatError } from "@weborigami/language";
3
3
  import ConstantTree from "../common/ConstantTree.js";
4
- import getTreeArgument from "../misc/getTreeArgument.js";
4
+ import getTreeArgument from "../common/getTreeArgument.js";
5
5
 
6
6
  /**
7
7
  * Let a tree (e.g., of files) respond to changes.
@@ -16,7 +16,12 @@ import getTreeArgument from "../misc/getTreeArgument.js";
16
16
  */
17
17
  export default async function watch(treelike, fn) {
18
18
  /** @type {any} */
19
- const container = await getTreeArgument(this, arguments, treelike, "@watch");
19
+ const container = await getTreeArgument(
20
+ this,
21
+ arguments,
22
+ treelike,
23
+ "dev:watch"
24
+ );
20
25
 
21
26
  // Watch the indicated tree.
22
27
  await /** @type {any} */ (container).watch?.();
@@ -48,7 +53,7 @@ async function evaluateTree(parent, fn) {
48
53
  let message;
49
54
  let result;
50
55
  try {
51
- result = await fn.call(parent);
56
+ result = await fn();
52
57
  } catch (/** @type {any} */ error) {
53
58
  message = formatError(error);
54
59
  }
@@ -82,6 +87,3 @@ function updateIndirectPointer(indirect, target) {
82
87
 
83
88
  Object.setPrototypeOf(indirect, target);
84
89
  }
85
-
86
- watch.usage = `@watch <folder>, [expr]\tLet a folder tree respond to changes`;
87
- watch.documentation = "https://weborigami.org/language/@watch.html";
@@ -0,0 +1,16 @@
1
+ export { default as cssHandler } from "./css.handler.js";
2
+ export { default as htmHandler } from "./htm.handler.js";
3
+ export { default as htmlHandler } from "./html.handler.js";
4
+ export { default as jpegHandler } from "./jpeg.handler.js";
5
+ export { default as jpgHandler } from "./jpg.handler.js";
6
+ export { default as jsHandler } from "./js.handler.js";
7
+ export { default as jsonHandler } from "./json.handler.js";
8
+ export { default as mdHandler } from "./md.handler.js";
9
+ export { default as mjsHandler } from "./mjs.handler.js";
10
+ export { default as oriHandler } from "./ori.handler.js";
11
+ export { default as oridocumentHandler } from "./oridocument.handler.js";
12
+ export { default as txtHandler } from "./txt.handler.js";
13
+ export { default as wasmHandler } from "./wasm.handler.js";
14
+ export { default as xhtmlHandler } from "./xhtml.handler.js";
15
+ export { default as yamlHandler } from "./yaml.handler.js";
16
+ export { default as ymlHandler } from "./yml.handler.js";
@@ -0,0 +1,37 @@
1
+ import {
2
+ jsHandler,
3
+ oriHandler,
4
+ oridocumentHandler,
5
+ wasmHandler,
6
+ yamlHandler,
7
+ } from "../internal.js";
8
+ import cssHandler from "./css.handler.js";
9
+ import htmHandler from "./htm.handler.js";
10
+ import htmlHandler from "./html.handler.js";
11
+ import jpegHandler from "./jpeg.handler.js";
12
+ import jpgHandler from "./jpg.handler.js";
13
+ import jsonHandler from "./json.handler.js";
14
+ import mdHandler from "./md.handler.js";
15
+ import mjsHandler from "./mjs.handler.js";
16
+ import txtHandler from "./txt.handler.js";
17
+ import xhtmlHandler from "./xhtml.handler.js";
18
+ import ymlHandler from "./yml.handler.js";
19
+
20
+ export default {
21
+ "css.handler": cssHandler,
22
+ "htm.handler": htmHandler,
23
+ "html.handler": htmlHandler,
24
+ "jpeg.handler": jpegHandler,
25
+ "jpg.handler": jpgHandler,
26
+ "js.handler": jsHandler,
27
+ "json.handler": jsonHandler,
28
+ "md.handler": mdHandler,
29
+ "mjs.handler": mjsHandler,
30
+ "ori.handler": oriHandler,
31
+ "oridocument.handler": oridocumentHandler,
32
+ "txt.handler": txtHandler,
33
+ "wasm.handler": wasmHandler,
34
+ "xhtml.handler": xhtmlHandler,
35
+ "yaml.handler": yamlHandler,
36
+ "yml.handler": ymlHandler,
37
+ };
@@ -1,4 +1,4 @@
1
- import processUnpackedContent from "../common/processUnpackedContent.js";
1
+ import { processUnpackedContent } from "../internal.js";
2
2
 
3
3
  /**
4
4
  * A JavaScript file
@@ -1,3 +1,4 @@
1
+ import { symbols } from "@weborigami/async-tree";
1
2
  import * as utilities from "../common/utilities.js";
2
3
 
3
4
  /**
@@ -14,6 +15,13 @@ export default {
14
15
  if (!json) {
15
16
  throw new Error("Tried to parse something as JSON but it wasn't text.");
16
17
  }
17
- return JSON.parse(json);
18
+ const data = JSON.parse(json);
19
+ if (data && typeof data === "object" && Object.isExtensible(data)) {
20
+ Object.defineProperty(data, symbols.deep, {
21
+ enumerable: false,
22
+ value: true,
23
+ });
24
+ }
25
+ return data;
18
26
  },
19
27
  };
@@ -0,0 +1,2 @@
1
+ // .mjs is a synonynm for .js
2
+ export { jsHandler as default } from "../internal.js";
@@ -1,8 +1,7 @@
1
1
  import { symbols } from "@weborigami/async-tree";
2
2
  import { compile } from "@weborigami/language";
3
- import processUnpackedContent from "../common/processUnpackedContent.js";
4
3
  import * as utilities from "../common/utilities.js";
5
- import builtins from "./@builtins.js";
4
+ import { builtinsTree, processUnpackedContent } from "../internal.js";
6
5
 
7
6
  /**
8
7
  * An Origami expression file
@@ -14,7 +13,6 @@ export default {
14
13
 
15
14
  /** @type {import("@weborigami/language").UnpackFunction} */
16
15
  async unpack(packed, options = {}) {
17
- const attachedData = options.attachedData;
18
16
  const parent =
19
17
  options.parent ??
20
18
  /** @type {any} */ (packed).parent ??
@@ -37,12 +35,12 @@ export default {
37
35
  url,
38
36
  };
39
37
 
40
- // Compile the source code as an Origami expression and evaluate it.
41
- const compiler = options.compiler ?? compile.expression;
38
+ // Compile the source code as an Origami program and evaluate it.
39
+ const compiler = options.compiler ?? compile.program;
42
40
  const fn = compiler(source);
43
- const target = parent ?? builtins;
41
+ const target = parent ?? builtinsTree;
44
42
  let content = await fn.call(target);
45
43
 
46
- return processUnpackedContent(content, parent, attachedData);
44
+ return processUnpackedContent(content, parent);
47
45
  },
48
46
  };
@@ -1,7 +1,7 @@
1
1
  import { symbols } from "@weborigami/async-tree";
2
2
  import { compile } from "@weborigami/language";
3
- import processUnpackedContent from "../common/processUnpackedContent.js";
4
3
  import * as utilities from "../common/utilities.js";
4
+ import { processUnpackedContent } from "../internal.js";
5
5
 
6
6
  /**
7
7
  * An Origami template document: a plain text file that contains Origami
@@ -1,4 +1,4 @@
1
- import processUnpackedContent from "../common/processUnpackedContent.js";
1
+ import { processUnpackedContent } from "../internal.js";
2
2
 
3
3
  /**
4
4
  * A WebAssembly module
@@ -1,7 +1,8 @@
1
+ import { symbols } from "@weborigami/async-tree";
1
2
  import * as YAMLModule from "yaml";
2
- import processUnpackedContent from "../common/processUnpackedContent.js";
3
3
  import { parseYaml } from "../common/serialize.js";
4
4
  import * as utilities from "../common/utilities.js";
5
+ import { processUnpackedContent } from "../internal.js";
5
6
 
6
7
  // See notes at serialize.js
7
8
  // @ts-ignore
@@ -24,6 +25,12 @@ export default {
24
25
  throw new Error("Tried to parse something as YAML but it wasn't text.");
25
26
  }
26
27
  const data = parseYaml(yaml);
28
+ if (data && typeof data === "object" && Object.isExtensible(data)) {
29
+ Object.defineProperty(data, symbols.deep, {
30
+ enumerable: false,
31
+ value: true,
32
+ });
33
+ }
27
34
  return processUnpackedContent(data, parent);
28
35
  },
29
36
  };
@@ -0,0 +1,2 @@
1
+ // .yml is a synonym for .yaml
2
+ export { yamlHandler as default } from "../internal.js";
@@ -0,0 +1,103 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "url";
4
+ import YAML from "yaml";
5
+ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
6
+ import version from "../origami/version.js";
7
+
8
+ /**
9
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
+ *
11
+ * @this {AsyncTree|null}
12
+ * @param {string} [key]
13
+ */
14
+ export default async function help(key) {
15
+ assertTreeIsDefined(this, "help:");
16
+
17
+ const helpFilename = path.resolve(
18
+ fileURLToPath(import.meta.url),
19
+ "../help.yaml"
20
+ );
21
+ const helpYaml = await fs.readFile(helpFilename);
22
+ const helpData = YAML.parse(String(helpYaml));
23
+
24
+ if (key === undefined) {
25
+ // Show all namespace descriptions
26
+ return namespaceDescriptions(helpData);
27
+ }
28
+
29
+ // Try treating key as a namespace.
30
+ const namespace = helpData[key];
31
+ if (namespace) {
32
+ return namespaceCommands(namespace, key);
33
+ }
34
+
35
+ // Try treating key as a builtin command.
36
+ for (const [namespace, { commands }] of Object.entries(helpData)) {
37
+ if (commands && Object.hasOwn(commands, key)) {
38
+ return commandDescription(commands[key], namespace, key);
39
+ }
40
+ }
41
+
42
+ return `help: "${key}" not found`;
43
+ }
44
+
45
+ async function commandDescription(commandHelp, namespace, command) {
46
+ const url = commandHelp.collection
47
+ ? `${namespace}.html`
48
+ : `${namespace}/${command}.html`;
49
+ const text = [
50
+ "",
51
+ formatCommandDescription(commandHelp, namespace, command),
52
+ "",
53
+ `For more information: https://weborigami.org/builtins/${url}`,
54
+ ];
55
+ return text.join("\n");
56
+ }
57
+
58
+ function formatCommandDescription(commandHelp, namespace, command) {
59
+ const { args, description } = commandHelp;
60
+ return ` ${namespace}:${command}${args ?? ""} - ${description}`;
61
+ }
62
+
63
+ async function namespaceCommands(namespaceHelp, namespace) {
64
+ const text = [];
65
+
66
+ const commands = namespaceHelp.commands;
67
+ if (commands === undefined) {
68
+ text.push(`"${namespace}" works like a protocol at the start of a path.`);
69
+ } else {
70
+ if (namespaceHelp.description) {
71
+ const description = namespaceHelp.description;
72
+ const lowercase = description[0].toLowerCase() + description.slice(1);
73
+ text.push(
74
+ `The "${namespace}" namespace contains commands to ${lowercase}.`
75
+ );
76
+ }
77
+ text.push("");
78
+ for (const [command, commandHelp] of Object.entries(commands)) {
79
+ text.push(formatCommandDescription(commandHelp, namespace, command));
80
+ }
81
+ text.push("");
82
+ }
83
+
84
+ const url = namespaceHelp.collection ? `${namespace}.html` : `${namespace}/`;
85
+ text.push(`For more information: https://weborigami.org/builtins/${url}`);
86
+ return text.join("\n");
87
+ }
88
+
89
+ async function namespaceDescriptions(helpData) {
90
+ const text = [
91
+ `Origami ${version} has commands grouped into the following namespaces:\n`,
92
+ ];
93
+ for (const [key, value] of Object.entries(helpData)) {
94
+ const description = value.description;
95
+ if (description) {
96
+ text.push(` ${key}: ${description}`);
97
+ }
98
+ }
99
+ text.push(
100
+ `\nType "ori help:<namespace>" for more or visit https://weborigami.org/builtins`
101
+ );
102
+ return text.join("\n");
103
+ }