@inglorious/ssx 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -52,13 +52,13 @@ npm install @inglorious/ssx @inglorious/web
52
52
 
53
53
  ### Create Your First Site
54
54
 
55
- <!-- ```bash
56
- npx @inglorious/create-app my-site --template ssx
55
+ ```bash
56
+ npx @inglorious/create-app my-site --template ssx-js
57
57
  cd my-site
58
58
  npm run dev
59
59
  ```
60
60
 
61
- Or manually: -->
61
+ Or manually:
62
62
 
63
63
  ### Create Your First Site (TypeScript)
64
64
 
@@ -224,7 +224,7 @@ export const about = {
224
224
  ```
225
225
 
226
226
  ```javascript
227
- // src/entities.js
227
+ // src/store/entities.js
228
228
  export const entities = {
229
229
  about: {
230
230
  type: "about",
@@ -452,7 +452,8 @@ my-site/
452
452
  │ │ └── posts/
453
453
  │ │ ├── index.js # /posts
454
454
  │ │ └── _id.js # /posts/:id
455
- │ ├── entities.js # Entity definitions
455
+ │ ├── store/ # Store configuration
456
+ │ │ └── entities.js # Entity definitions
456
457
  │ └── types/ # Custom entity types (optional)
457
458
  ├── dist/ # Build output
458
459
  ├── package.json
@@ -571,7 +572,7 @@ export const metadata = {
571
572
  Register it in your router:
572
573
 
573
574
  ```javascript
574
- // src/entities.js
575
+ // src/store/entities.js
575
576
  import { setRoutes } from "@inglorious/web/router"
576
577
 
577
578
  setRoutes({
package/bin/ssx.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { existsSync } from "node:fs"
2
3
  import { readFile } from "node:fs/promises"
3
4
  import path from "node:path"
4
5
  import { fileURLToPath } from "node:url"
@@ -31,10 +32,12 @@ program
31
32
  .option("-p, --port <port>", "dev server port", 3000)
32
33
  .action(async (options) => {
33
34
  const cwd = process.cwd()
35
+ const config = resolveConfigFile(options.config)
34
36
 
35
37
  try {
36
38
  await dev({
37
39
  ...options,
40
+ config,
38
41
  rootDir: path.resolve(cwd, options.root),
39
42
  port: Number(options.port),
40
43
  })
@@ -54,10 +57,12 @@ program
54
57
  .option("-f, --force", "force clean build (ignore cache)", false)
55
58
  .action(async (options) => {
56
59
  const cwd = process.cwd()
60
+ const config = resolveConfigFile(options.config)
57
61
 
58
62
  try {
59
63
  await build({
60
64
  ...options,
65
+ config,
61
66
  rootDir: path.resolve(cwd, options.root),
62
67
  outDir: path.resolve(cwd, options.out),
63
68
  incremental: options.incremental, // Enabled by default
@@ -76,3 +81,15 @@ program
76
81
  })
77
82
 
78
83
  program.parse()
84
+
85
+ function resolveConfigFile(configFile) {
86
+ if (configFile === "site.config.js") {
87
+ const jsPath = path.resolve(process.cwd(), "site.config.js")
88
+ const tsPath = path.resolve(process.cwd(), "site.config.ts")
89
+
90
+ if (!existsSync(jsPath) && existsSync(tsPath)) {
91
+ return "site.config.ts"
92
+ }
93
+ }
94
+ return configFile
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/ssx",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Server-Side-X. Xecution? Xperience? Who knows.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@ export async function hashFile(filePath) {
57
57
  * @returns {Promise<string|null>} Hash of entities.js.
58
58
  */
59
59
  export async function hashEntities(rootDir) {
60
- const entitiesPath = path.join(rootDir, "entities.js")
60
+ const entitiesPath = path.join(rootDir, "store", "entities.js")
61
61
  return await hashFile(entitiesPath)
62
62
  }
63
63
 
@@ -32,7 +32,7 @@ export async function generateStore(pages = [], options = {}, loader) {
32
32
 
33
33
  for (const ext of extensions) {
34
34
  try {
35
- const module = await load(path.join(rootDir, `entities.${ext}`))
35
+ const module = await load(path.join(rootDir, "store", `entities.${ext}`))
36
36
  entities = module.entities
37
37
  break
38
38
  } catch {
@@ -68,7 +68,11 @@ describe("generateStore", () => {
68
68
  await generateStore([page], { rootDir: "src" }, loader)
69
69
 
70
70
  expect(loader).toHaveBeenCalledWith(page.filePath)
71
- expect(loader).toHaveBeenCalledWith(path.join("src", "entities.js"))
72
- expect(loader).toHaveBeenCalledWith(path.join("src", "entities.ts"))
71
+ expect(loader).toHaveBeenCalledWith(
72
+ path.join("src", "store", "entities.js"),
73
+ )
74
+ expect(loader).toHaveBeenCalledWith(
75
+ path.join("src", "store", "entities.ts"),
76
+ )
73
77
  })
74
78
  })