annotate esbuild.config.mjs @ 53:f2e066bbe343

Handle errors around reading the state database file.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 02 Oct 2023 10:07:26 -0700
parents bdaa6e2c18d6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import esbuild from "esbuild";
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import process from "process";
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import builtins from 'builtin-modules'
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 const banner =
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 `/*
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
48
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
8
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
9 If you want to view the source, please visit one of the following:
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
10 - https://hg.bolt80.com/obsidian-remember-file-state
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
11 - https://hg.sr.ht/~ludovicchabant/obsidian-remember-file-state
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
12 - https://github.com/ludovicchabant/obsidian-remember-file-state
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 */
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 `;
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 const prod = (process.argv[2] === 'production');
42
d52beb77d109 Better error message for incorrect usage of dogfood build mode
Ludovic Chabant <ludovic@chabant.com>
parents: 34
diff changeset
17 const dogfood = (process.argv[2] === 'dogfood');
19
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
18
42
d52beb77d109 Better error message for incorrect usage of dogfood build mode
Ludovic Chabant <ludovic@chabant.com>
parents: 34
diff changeset
19 var outdir = (dogfood ? process.argv[3] : '');
32
141f0a7d1986 Better error handling for npm dogfood command. Expand the README info.
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
20 if (outdir != undefined && outdir != '') {
24
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
21 if (outdir.slice(-1) != '/' && outdir.slice(-1) != "\\") {
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
22 outdir += '/';
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
23 }
42
d52beb77d109 Better error message for incorrect usage of dogfood build mode
Ludovic Chabant <ludovic@chabant.com>
parents: 34
diff changeset
24 } else if (dogfood) {
32
141f0a7d1986 Better error handling for npm dogfood command. Expand the README info.
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
25 throw("Please provide an output directory to put the dog food into");
24
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
26 }
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
27
61fd7dde51d3 Fix build script
Ludovic Chabant <ludovic@chabant.com>
parents: 19
diff changeset
28 const outfile = outdir + 'main.js';
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29
48
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
30 const context = await esbuild.context({
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 banner: {
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 js: banner,
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 },
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 entryPoints: ['src/main.ts'],
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 bundle: true,
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 external: [
19
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
37 'obsidian',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
38 'electron',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
39 '@codemirror/autocomplete',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
40 '@codemirror/closebrackets',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
41 '@codemirror/collab',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
42 '@codemirror/commands',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
43 '@codemirror/comment',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
44 '@codemirror/fold',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
45 '@codemirror/gutter',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
46 '@codemirror/highlight',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
47 '@codemirror/history',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
48 '@codemirror/language',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
49 '@codemirror/lint',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
50 '@codemirror/matchbrackets',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
51 '@codemirror/panel',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
52 '@codemirror/rangeset',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
53 '@codemirror/rectangular-selection',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
54 '@codemirror/search',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
55 '@codemirror/state',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
56 '@codemirror/stream-parser',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
57 '@codemirror/text',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
58 '@codemirror/tooltip',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
59 '@codemirror/view',
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
60 ...builtins],
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 format: 'cjs',
48
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
62 target: 'es2018',
0
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 logLevel: "info",
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 sourcemap: prod ? false : 'inline',
7975d7c73f8a Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 treeShaking: true,
19
2a9e941c96ee Bring new build tools from the sample plugin project
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
66 outfile: outfile,
48
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
67 });
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
68
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
69 if (prod) {
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
70 await context.rebuild();
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
71 process.exit(0);
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
72 } else {
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
73 await context.watch();
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
74 }
bdaa6e2c18d6 Update build script to newest esbuild APIs.
Ludovic Chabant <ludovic@chabant.com>
parents: 42
diff changeset
75