forked from Kenan2000/CDDA-Structured-Kenan-Modpack
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwiki.js
73 lines (69 loc) · 3.23 KB
/
wiki.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fs = require('fs-jetpack');
const path = require('path');
const { execSync } = require('child_process');
const repoFolder = path.dirname(__filename);
const folderToServe = path.join(repoFolder, 'public-dist');
const wikiFolder = path.join(repoFolder, 'wiki');
// cross-env TIDDLYWIKI_PLUGIN_PATH='node_modules/tiddlywiki/plugins/published' TIDDLYWIKI_THEME_PATH='${wikiFolderName}/themes'
process.env.TIDDLYWIKI_PLUGIN_PATH = `${wikiFolder}/plugins`;
process.env.TIDDLYWIKI_THEME_PATH = `${wikiFolder}/themes`;
const execAndLog = (command, options) => console.log(String(execSync(command, options)));
module.exports = function build() {
// npm run build:prepare
execAndLog(`rm -rf ${folderToServe}`, { cwd: repoFolder });
// npm run build:public
// execAndLog(`cp -r ${repoFolder}/public/ ${folderToServe}`, { cwd: repoFolder });
// try copy some static assets, don't cause error if some of them been removed by the user
// try {
// // npm run build:public
// execAndLog(`cp ${repoFolder}/tiddlers/favicon.ico ${folderToServe}/favicon.ico`, { cwd: repoFolder });
// execAndLog(`cp ${repoFolder}/tiddlers/TiddlyWikiIconWhite.png ${folderToServe}/TiddlyWikiIconWhite.png`, {
// cwd: repoFolder,
// });
// execAndLog(`cp ${repoFolder}/tiddlers/TiddlyWikiIconBlack.png ${folderToServe}/TiddlyWikiIconBlack.png`, {
// cwd: repoFolder,
// });
// } catch (error) {
// console.log(error);
// }
// npm run build:nodejs2html
execAndLog(`cp ${repoFolder}/README.md ${wikiFolder}/tiddlers/README.md`, {
cwd: repoFolder,
});
fs.write(
`${wikiFolder}/tiddlers/README.md.meta`,
`creator: 林一二
title: README.md
type: text/x-markdown`
);
execAndLog(`tiddlywiki ${wikiFolder} --build index`, { cwd: wikiFolder });
// execAndLog(`tiddlywiki ${repoFolder} --build externaljs`, { cwd: repoFolder });
// npm run build:sitemap
// execAndLog(
// `tiddlywiki . --rendertiddler sitemap sitemap.xml text/plain && mv ${repoFolder}/output/sitemap.xml ${folderToServe}/sitemap.xml`,
// { cwd: repoFolder }
// );
// npm run build:minifyHTML
const htmlOutputPath = `${folderToServe}/index.html`;
execAndLog(`mkdir -p ${folderToServe}`, {
cwd: repoFolder,
});
execAndLog(
`html-minifier-terser -c ../html-minifier-terser.config.json -o ${htmlOutputPath} ${wikiFolder}/output/index.html`,
{ cwd: wikiFolder }
);
// execAndLog(`cp ${wikiFolder}/output/index.html ${htmlOutputPath}`, {
// cwd: repoFolder,
// });
// build dll.js and config tw to load it
// original filename contains invalid char, will cause static server unable to load it
// const htmlContent = fs.readFileSync(htmlOutputPath, 'utf-8');
// fs.writeFileSync(htmlOutputPath, htmlContent.replace('%24%3A%2Fcore%2Ftemplates%2Ftiddlywiki5.js', 'tiddlywiki5.js'));
// execAndLog(`mv ${repoFolder}/output/tiddlywiki5.js ${folderToServe}/tiddlywiki5.js`, { cwd: repoFolder });
// npm run build:precache
// execAndLog(`workbox injectManifest workbox-config.js`, { cwd: repoFolder });
// npm run build:clean
// execAndLog(`rm -r ${repoFolder}/output`, { cwd: repoFolder });
// npm run build:pluginLibrary
// execAndLog(`tiddlywiki ${repoFolder} --output ${folderToServe}/library --build library`, { cwd: repoFolder });
};