-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
43 lines (40 loc) · 1.34 KB
/
esbuild.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
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
const manifestJson = JSON.parse(fs.readFileSync('./manifest.json'));
manifestJson.version = packageJson.version;
fs.writeFileSync('./manifest.json', JSON.stringify(manifestJson, null, 2));
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifestJson, null, 2));
// Copy styles.css to dist folder
fs.copyFileSync('./src/styles.css', './dist/styles.css');
const destination_vaults = [
'sc-test-vault',
'obsidian-1',
];
// Build the project
esbuild.build({
entryPoints: ['src/index.js'],
outfile: 'dist/main.js',
format: 'cjs',
bundle: true,
write: true,
sourcemap: 'inline',
target: "es2018",
logLevel: "info",
treeShaking: true,
external: [
'obsidian',
'crypto',
],
}).then(() => {
// Copy the dist folder to ../DESTINATION_VAULT/.obsidian/plugins/smart-connections/
const srcDir = path.join(__dirname, 'dist');
for(let vault of destination_vaults) {
const destDir = path.join(__dirname, '..', vault, '.obsidian', 'plugins', 'smart-connections');
fs.mkdirSync(destDir, { recursive: true });
fs.readdirSync(srcDir).forEach(file => {
fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file));
});
}
}).catch(() => process.exit(1));