orga-build 0.1.0 → 0.1.1

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 (33) hide show
  1. package/cli.js +4 -4
  2. package/index.d.ts +1 -1
  3. package/index.js +1 -1
  4. package/lib/config.d.ts +12 -0
  5. package/lib/config.d.ts.map +1 -0
  6. package/lib/config.js +34 -0
  7. package/lib/esbuild/build.d.ts +9 -0
  8. package/lib/esbuild/build.d.ts.map +1 -0
  9. package/lib/esbuild/{index.js → build.js} +26 -9
  10. package/lib/esbuild/evaluate.d.ts +8 -0
  11. package/lib/esbuild/evaluate.d.ts.map +1 -0
  12. package/lib/{esbuild.js → esbuild/evaluate.js} +0 -24
  13. package/lib/esbuild/resolve-react.d.ts +13 -0
  14. package/lib/esbuild/resolve-react.d.ts.map +1 -0
  15. package/lib/esbuild/resolve-react.js +27 -0
  16. package/lib/{build.d.ts.map → node/build.d.ts.map} +1 -1
  17. package/lib/{build.js → node/build.js} +5 -15
  18. package/lib/watch.js +1 -1
  19. package/package.json +6 -5
  20. package/lib/esbuild/index.d.ts +0 -16
  21. package/lib/esbuild/index.d.ts.map +0 -1
  22. package/lib/esbuild.d.ts +0 -31
  23. package/lib/esbuild.d.ts.map +0 -1
  24. /package/lib/{build.d.ts → node/build.d.ts} +0 -0
  25. /package/lib/{jsx-loader.d.ts → node/jsx-loader.d.ts} +0 -0
  26. /package/lib/{jsx-loader.d.ts.map → node/jsx-loader.d.ts.map} +0 -0
  27. /package/lib/{jsx-loader.js → node/jsx-loader.js} +0 -0
  28. /package/lib/{orga-loader.d.ts → node/orga-loader.d.ts} +0 -0
  29. /package/lib/{orga-loader.d.ts.map → node/orga-loader.d.ts.map} +0 -0
  30. /package/lib/{orga-loader.js → node/orga-loader.js} +0 -0
  31. /package/lib/{raw-loader.d.ts → node/raw-loader.d.ts} +0 -0
  32. /package/lib/{raw-loader.d.ts.map → node/raw-loader.d.ts.map} +0 -0
  33. /package/lib/{raw-loader.js → node/raw-loader.js} +0 -0
package/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { argv } from 'node:process'
3
+ import { argv, cwd } from 'node:process'
4
4
  import { parseArgs } from 'node:util'
5
5
  import { watch } from './lib/watch.js'
6
- import { loadConfig, clean } from './lib/build.js'
7
- import { build } from './lib/esbuild/index.js'
6
+ import { build, clean } from './lib/esbuild/build.js'
7
+ import { loadConfig } from './lib/config.js'
8
8
  import { serve } from './lib/serve.js'
9
9
 
10
10
  const { values, positionals } = parseArgs({
@@ -17,7 +17,7 @@ const { values, positionals } = parseArgs({
17
17
  allowPositionals: true
18
18
  })
19
19
 
20
- const config = await loadConfig()
20
+ const config = await loadConfig(cwd(), 'orga.config.js', 'orga.config.ts')
21
21
 
22
22
  await build(config)
23
23
 
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { build } from "./lib/build.js";
1
+ export { build } from "./lib/esbuild/build.js";
2
2
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1 +1 @@
1
- export { build } from './lib/build.js'
1
+ export { build } from './lib/esbuild/build.js'
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param {string} cwd
3
+ * @param {string[]} files
4
+ * @returns {Promise<Config>}
5
+ */
6
+ export function loadConfig(cwd: string, ...files: string[]): Promise<Config>;
7
+ export type Config = {
8
+ outDir: string;
9
+ preBuild: string[];
10
+ postBuild: string[];
11
+ };
12
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,gCAJW,MAAM,YACN,MAAM,EAAE,GACN,OAAO,CAAC,MAAM,CAAC,CAY3B;;YA3Ba,MAAM;cACN,MAAM,EAAE;eACR,MAAM,EAAE"}
package/lib/config.js ADDED
@@ -0,0 +1,34 @@
1
+ import fs from 'node:fs/promises'
2
+ import path from 'node:path'
3
+ import { evaluate } from './esbuild/evaluate.js'
4
+
5
+ /**
6
+ * @typedef {Object} Config
7
+ * @property {string} outDir
8
+ * @property {string[]} preBuild
9
+ * @property {string[]} postBuild
10
+ */
11
+
12
+ /** @type {Config} */
13
+ const defaultConfig = {
14
+ outDir: 'out',
15
+ preBuild: [],
16
+ postBuild: []
17
+ }
18
+
19
+ /**
20
+ * @param {string} cwd
21
+ * @param {string[]} files
22
+ * @returns {Promise<Config>}
23
+ */
24
+ export async function loadConfig(cwd, ...files) {
25
+ for (const file of files) {
26
+ const filePath = path.join(cwd, file)
27
+ try {
28
+ await fs.access(filePath, fs.constants.F_OK)
29
+ const config = await evaluate(filePath)
30
+ return { ...defaultConfig, ...config }
31
+ } catch (err) {}
32
+ }
33
+ return defaultConfig
34
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @param {import('../config.js').Config} options
3
+ */
4
+ export function build({ outDir, preBuild, postBuild }: import("../config.js").Config): Promise<void>;
5
+ /**
6
+ * @param {import("fs").PathLike} dir
7
+ */
8
+ export function clean(dir: import("fs").PathLike): Promise<void>;
9
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAWA;;GAEG;AACH,uDAFW,OAAO,cAAc,EAAE,MAAM,iBAuLvC;AAiCD;;GAEG;AACH,2BAFW,OAAO,IAAI,EAAE,QAAQ,iBAI/B"}
@@ -7,16 +7,10 @@ import { renderToString } from 'react-dom/server'
7
7
  import assert from 'node:assert'
8
8
  import { DefaultLayout, $, match } from '../util.js'
9
9
  import rawLoader from './raw-loader.js'
10
+ import resolveReact from './resolve-react.js'
10
11
 
11
12
  /**
12
- * @typedef {Object} Options
13
- * @property {string} [outDir]
14
- * @property {string[]} [preBuild]
15
- * @property {string[]} [postBuild]
16
- */
17
-
18
- /**
19
- * @param {Options} options
13
+ * @param {import('../config.js').Config} options
20
14
  */
21
15
  export async function build({ outDir = 'dir', preBuild = [], postBuild = [] }) {
22
16
  for (const cmd of preBuild) {
@@ -62,12 +56,28 @@ export async function build({ outDir = 'dir', preBuild = [], postBuild = [] }) {
62
56
  format: 'esm',
63
57
  platform: 'node',
64
58
  target: 'esnext',
59
+ // jsxFactory: 'React.createElement',
60
+ // jsxFragment: 'React.Fragment',
65
61
  jsx: 'automatic',
66
62
  // write: false,
67
63
  outdir: '.orga-build/js',
68
64
  // splitting: true,
69
65
  metafile: true,
70
- plugins: [esbuildOrga(), rawLoader],
66
+ plugins: [
67
+ esbuildOrga({
68
+ reorgRehypeOptions: {
69
+ linkHref: (link) => {
70
+ if (link.path.protocol === 'file') {
71
+ return link.path.value.replace(/\.org$/, '.html')
72
+ }
73
+ return link.path.value
74
+ }
75
+ }
76
+ // reorgPlugins: [reorgLinks]
77
+ }),
78
+ rawLoader,
79
+ resolveReact
80
+ ],
71
81
  // external: ['react/jsx-runtime'],
72
82
  loader: {
73
83
  '.jsx': 'jsx',
@@ -215,3 +225,10 @@ async function walk(dirPath, callback) {
215
225
  }
216
226
  }
217
227
  }
228
+
229
+ /**
230
+ * @param {import("fs").PathLike} dir
231
+ */
232
+ export async function clean(dir) {
233
+ await fs.rm(dir, { recursive: true })
234
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Evaluate an org/jsx/tsx/ts file. Returns as a module.
3
+ * It's like a dynamic import, but without relying on nodejs.
4
+ * @param {string} filePath
5
+ * @returns {Promise<any>}
6
+ */
7
+ export function evaluate(filePath: string): Promise<any>;
8
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["evaluate.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,mCAHW,MAAM,GACJ,OAAO,CAAC,GAAG,CAAC,CAwBxB"}
@@ -31,27 +31,3 @@ export async function evaluate(filePath) {
31
31
  `return import("data:application/javascript,${encodeURIComponent(code)}")`
32
32
  )()
33
33
  }
34
-
35
- /**
36
- * @param {string} pattern
37
- */
38
- export async function build(pattern) {
39
- return await esbuild.build({
40
- entryPoints: [pattern],
41
- entryNames: '[dir]/_/[name]',
42
- bundle: true,
43
- format: 'esm',
44
- platform: 'node',
45
- target: 'esnext',
46
- jsx: 'automatic',
47
- // write: false,
48
- outdir: '.build',
49
- plugins: [esbuildOrga()],
50
- loader: {
51
- '.jsx': 'jsx',
52
- '.tsx': 'tsx'
53
- }
54
- })
55
- }
56
-
57
- export async function b() {}
@@ -0,0 +1,13 @@
1
+ export default resolveReact;
2
+ declare namespace resolveReact {
3
+ let name: string;
4
+ /**
5
+ * @param {PluginBuild} build
6
+ * Build.
7
+ * @returns {undefined}
8
+ * Nothing.
9
+ */
10
+ function setup(build: PluginBuild): undefined;
11
+ }
12
+ import type { PluginBuild } from 'esbuild';
13
+ //# sourceMappingURL=resolve-react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-react.d.ts","sourceRoot":"","sources":["resolve-react.js"],"names":[],"mappings":";;;IAaC;;;;;OAKG;IACH,sBALW,WAAW,GAET,SAAS,CAOrB;;iCAtB4B,SAAS"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @import {PluginBuild} from 'esbuild'
3
+ */
4
+
5
+ import { createRequire } from 'module'
6
+ import path from 'path'
7
+
8
+ const require = createRequire(import.meta.url)
9
+ const reactPath = require.resolve('react')
10
+ const reactDirPath = path.dirname(reactPath)
11
+
12
+ const resolveReact = {
13
+ name: 'resolve-react',
14
+ /**
15
+ * @param {PluginBuild} build
16
+ * Build.
17
+ * @returns {undefined}
18
+ * Nothing.
19
+ */
20
+ setup(build) {
21
+ build.onResolve({ filter: /^react\/jsx-runtime$/ }, () => {
22
+ return { path: path.join(reactDirPath, 'jsx-runtime.js') }
23
+ })
24
+ }
25
+ }
26
+
27
+ export default resolveReact
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAwJA;;GAEG;AACH,uDAFW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AAS;;;;aAClB,OAAO,GAAG,OAAO,EAAE;;;;WACnB,CAAC,IAAI,EAAE,IAAI,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC;;;;eAChG,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM;;;;kBA5B7D,MAAM,EAAE;mBAER,MAAM,EAAE"}
@@ -5,17 +5,11 @@ import path from 'path'
5
5
  import { createElement } from 'react'
6
6
  import { renderToString } from 'react-dom/server'
7
7
  import assert from 'node:assert'
8
- import { match } from './util.js'
9
- import { evaluate, build as _build } from './esbuild.js'
10
- import { $, DefaultLayout } from './util.js'
8
+ import { match, $, DefaultLayout } from '../util.js'
11
9
 
12
- const USE_NODE = false
13
-
14
- if (USE_NODE) {
15
- register('./jsx-loader.js', import.meta.url)
16
- register('./orga-loader.js', import.meta.url)
17
- register('./raw-loader.js', import.meta.url)
18
- }
10
+ register('./jsx-loader.js', import.meta.url)
11
+ register('./orga-loader.js', import.meta.url)
12
+ register('./raw-loader.js', import.meta.url)
19
13
 
20
14
  const defaultConfig = {
21
15
  outDir: 'out',
@@ -208,11 +202,7 @@ async function _import(...files) {
208
202
  const file = found[0]
209
203
  const fullPath = path.isAbsolute(file) ? file : path.join(process.cwd(), file)
210
204
  const { mtime } = await fs.stat(fullPath)
211
- if (USE_NODE) {
212
- return await import(`${fullPath}?version=${mtime.getTime()}`)
213
- } else {
214
- return await evaluate(fullPath)
215
- }
205
+ return await import(`${fullPath}?version=${mtime.getTime()}`)
216
206
  }
217
207
 
218
208
  /**
package/lib/watch.js CHANGED
@@ -11,7 +11,7 @@ export async function watch(dir, ignore, onChange) {
11
11
  /** @type {ReturnType<typeof setTimeout> | null} */
12
12
  let timeout = null
13
13
  const delay = 1000
14
- const defaultIgnorePattern = /node_modules|\.git|\.DS_Store/
14
+ const defaultIgnorePattern = /node_modules|\.git|\.DS_Store|\.orga-build/
15
15
 
16
16
  const watcher = fs.watch(dir, { recursive: true })
17
17
  for await (const event of watcher) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "orga-build",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A simple tool that builds org-mode files into a website",
5
5
  "type": "module",
6
6
  "bin": {
7
- "orga-build": "cli.js"
7
+ "orga-build": "./cli.js"
8
8
  },
9
9
  "files": [
10
10
  "lib/",
@@ -24,21 +24,22 @@
24
24
  "author": "Xiaoxing Hu <hi@xiaoxing.dev>",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@orgajs/esbuild": "^1.1.1",
28
27
  "esbuild": "^0.24.2",
29
28
  "globby": "^14.0.2",
30
29
  "react": "^19.0.0",
31
30
  "react-dom": "^19.0.0",
32
31
  "rehype-katex": "^7.0.1",
33
32
  "serve-handler": "^6.1.6",
34
- "@orgajs/node-loader": "^1.1.1"
33
+ "@orgajs/esbuild": "^1.1.2",
34
+ "@orgajs/node-loader": "^1.1.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^22.13.1",
38
38
  "@types/react": "^19.0.8",
39
39
  "@types/react-dom": "^19.0.3",
40
40
  "@types/serve-handler": "^6.1.4",
41
- "@orgajs/orgx": "^2.5.0"
41
+ "@orgajs/orgx": "^2.5.1",
42
+ "orga": "^4.5.0"
42
43
  },
43
44
  "scripts": {}
44
45
  }
@@ -1,16 +0,0 @@
1
- /**
2
- * @typedef {Object} Options
3
- * @property {string} [outDir]
4
- * @property {string[]} [preBuild]
5
- * @property {string[]} [postBuild]
6
- */
7
- /**
8
- * @param {Options} options
9
- */
10
- export function build({ outDir, preBuild, postBuild }: Options): Promise<void>;
11
- export type Options = {
12
- outDir?: string;
13
- preBuild?: string[];
14
- postBuild?: string[];
15
- };
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAUA;;;;;GAKG;AAEH;;GAEG;AACH,uDAFW,OAAO,iBAuKjB;;aA7Ka,MAAM;eACN,MAAM,EAAE;gBACR,MAAM,EAAE"}
package/lib/esbuild.d.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Evaluate an org/jsx/tsx/ts file. Returns as a module.
3
- * It's like a dynamic import, but without relying on nodejs.
4
- * @param {string} filePath
5
- * @returns {Promise<any>}
6
- */
7
- export function evaluate(filePath: string): Promise<any>;
8
- /**
9
- * @param {string} pattern
10
- */
11
- export function build(pattern: string): Promise<esbuild.BuildResult<{
12
- entryPoints: string[];
13
- entryNames: string;
14
- bundle: true;
15
- format: "esm";
16
- platform: "node";
17
- target: string;
18
- jsx: "automatic";
19
- outdir: string;
20
- plugins: {
21
- name: string;
22
- setup: (build: esbuild.PluginBuild) => undefined;
23
- }[];
24
- loader: {
25
- '.jsx': "jsx";
26
- '.tsx': "tsx";
27
- };
28
- }>>;
29
- export function b(): Promise<void>;
30
- import * as esbuild from 'esbuild';
31
- //# sourceMappingURL=esbuild.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["esbuild.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,mCAHW,MAAM,GACJ,OAAO,CAAC,GAAG,CAAC,CAwBxB;AAED;;GAEG;AACH,+BAFW,MAAM;;;;;;;;;;;;;;;;;IAmBhB;AAED,mCAA4B;yBAvDH,SAAS"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes