@lincyaw/workspace 1.0.0-rc.5 → 1.0.0-rc.7
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/package.json +5 -5
- package/src/node/build.ts +18 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.7",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"image-size": "2.0.4",
|
|
34
34
|
"mime-types": "3.0.2",
|
|
35
35
|
"yaml": "^2.9.1",
|
|
36
|
-
"@lincyaw/
|
|
37
|
-
"@lincyaw/
|
|
38
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
36
|
+
"@lincyaw/server": "1.0.0-rc.7",
|
|
37
|
+
"@lincyaw/compiler": "1.0.0-rc.7",
|
|
38
|
+
"@lincyaw/kernel": "1.0.0-rc.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/mime-types": "^3.0.1",
|
|
42
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
42
|
+
"@lincyaw/mcp": "1.0.0-rc.7"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/node/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cpSync, existsSync, rmSync } from 'node:fs'
|
|
1
|
+
import { cpSync, existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { join, resolve } from 'node:path'
|
|
3
3
|
import { build, Compiler } from '@lincyaw/compiler'
|
|
4
4
|
import type { Compilation, RunStats } from '@lincyaw/compiler'
|
|
@@ -23,7 +23,7 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
|
|
|
23
23
|
const forms: { dir: string, compilation: Compilation, to: string[] }[] = []
|
|
24
24
|
for (const document of found) {
|
|
25
25
|
const compilation = await new Compiler(join(config.root, document.entry), { bundled: options.bundled, settings: config.settings }).compile({ pruneCache: true })
|
|
26
|
-
const to = presentations(compilation, `${base}${document.dir
|
|
26
|
+
const to = presentations(compilation, `${base}${urlPath(document.dir)}/`)
|
|
27
27
|
if (to.length > 0) forms.push({ dir: document.dir, compilation, to })
|
|
28
28
|
const translated = await siteTranslations(compilation)
|
|
29
29
|
findings.push(...compilation.doc.diagnostics, ...translated.findings)
|
|
@@ -47,6 +47,7 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
|
|
|
47
47
|
const report = await build(compilation, { outDir: work, to })
|
|
48
48
|
findings.push(...report.findings)
|
|
49
49
|
for (const form of to) if (existsSync(join(work, form))) cpSync(join(work, form), join(outDir, dir, form), { recursive: true })
|
|
50
|
+
if (to.includes('slides')) shareSlidesApp(join(outDir, dir, 'slides'), `${base}${urlPath(dir)}/slides/`, outDir, base)
|
|
50
51
|
} catch (error) {
|
|
51
52
|
findings.push({ checkId: 'presmium.render', severity: 'error', message: `document ${dir}: its ${to.join(' and ')} failed: ${errorMessage(error)}` })
|
|
52
53
|
}
|
|
@@ -56,6 +57,21 @@ export async function buildWorkspace(root: string, options: { outDir?: string, b
|
|
|
56
57
|
|
|
57
58
|
const PRESENTATIONS = ['slides', 'lecture']
|
|
58
59
|
|
|
60
|
+
const urlPath = (dir: string) => dir.split('/').map(encodeURIComponent).join('/')
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Every document's slides run the same viewer app: it moves to the site's `_app/<key>/`, beside the web pages' own,
|
|
64
|
+
* so a reader downloads it once for all the presentations of the site, and the slides' page points there.
|
|
65
|
+
*/
|
|
66
|
+
function shareSlidesApp(slides: string, slidesBase: string, outDir: string, base: string): void {
|
|
67
|
+
const app = join(slides, '_app')
|
|
68
|
+
if (!existsSync(app)) return
|
|
69
|
+
for (const key of readdirSync(app)) if (!existsSync(join(outDir, '_app', key))) cpSync(join(app, key), join(outDir, '_app', key), { recursive: true })
|
|
70
|
+
rmSync(app, { recursive: true, force: true })
|
|
71
|
+
const page = join(slides, 'index.html')
|
|
72
|
+
writeFileSync(page, readFileSync(page, 'utf8').replaceAll(`${slidesBase}_app/`, `${base}_app/`))
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
/**
|
|
60
76
|
* The presentation forms a document asks for (`metadata.renderers.slides` or `lecture`), set to be served below its
|
|
61
77
|
* pages at `prefix`: the slides at `slides/`, and the web pages and the slides linked to each other.
|