-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-demo-html.mjs
47 lines (42 loc) · 1.92 KB
/
build-demo-html.mjs
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
/* eslint-disable unicorn/prevent-abbreviations */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { cd } from 'zx';
if (process.platform === 'win32') {
$.prefix = '';
$.shell = 'pwsh.exe';
}
/**
* Put plugin into demo folder
*/
const pluginInfo = fs.readJsonSync('src/plugin.info');
const [_, __, author, name] = pluginInfo.title.split('/');
const pluginTitle = `${author}/${name}`;
const repoDirectory = path.resolve(__dirname, '..');
const distDirectory = path.resolve(repoDirectory, 'dist');
const jsonPluginFileName = `$__plugins_${pluginTitle.replace('/', '_')}-dev.json`;
// copy demo
await fs.copy(path.join(repoDirectory, 'demo'), distDirectory);
// copy json plugin
await fs.copy(path.join(distDirectory, 'out', jsonPluginFileName), path.join(distDirectory, 'tiddlers', jsonPluginFileName));
/**
* Make demo html file
*/
const htmlPath = `${distDirectory}/output/index.html`;
/**
* Same as `cross-env TIDDLYWIKI_PLUGIN_PATH='node_modules/tiddlywiki/plugins/published' TIDDLYWIKI_THEME_PATH='${wikiFolderName}/themes'`
*
* But we don't need this, because we put the JSON plugin into the dist folder, it will be loaded automatically
*/
// process.env.TIDDLYWIKI_PLUGIN_PATH = `${distDir}/plugins`;
cd(distDirectory);
await $`tiddlywiki . --build externalimages`;
await $`tiddlywiki . --build externaljs`;
// 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(htmlPath, 'utf8');
const htmlContentWithCorrectJsPath = htmlContent.replaceAll('%24%3A%2Fcore%2Ftemplates%2Ftiddlywiki5.js', 'tiddlywiki5.js');
await fs.writeFile(htmlPath, htmlContentWithCorrectJsPath);