@inglorious/ssx 1.3.1 → 1.3.3
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 +7 -6
- package/bin/ssx.js +24 -4
- package/package.json +1 -1
- package/src/build/manifest.js +1 -1
- package/src/store/index.js +1 -1
- package/src/store/store.test.js +6 -2
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
|
-
|
|
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
|
-
│ ├──
|
|
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"
|
|
@@ -26,15 +27,19 @@ program
|
|
|
26
27
|
program
|
|
27
28
|
.command("dev")
|
|
28
29
|
.description("Start development server with hot reload")
|
|
29
|
-
.option("-c, --config <file>", "config file", "site.config.js")
|
|
30
|
+
.option("-c, --config <file>", "config file path", "site.config.js")
|
|
30
31
|
.option("-r, --root <dir>", "source root directory", "src")
|
|
31
32
|
.option("-p, --port <port>", "dev server port", 3000)
|
|
32
33
|
.action(async (options) => {
|
|
33
34
|
const cwd = process.cwd()
|
|
35
|
+
const configPath = resolveConfigFile(options.config)
|
|
34
36
|
|
|
35
37
|
try {
|
|
36
38
|
await dev({
|
|
37
39
|
...options,
|
|
40
|
+
config: undefined,
|
|
41
|
+
root: undefined,
|
|
42
|
+
configPath,
|
|
38
43
|
rootDir: path.resolve(cwd, options.root),
|
|
39
44
|
port: Number(options.port),
|
|
40
45
|
})
|
|
@@ -47,21 +52,24 @@ program
|
|
|
47
52
|
program
|
|
48
53
|
.command("build")
|
|
49
54
|
.description("Build site from pages directory")
|
|
50
|
-
.option("-c, --config <file>", "config file", "site.config.js")
|
|
55
|
+
.option("-c, --config <file>", "config file path", "site.config.js")
|
|
51
56
|
.option("-r, --root <dir>", "source root directory", "src")
|
|
52
57
|
.option("-o, --out <dir>", "output directory", "dist")
|
|
53
58
|
.option("-i, --incremental", "enable incremental builds", true)
|
|
54
59
|
.option("-f, --force", "force clean build (ignore cache)", false)
|
|
55
60
|
.action(async (options) => {
|
|
56
61
|
const cwd = process.cwd()
|
|
62
|
+
const configPath = resolveConfigFile(options.config)
|
|
57
63
|
|
|
58
64
|
try {
|
|
59
65
|
await build({
|
|
60
66
|
...options,
|
|
67
|
+
config: undefined,
|
|
68
|
+
root: undefined,
|
|
69
|
+
out: undefined,
|
|
70
|
+
configPath,
|
|
61
71
|
rootDir: path.resolve(cwd, options.root),
|
|
62
72
|
outDir: path.resolve(cwd, options.out),
|
|
63
|
-
incremental: options.incremental, // Enabled by default
|
|
64
|
-
clean: options.force,
|
|
65
73
|
})
|
|
66
74
|
|
|
67
75
|
// if (result.skipped) {
|
|
@@ -76,3 +84,15 @@ program
|
|
|
76
84
|
})
|
|
77
85
|
|
|
78
86
|
program.parse()
|
|
87
|
+
|
|
88
|
+
function resolveConfigFile(configFile) {
|
|
89
|
+
if (configFile === "site.config.js") {
|
|
90
|
+
const jsPath = path.resolve(process.cwd(), "site.config.js")
|
|
91
|
+
const tsPath = path.resolve(process.cwd(), "site.config.ts")
|
|
92
|
+
|
|
93
|
+
if (!existsSync(jsPath) && existsSync(tsPath)) {
|
|
94
|
+
return "site.config.ts"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return configFile
|
|
98
|
+
}
|
package/package.json
CHANGED
package/src/build/manifest.js
CHANGED
|
@@ -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
|
|
package/src/store/index.js
CHANGED
|
@@ -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 {
|
package/src/store/store.test.js
CHANGED
|
@@ -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(
|
|
72
|
-
|
|
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
|
})
|