orga-build 0.6.0 → 0.6.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.
package/cli.js CHANGED
@@ -16,6 +16,11 @@ const { positionals } = parseArgs({
16
16
  allowPositionals: true
17
17
  })
18
18
 
19
- const config = await loadConfig('orga.config.js', 'orga.config.mjs')
19
+ const { config, projectRoot } = await loadConfig(
20
+ 'orga.config.js',
21
+ 'orga.config.mjs'
22
+ )
20
23
 
21
- await (positionals.includes('dev') ? serve(config) : build(config))
24
+ await (positionals.includes('dev')
25
+ ? serve(config, 3000, projectRoot)
26
+ : build(config, projectRoot))
package/lib/build.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @param {import('./config.js').Config} config
3
+ * @param {string} [projectRoot]
3
4
  */
4
- export function build({ outDir, root, containerClass, styles, vitePlugins }: import("./config.js").Config): Promise<void>;
5
+ export function build({ outDir, root, containerClass, styles, vitePlugins }: import("./config.js").Config, projectRoot?: string): Promise<void>;
5
6
  export { alias };
6
7
  import { alias } from './plugin.js';
7
8
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAeA;;GAEG;AACH,6EAFW,OAAO,aAAa,EAAE,MAAM,iBAqJtC;;sBAhK4C,aAAa"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,6EAHW,OAAO,aAAa,EAAE,MAAM,gBAC5B,MAAM,iBAoJhB;;sBAhK4C,aAAa"}
package/lib/build.js CHANGED
@@ -15,6 +15,7 @@ const defaultIndexHtml = fileURLToPath(new URL('./index.html', import.meta.url))
15
15
 
16
16
  /**
17
17
  * @param {import('./config.js').Config} config
18
+ * @param {string} [projectRoot]
18
19
  */
19
20
  export async function build({
20
21
  outDir,
@@ -22,7 +23,7 @@ export async function build({
22
23
  containerClass,
23
24
  styles = [],
24
25
  vitePlugins = []
25
- }) {
26
+ }, projectRoot = process.cwd()) {
26
27
  await emptyDir(outDir)
27
28
  const ssrOutDir = path.join(outDir, '.ssr')
28
29
  const clientOutDir = outDir
@@ -103,7 +104,6 @@ export async function build({
103
104
 
104
105
  /* --- get html template, inject entry js and css --- */
105
106
  // Check for user's index.html in project root, otherwise use default
106
- const projectRoot = process.cwd()
107
107
  const userIndexPath = path.join(projectRoot, 'index.html')
108
108
  const indexHtmlPath = (await exists(userIndexPath)) ? userIndexPath : defaultIndexHtml
109
109
  const template = await fs.readFile(indexHtmlPath, { encoding: 'utf-8' })
package/lib/config.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * @param {string[]} files
3
- * @returns {Promise<Config>}
3
+ * @returns {Promise<{ config: Config, projectRoot: string }>}
4
4
  */
5
- export function loadConfig(...files: string[]): Promise<Config>;
5
+ export function loadConfig(...files: string[]): Promise<{
6
+ config: Config;
7
+ projectRoot: string;
8
+ }>;
6
9
  export type Config = {
7
10
  outDir: string;
8
11
  root: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,qCAHW,MAAM,EAAE,GACN,OAAO,CAAC,MAAM,CAAC,CAwC3B;;YA9Da,MAAM;UACN,MAAM;cACN,MAAM,EAAE;eACR,MAAM,EAAE;;;;iBACR,OAAO,MAAM,EAAE,YAAY,EAAE;oBAC7B,MAAM,EAAE,GAAC,MAAM;;;;aACf,MAAM,EAAE"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,qCAHW,MAAM,EAAE,GACN,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CA6C5D;;YAnEa,MAAM;UACN,MAAM;cACN,MAAM,EAAE;eACR,MAAM,EAAE;;;;iBACR,OAAO,MAAM,EAAE,YAAY,EAAE;oBAC7B,MAAM,EAAE,GAAC,MAAM;;;;aACf,MAAM,EAAE"}
package/lib/config.js CHANGED
@@ -25,7 +25,7 @@ const defaultConfig = {
25
25
 
26
26
  /**
27
27
  * @param {string[]} files
28
- * @returns {Promise<Config>}
28
+ * @returns {Promise<{ config: Config, projectRoot: string }>}
29
29
  */
30
30
  export async function loadConfig(...files) {
31
31
  const cwd = process.cwd()
@@ -37,6 +37,7 @@ export async function loadConfig(...files) {
37
37
  path.isAbsolute(value) ? value : path.resolve(cwd, value)
38
38
 
39
39
  let result = { ...defaultConfig }
40
+ let configPath = null
40
41
 
41
42
  for (const file of files) {
42
43
  const filePath = path.join(cwd, file)
@@ -53,6 +54,7 @@ export async function loadConfig(...files) {
53
54
  // Support both default export (recommended) and named exports
54
55
  const config = module.default || module
55
56
  result = { ...defaultConfig, ...config }
57
+ configPath = filePath
56
58
  break
57
59
  } catch (err) {
58
60
  // Config file exists but has errors
@@ -64,5 +66,8 @@ export async function loadConfig(...files) {
64
66
  result.outDir = resolveConfigPath(result.outDir)
65
67
  const styles = result.styles
66
68
  result.styles = Array.isArray(styles) ? styles.filter((v) => typeof v === 'string') : []
67
- return result
69
+ return {
70
+ config: result,
71
+ projectRoot: configPath ? path.dirname(configPath) : cwd
72
+ }
68
73
  }
package/lib/serve.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @param {import('./config.js').Config} config
5
5
  * @param {number} [port]
6
+ * @param {string} [projectRoot]
6
7
  */
7
- export function serve(config: import("./config.js").Config, port?: number): Promise<void>;
8
+ export function serve(config: import("./config.js").Config, port?: number, projectRoot?: string): Promise<void>;
8
9
  //# sourceMappingURL=serve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["serve.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,8BAHW,OAAO,aAAa,EAAE,MAAM,SAC5B,MAAM,iBAsChB"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["serve.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,8BAJW,OAAO,aAAa,EAAE,MAAM,SAC5B,MAAM,gBACN,MAAM,iBAsChB"}
package/lib/serve.js CHANGED
@@ -7,8 +7,9 @@ import { createOrgaBuildConfig, alias } from './plugin.js'
7
7
  *
8
8
  * @param {import('./config.js').Config} config
9
9
  * @param {number} [port]
10
+ * @param {string} [projectRoot]
10
11
  */
11
- export async function serve(config, port = 3000) {
12
+ export async function serve(config, port = 3000, projectRoot = process.cwd()) {
12
13
  const { plugins } = createOrgaBuildConfig({
13
14
  root: config.root,
14
15
  outDir: config.outDir,
@@ -16,7 +17,7 @@ export async function serve(config, port = 3000) {
16
17
  styles: config.styles ?? [],
17
18
  vitePlugins: config.vitePlugins,
18
19
  includeFallbackHtml: true,
19
- projectRoot: config.root
20
+ projectRoot
20
21
  })
21
22
 
22
23
  const server = await createServer({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orga-build",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "A simple tool that builds org-mode files into a website",
5
5
  "type": "module",
6
6
  "engines": {