-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (61 loc) · 1.86 KB
/
main.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
const { readdirSync, copyFileSync } = require('fs');
const { extname, dirname, join } = require('path');
const { userInfo } = require('os');
const { fileURLToPath } = require('url');
function defaultViteConfig(args = {}) {
const entry = args.entry ?? 'main.ts';
const outDir = args.outDir ?? 'dist';
const destDir = args.destDir ?? '/Library/Containers/app.cyan.markedit/Data/Documents/scripts/';
const rootDir = (() => {
const stackTrace = Error.prepareStackTrace;
try {
Error.prepareStackTrace = (_, stack) => stack;
const error = new Error();
const stack = error.stack;
return dirname(fileURLToPath(stack[2].getFileName()));
} finally {
Error.prepareStackTrace = stackTrace;
}
})();
return {
build: {
outDir,
rollupOptions: {
external: [
'markedit-api',
'@codemirror/view',
'@codemirror/state',
'@codemirror/language',
'@codemirror/commands',
'@codemirror/search',
'@lezer/common',
'@lezer/highlight',
'@lezer/markdown',
'@lezer/lr',
],
},
lib: {
entry,
formats: ['cjs'],
},
},
plugins: [
{
name: 'markedit-copy-dist-file',
closeBundle: () => {
const distDir = join(rootDir, outDir);
const filename = readdirSync(distDir).find(name => extname(name) === '.js');
if (filename === undefined) {
console.error('Failed to find generated .js file in dist directory.');
return;
}
const sourcePath = join(distDir, filename);
const destPath = join(userInfo().homedir, destDir, filename);
copyFileSync(sourcePath, destPath);
console.log(`Successfully deployed to ${destPath}.`);
},
},
],
};
}
module.exports = { defaultViteConfig };