@ossy/app 1.0.8 → 1.0.9
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/build.js +14 -108
- package/cli/dev.js +10 -12
- package/cli/index.js +30 -0
- package/package.json +13 -10
package/cli/build.js
CHANGED
|
@@ -12,11 +12,10 @@ import copy from 'rollup-plugin-copy';
|
|
|
12
12
|
import replace from '@rollup/plugin-replace';
|
|
13
13
|
import arg from 'arg'
|
|
14
14
|
import { ensureBuildStubs } from '../scripts/ensure-build-stubs.mjs'
|
|
15
|
-
import { createRequire } from 'node:module'
|
|
16
15
|
|
|
17
|
-
const PAGE_FILE_PATTERN = /\.page\.(jsx?|tsx?)$/
|
|
18
|
-
const API_FILE_PATTERN = /\.api\.(mjs|cjs|js)$/
|
|
19
|
-
const TASK_FILE_PATTERN = /\.task\.(mjs|cjs|js)$/
|
|
16
|
+
export const PAGE_FILE_PATTERN = /\.page\.(jsx?|tsx?)$/
|
|
17
|
+
export const API_FILE_PATTERN = /\.api\.(mjs|cjs|js)$/
|
|
18
|
+
export const TASK_FILE_PATTERN = /\.task\.(mjs|cjs|js)$/
|
|
20
19
|
const RESOURCE_TEMPLATE_FILE_PATTERN = /\.resource\.js$/
|
|
21
20
|
|
|
22
21
|
/** Written next to `*.resource.js` under `src/resource-templates/` when that dir exists. */
|
|
@@ -213,25 +212,10 @@ export function createOssyRollupPlugins ({
|
|
|
213
212
|
return plugins
|
|
214
213
|
}
|
|
215
214
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
const files = []
|
|
222
|
-
const walk = (d) => {
|
|
223
|
-
const entries = fs.readdirSync(d, { withFileTypes: true })
|
|
224
|
-
for (const e of entries) {
|
|
225
|
-
const full = path.join(d, e.name)
|
|
226
|
-
if (e.isDirectory()) walk(full)
|
|
227
|
-
else if (API_FILE_PATTERN.test(e.name)) files.push(full)
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
walk(dir)
|
|
231
|
-
return files.sort()
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export function discoverTaskFiles(srcDir) {
|
|
215
|
+
/**
|
|
216
|
+
* Recursively lists files under `srcDir` whose basename matches `filePattern` (e.g. `/\.api\.js$/`).
|
|
217
|
+
*/
|
|
218
|
+
export function discoverFilesByPattern (srcDir, filePattern) {
|
|
235
219
|
const dir = path.resolve(srcDir)
|
|
236
220
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
|
237
221
|
return []
|
|
@@ -242,7 +226,7 @@ export function discoverTaskFiles(srcDir) {
|
|
|
242
226
|
for (const e of entries) {
|
|
243
227
|
const full = path.join(d, e.name)
|
|
244
228
|
if (e.isDirectory()) walk(full)
|
|
245
|
-
else if (
|
|
229
|
+
else if (filePattern.test(e.name)) files.push(full)
|
|
246
230
|
}
|
|
247
231
|
}
|
|
248
232
|
walk(dir)
|
|
@@ -294,7 +278,7 @@ export function generateApiModule ({ generatedPath, apiFiles }) {
|
|
|
294
278
|
export function resolveApiSource ({ srcDir, buildPath }) {
|
|
295
279
|
ensureOssyGeneratedDir(buildPath)
|
|
296
280
|
const generatedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_API_BASENAME)
|
|
297
|
-
const apiFiles =
|
|
281
|
+
const apiFiles = discoverFilesByPattern(srcDir, API_FILE_PATTERN)
|
|
298
282
|
fs.writeFileSync(
|
|
299
283
|
generatedPath,
|
|
300
284
|
generateApiModule({ generatedPath, apiFiles })
|
|
@@ -343,7 +327,7 @@ export function resolveTaskSource ({ srcDir, scriptDir, buildPath }) {
|
|
|
343
327
|
ensureOssyGeneratedDir(buildPath)
|
|
344
328
|
const generatedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_TASKS_BASENAME)
|
|
345
329
|
|
|
346
|
-
const taskFiles =
|
|
330
|
+
const taskFiles = discoverFilesByPattern(srcDir, TASK_FILE_PATTERN)
|
|
347
331
|
if (taskFiles.length > 0) {
|
|
348
332
|
fs.writeFileSync(
|
|
349
333
|
generatedPath,
|
|
@@ -358,23 +342,6 @@ export function resolveTaskSource ({ srcDir, scriptDir, buildPath }) {
|
|
|
358
342
|
return { taskSourcePath: defaultStub, taskOverviewFiles: [], usedGenerated: false }
|
|
359
343
|
}
|
|
360
344
|
|
|
361
|
-
export function discoverPageFiles(srcDir) {
|
|
362
|
-
if (!fs.existsSync(srcDir) || !fs.statSync(srcDir).isDirectory()) {
|
|
363
|
-
return []
|
|
364
|
-
}
|
|
365
|
-
const files = []
|
|
366
|
-
const walk = (d) => {
|
|
367
|
-
const entries = fs.readdirSync(d, { withFileTypes: true })
|
|
368
|
-
for (const e of entries) {
|
|
369
|
-
const full = path.join(d, e.name)
|
|
370
|
-
if (e.isDirectory()) walk(full)
|
|
371
|
-
else if (PAGE_FILE_PATTERN.test(e.name)) files.push(full)
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
walk(srcDir)
|
|
375
|
-
return files.sort()
|
|
376
|
-
}
|
|
377
|
-
|
|
378
345
|
export function filePathToRoute(filePath, srcDir) {
|
|
379
346
|
const rel = path.relative(srcDir, filePath).replace(/\\/g, '/')
|
|
380
347
|
let pathPart = rel.replace(PAGE_FILE_PATTERN, '').replace(/\/index$/, '').replace(/\/home$/, '') || 'home'
|
|
@@ -510,65 +477,6 @@ export function generatePagesModule (pageFiles, srcDir, generatedPath) {
|
|
|
510
477
|
return lines.join('\n')
|
|
511
478
|
}
|
|
512
479
|
|
|
513
|
-
export async function discoverModulePageFiles({ configPath }) {
|
|
514
|
-
if (!configPath || !fs.existsSync(configPath)) return []
|
|
515
|
-
try {
|
|
516
|
-
// Try a cheap static parse first so we don't depend on the config file being
|
|
517
|
-
// importable (configs often import theme/template modules that may not be
|
|
518
|
-
// resolvable in the build-time node context).
|
|
519
|
-
const cfgSource = fs.readFileSync(configPath, 'utf8')
|
|
520
|
-
const modules = []
|
|
521
|
-
|
|
522
|
-
// pagesModules: ['a', "b"]
|
|
523
|
-
const arrMatch = cfgSource.match(/pagesModules\s*:\s*\[([^\]]*)\]/m)
|
|
524
|
-
if (arrMatch?.[1]) {
|
|
525
|
-
const body = arrMatch[1]
|
|
526
|
-
const re = /['"]([^'"]+)['"]/g
|
|
527
|
-
let m
|
|
528
|
-
while ((m = re.exec(body)) !== null) modules.push(m[1])
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// pagesModule: 'a'
|
|
532
|
-
if (modules.length === 0) {
|
|
533
|
-
const singleMatch = cfgSource.match(/pagesModule\s*:\s*['"]([^'"]+)['"]/m)
|
|
534
|
-
if (singleMatch?.[1]) modules.push(singleMatch[1])
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (modules.length) {
|
|
538
|
-
const req = createRequire(path.resolve(process.cwd(), 'package.json'))
|
|
539
|
-
const files = []
|
|
540
|
-
for (const name of modules) {
|
|
541
|
-
const pkgJsonPath = req.resolve(`${name}/package.json`)
|
|
542
|
-
const pkgDir = path.dirname(pkgJsonPath)
|
|
543
|
-
const modulePagesDir = path.join(pkgDir, 'src', 'pages')
|
|
544
|
-
files.push(...discoverPageFiles(modulePagesDir))
|
|
545
|
-
}
|
|
546
|
-
return files
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const mod = await import(url.pathToFileURL(configPath))
|
|
550
|
-
const cfg = mod?.default ?? mod ?? {}
|
|
551
|
-
const modules2 = Array.isArray(cfg.pagesModules)
|
|
552
|
-
? cfg.pagesModules
|
|
553
|
-
: (typeof cfg.pagesModule === 'string' ? [cfg.pagesModule] : [])
|
|
554
|
-
|
|
555
|
-
if (!modules2.length) return []
|
|
556
|
-
|
|
557
|
-
const req = createRequire(path.resolve(process.cwd(), 'package.json'))
|
|
558
|
-
const files = []
|
|
559
|
-
for (const name of modules2) {
|
|
560
|
-
const pkgJsonPath = req.resolve(`${name}/package.json`)
|
|
561
|
-
const pkgDir = path.dirname(pkgJsonPath)
|
|
562
|
-
const modulePagesDir = path.join(pkgDir, 'src', 'pages')
|
|
563
|
-
files.push(...discoverPageFiles(modulePagesDir))
|
|
564
|
-
}
|
|
565
|
-
return files
|
|
566
|
-
} catch (e) {
|
|
567
|
-
console.warn('[@ossy/app][build] pagesModules config could not be loaded; continuing without modules')
|
|
568
|
-
return []
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
480
|
export function parsePagesFromSource(filePath) {
|
|
573
481
|
try {
|
|
574
482
|
const content = fs.readFileSync(filePath, 'utf8')
|
|
@@ -665,8 +573,7 @@ export const build = async (cliArgs) => {
|
|
|
665
573
|
const buildPath = path.resolve('build')
|
|
666
574
|
const srcDir = path.resolve('src')
|
|
667
575
|
const configPath = path.resolve(options['--config'] || 'src/config.js');
|
|
668
|
-
const pageFiles =
|
|
669
|
-
const modulePageFiles = await discoverModulePageFiles({ configPath })
|
|
576
|
+
const pageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
|
|
670
577
|
|
|
671
578
|
resetOssyBuildDir(buildPath)
|
|
672
579
|
|
|
@@ -674,14 +581,13 @@ export const build = async (cliArgs) => {
|
|
|
674
581
|
|
|
675
582
|
const pagesGeneratedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
|
|
676
583
|
|
|
677
|
-
const allPageFiles = [...pageFiles, ...modulePageFiles]
|
|
678
584
|
fs.writeFileSync(
|
|
679
585
|
pagesGeneratedPath,
|
|
680
|
-
generatePagesModule(
|
|
586
|
+
generatePagesModule(pageFiles, srcDir, pagesGeneratedPath)
|
|
681
587
|
)
|
|
682
588
|
const ossyDir = ossyGeneratedDir(buildPath)
|
|
683
|
-
writePageHydrateStubs(
|
|
684
|
-
const clientHydrateInput = buildClientHydrateInput(
|
|
589
|
+
writePageHydrateStubs(pageFiles, srcDir, ossyDir)
|
|
590
|
+
const clientHydrateInput = buildClientHydrateInput(pageFiles, srcDir, ossyDir)
|
|
685
591
|
|
|
686
592
|
const {
|
|
687
593
|
apiSourcePath: resolvedApi,
|
package/cli/dev.js
CHANGED
|
@@ -3,9 +3,9 @@ import url from 'url';
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import {
|
|
5
5
|
printBuildOverview,
|
|
6
|
-
|
|
6
|
+
discoverFilesByPattern,
|
|
7
|
+
PAGE_FILE_PATTERN,
|
|
7
8
|
generatePagesModule,
|
|
8
|
-
discoverModulePageFiles,
|
|
9
9
|
resolveApiSource,
|
|
10
10
|
resetOssyBuildDir,
|
|
11
11
|
createOssyRollupPlugins,
|
|
@@ -37,23 +37,21 @@ export const dev = async (cliArgs) => {
|
|
|
37
37
|
const buildPath = path.resolve('build')
|
|
38
38
|
const srcDir = path.resolve('src')
|
|
39
39
|
const configPath = path.resolve(options['--config'] || 'src/config.js');
|
|
40
|
-
const pageFiles =
|
|
41
|
-
const modulePageFiles = await discoverModulePageFiles({ configPath })
|
|
40
|
+
const pageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
|
|
42
41
|
|
|
43
42
|
resetOssyBuildDir(buildPath)
|
|
44
43
|
|
|
45
44
|
writeResourceTemplatesBarrelIfPresent({ cwd: process.cwd(), log: true })
|
|
46
45
|
|
|
47
|
-
const allPageFiles = [...pageFiles, ...modulePageFiles]
|
|
48
46
|
const pagesGeneratedPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
|
|
49
47
|
fs.writeFileSync(
|
|
50
48
|
pagesGeneratedPath,
|
|
51
|
-
generatePagesModule(
|
|
49
|
+
generatePagesModule(pageFiles, srcDir, pagesGeneratedPath)
|
|
52
50
|
)
|
|
53
51
|
const effectivePagesSource = pagesGeneratedPath
|
|
54
52
|
const ossyDir = ossyGeneratedDir(buildPath)
|
|
55
|
-
writePageHydrateStubs(
|
|
56
|
-
const clientHydrateInput = buildClientHydrateInput(
|
|
53
|
+
writePageHydrateStubs(pageFiles, srcDir, ossyDir)
|
|
54
|
+
const clientHydrateInput = buildClientHydrateInput(pageFiles, srcDir, ossyDir)
|
|
57
55
|
|
|
58
56
|
const {
|
|
59
57
|
apiSourcePath: resolvedApi,
|
|
@@ -217,13 +215,13 @@ export const dev = async (cliArgs) => {
|
|
|
217
215
|
fs.watch(srcDir, { recursive: true }, (eventType, filename) => {
|
|
218
216
|
if (!filename) return
|
|
219
217
|
if (/\.page\.(jsx?|tsx?)$/.test(filename)) {
|
|
220
|
-
const
|
|
218
|
+
const refreshedPageFiles = discoverFilesByPattern(srcDir, PAGE_FILE_PATTERN)
|
|
221
219
|
const regenPath = path.join(ossyGeneratedDir(buildPath), OSSY_GEN_PAGES_BASENAME)
|
|
222
|
-
fs.writeFileSync(regenPath, generatePagesModule(
|
|
223
|
-
writePageHydrateStubs(
|
|
220
|
+
fs.writeFileSync(regenPath, generatePagesModule(refreshedPageFiles, srcDir, regenPath))
|
|
221
|
+
writePageHydrateStubs(refreshedPageFiles, srcDir, ossyDir)
|
|
224
222
|
if (typeof watcher?.invalidate === 'function') {
|
|
225
223
|
watcher.invalidate(regenPath)
|
|
226
|
-
for (const f of
|
|
224
|
+
for (const f of refreshedPageFiles) {
|
|
227
225
|
const hid = clientHydrateIdForPage(f, srcDir)
|
|
228
226
|
watcher.invalidate(path.join(ossyDir, `hydrate-${hid}.jsx`))
|
|
229
227
|
}
|
package/cli/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { build } from './build.js'
|
|
3
|
+
import { dev } from './dev.js'
|
|
4
|
+
|
|
5
|
+
const [,, command, ...restArgs] = process.argv
|
|
6
|
+
|
|
7
|
+
if (!command) {
|
|
8
|
+
console.error(
|
|
9
|
+
'[@ossy/app] No command provided. Usage: app dev | build'
|
|
10
|
+
)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const run = async () => {
|
|
15
|
+
if (command === 'dev') {
|
|
16
|
+
await dev(restArgs)
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
if (command === 'build') {
|
|
20
|
+
await build(restArgs)
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
console.error(`[@ossy/app] Unknown command: ${command}`)
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
run().catch((err) => {
|
|
28
|
+
console.error(err)
|
|
29
|
+
process.exit(1)
|
|
30
|
+
})
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"app": "./cli/index.js"
|
|
10
|
+
},
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "echo Building not required",
|
|
10
13
|
"test": "node --experimental-vm-modules ../node_modules/jest/bin/jest.js --verbose",
|
|
@@ -24,14 +27,14 @@
|
|
|
24
27
|
"@babel/eslint-parser": "^7.15.8",
|
|
25
28
|
"@babel/preset-react": "^7.26.3",
|
|
26
29
|
"@babel/register": "^7.25.9",
|
|
27
|
-
"@ossy/connected-components": "^1.0.
|
|
28
|
-
"@ossy/design-system": "^1.0.
|
|
29
|
-
"@ossy/pages": "^1.0.
|
|
30
|
-
"@ossy/router": "^1.0.
|
|
31
|
-
"@ossy/router-react": "^1.0.
|
|
32
|
-
"@ossy/sdk": "^1.0.
|
|
33
|
-
"@ossy/sdk-react": "^1.0.
|
|
34
|
-
"@ossy/themes": "^1.0.
|
|
30
|
+
"@ossy/connected-components": "^1.0.9",
|
|
31
|
+
"@ossy/design-system": "^1.0.9",
|
|
32
|
+
"@ossy/pages": "^1.0.9",
|
|
33
|
+
"@ossy/router": "^1.0.9",
|
|
34
|
+
"@ossy/router-react": "^1.0.9",
|
|
35
|
+
"@ossy/sdk": "^1.0.9",
|
|
36
|
+
"@ossy/sdk-react": "^1.0.9",
|
|
37
|
+
"@ossy/themes": "^1.0.9",
|
|
35
38
|
"@rollup/plugin-alias": "^6.0.0",
|
|
36
39
|
"@rollup/plugin-babel": "6.1.0",
|
|
37
40
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -64,5 +67,5 @@
|
|
|
64
67
|
"README.md",
|
|
65
68
|
"tsconfig.json"
|
|
66
69
|
],
|
|
67
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "c9da4864730c693fe18339f0920a0802ce9c8ebf"
|
|
68
71
|
}
|