obsidian-plugin-config 1.4.6 â 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -13
- package/.injection-info.json +5 -5
- package/.vscode/settings.json +11 -11
- package/.vscode/tasks.json +118 -118
- package/bin/obsidian-inject.js +1 -1
- package/eslint.config.mts +64 -64
- package/package.json +1 -1
- package/scripts/esbuild.config.ts +268 -268
- package/scripts/help.ts +152 -152
- package/scripts/utils.ts +151 -151
- package/templates/.vscode/tasks.json +8 -0
- package/templates/package.json +1 -1
- package/tsconfig.json +30 -30
- package/versions.json +3 -1
|
@@ -1,268 +1,268 @@
|
|
|
1
|
-
import esbuild from 'esbuild';
|
|
2
|
-
import process from 'process';
|
|
3
|
-
import builtins from 'builtin-modules';
|
|
4
|
-
import { config } from 'dotenv';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { readFileSync } from 'fs';
|
|
7
|
-
import { rm } from 'fs/promises';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import {
|
|
10
|
-
isValidPath,
|
|
11
|
-
copyFilesToTargetDir,
|
|
12
|
-
askQuestion,
|
|
13
|
-
createReadlineInterface
|
|
14
|
-
} from './utils.js';
|
|
15
|
-
|
|
16
|
-
// Determine the plugin directory (where the script is called from)
|
|
17
|
-
const pluginDir = process.cwd();
|
|
18
|
-
|
|
19
|
-
// Create readline interface for prompts
|
|
20
|
-
const rl = createReadlineInterface();
|
|
21
|
-
|
|
22
|
-
async function promptForVaultPath(envKey: string): Promise<string> {
|
|
23
|
-
const vaultType = envKey === 'REAL_VAULT' ? 'real' : 'test';
|
|
24
|
-
const usage =
|
|
25
|
-
envKey === 'REAL_VAULT'
|
|
26
|
-
? 'for final plugin installation'
|
|
27
|
-
: 'for development and testing';
|
|
28
|
-
|
|
29
|
-
console.log(`â ${envKey} path is required ${usage}`);
|
|
30
|
-
const path = await askQuestion(
|
|
31
|
-
`đ Enter your ${vaultType} vault path (or Ctrl+C to cancel): `,
|
|
32
|
-
rl
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
if (!path) {
|
|
36
|
-
console.log('â No path provided, exiting...');
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return path;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
44
|
-
const envPath = path.join(pluginDir, '.env');
|
|
45
|
-
let envContent = '';
|
|
46
|
-
|
|
47
|
-
// Read existing .env if it exists
|
|
48
|
-
try {
|
|
49
|
-
envContent = readFileSync(envPath, 'utf8');
|
|
50
|
-
} catch {
|
|
51
|
-
// File doesn't exist, start with empty content
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Update or add the variable
|
|
55
|
-
const regex = new RegExp(`^${envKey}=.*$`, 'm');
|
|
56
|
-
const newLine = `${envKey}=${vaultPath}`;
|
|
57
|
-
|
|
58
|
-
if (regex.test(envContent)) {
|
|
59
|
-
envContent = envContent.replace(regex, newLine);
|
|
60
|
-
} else {
|
|
61
|
-
envContent += envContent.endsWith('\n') ? '' : '\n';
|
|
62
|
-
envContent += newLine + '\n';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Write back to .env
|
|
66
|
-
await import('fs').then((fs) => fs.writeFileSync(envPath, envContent));
|
|
67
|
-
console.log(`â
Updated ${envKey} in .env file`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function validateVaultPath(vaultPath: string): boolean {
|
|
71
|
-
// Check if the path contains .obsidian directory
|
|
72
|
-
const obsidianPath = path.join(vaultPath, '.obsidian');
|
|
73
|
-
const pluginsPath = path.join(vaultPath, '.obsidian', 'plugins');
|
|
74
|
-
|
|
75
|
-
return fs.existsSync(obsidianPath) && fs.existsSync(pluginsPath);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function getVaultPath(vaultPath: string): string {
|
|
79
|
-
// Validate that this is a proper vault path
|
|
80
|
-
if (!validateVaultPath(vaultPath)) {
|
|
81
|
-
console.error(`â Invalid vault path: ${vaultPath}`);
|
|
82
|
-
console.error(` The path must contain a .obsidian/plugins directory`);
|
|
83
|
-
console.error(` Please enter a valid Obsidian vault path`);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Check if the path already contains the plugins directory path
|
|
88
|
-
const pluginsPath = path.join('.obsidian', 'plugins');
|
|
89
|
-
if (vaultPath.includes(pluginsPath)) {
|
|
90
|
-
return path.join(vaultPath, manifest.id);
|
|
91
|
-
} else {
|
|
92
|
-
return path.join(vaultPath, '.obsidian', 'plugins', manifest.id);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const manifestPath = path.join(pluginDir, 'manifest.json');
|
|
96
|
-
|
|
97
|
-
// Check if manifest exists (for plugin-config itself, it might not exist)
|
|
98
|
-
if (!fs.existsSync(manifestPath)) {
|
|
99
|
-
console.log(
|
|
100
|
-
'â ī¸ No manifest.json found - this script is designed for Obsidian plugins'
|
|
101
|
-
);
|
|
102
|
-
console.log(" If you're building plugin-config itself, use 'tsc' instead");
|
|
103
|
-
process.exit(0);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
107
|
-
|
|
108
|
-
config();
|
|
109
|
-
|
|
110
|
-
const EXTERNAL_DEPS = [
|
|
111
|
-
'obsidian',
|
|
112
|
-
'electron',
|
|
113
|
-
'@codemirror/autocomplete',
|
|
114
|
-
'@codemirror/collab',
|
|
115
|
-
'@codemirror/commands',
|
|
116
|
-
'@codemirror/language',
|
|
117
|
-
'@codemirror/lint',
|
|
118
|
-
'@codemirror/search',
|
|
119
|
-
'@codemirror/state',
|
|
120
|
-
'@codemirror/view',
|
|
121
|
-
'@lezer/common',
|
|
122
|
-
'@lezer/highlight',
|
|
123
|
-
'@lezer/lr',
|
|
124
|
-
...builtins
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
const BANNER = `/*
|
|
128
|
-
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
129
|
-
if you want to view the source, please visit the github repository of this plugin
|
|
130
|
-
*/`;
|
|
131
|
-
|
|
132
|
-
async function validateEnvironment(): Promise<void> {
|
|
133
|
-
const srcMainPath = path.join(pluginDir, 'src/main.ts');
|
|
134
|
-
if (!(await isValidPath(srcMainPath))) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
'Invalid path for src/main.ts. main.ts must be in the src directory'
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
if (!(await isValidPath(manifestPath))) {
|
|
140
|
-
throw new Error('Invalid path for manifest.json');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function getBuildPath(isProd: boolean): Promise<string> {
|
|
145
|
-
// Check if we should use real vault (either -r flag or "real" argument)
|
|
146
|
-
const useRealVault = process.argv.includes('-r') || process.argv.includes('real');
|
|
147
|
-
|
|
148
|
-
// If production build without redirection, return plugin directory
|
|
149
|
-
if (isProd && !useRealVault) {
|
|
150
|
-
return pluginDir;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Determine which path to use
|
|
154
|
-
const envKey = useRealVault ? 'REAL_VAULT' : 'TEST_VAULT';
|
|
155
|
-
const vaultPath = process.env[envKey]?.trim();
|
|
156
|
-
|
|
157
|
-
// If empty or undefined, we're already in the plugin folder
|
|
158
|
-
if (!vaultPath) {
|
|
159
|
-
// Check if we're in Obsidian plugins folder
|
|
160
|
-
const currentPath = process.cwd();
|
|
161
|
-
const isInObsidianPlugins =
|
|
162
|
-
currentPath.includes('.obsidian/plugins') ||
|
|
163
|
-
currentPath.includes('.obsidian\\plugins');
|
|
164
|
-
|
|
165
|
-
if (isInObsidianPlugins) {
|
|
166
|
-
// In obsidian/plugins: allow in-place development
|
|
167
|
-
console.log(`âšī¸ Building in Obsidian plugins folder (in-place development)`);
|
|
168
|
-
return pluginDir;
|
|
169
|
-
} else {
|
|
170
|
-
// External development: prompt for missing vault path
|
|
171
|
-
const newPath = await promptForVaultPath(envKey);
|
|
172
|
-
await updateEnvFile(envKey, newPath);
|
|
173
|
-
config();
|
|
174
|
-
return getVaultPath(newPath);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// If we reach here, use the vault path directly
|
|
179
|
-
return getVaultPath(vaultPath);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function createBuildContext(
|
|
183
|
-
buildPath: string,
|
|
184
|
-
isProd: boolean,
|
|
185
|
-
entryPoints: string[]
|
|
186
|
-
): Promise<esbuild.BuildContext> {
|
|
187
|
-
return await esbuild.context({
|
|
188
|
-
banner: { js: BANNER },
|
|
189
|
-
minify: isProd,
|
|
190
|
-
entryPoints,
|
|
191
|
-
bundle: true,
|
|
192
|
-
external: EXTERNAL_DEPS,
|
|
193
|
-
format: 'cjs',
|
|
194
|
-
target: 'esNext',
|
|
195
|
-
platform: 'node',
|
|
196
|
-
logLevel: 'info',
|
|
197
|
-
sourcemap: isProd ? false : 'inline',
|
|
198
|
-
treeShaking: true,
|
|
199
|
-
outdir: buildPath,
|
|
200
|
-
outbase: path.join(pluginDir, 'src'),
|
|
201
|
-
plugins: [
|
|
202
|
-
{
|
|
203
|
-
name: 'copy-to-plugins-folder',
|
|
204
|
-
setup: (build): void => {
|
|
205
|
-
build.onEnd(async () => {
|
|
206
|
-
// if real or build
|
|
207
|
-
if (isProd) {
|
|
208
|
-
if (
|
|
209
|
-
process.argv.includes('-r') ||
|
|
210
|
-
process.argv.includes('real')
|
|
211
|
-
) {
|
|
212
|
-
await copyFilesToTargetDir(buildPath);
|
|
213
|
-
console.log(`Successfully installed in ${buildPath}`);
|
|
214
|
-
} else {
|
|
215
|
-
const folderToRemove = path.join(buildPath, '_.._');
|
|
216
|
-
if (await isValidPath(folderToRemove)) {
|
|
217
|
-
await rm(folderToRemove, { recursive: true });
|
|
218
|
-
}
|
|
219
|
-
console.log('Built done in initial folder');
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
// if watch (dev)
|
|
223
|
-
else {
|
|
224
|
-
await copyFilesToTargetDir(buildPath);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
]
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async function main(): Promise<void> {
|
|
234
|
-
try {
|
|
235
|
-
await validateEnvironment();
|
|
236
|
-
const isProd = process.argv[2] === 'production';
|
|
237
|
-
const buildPath = await getBuildPath(isProd);
|
|
238
|
-
console.log(
|
|
239
|
-
buildPath === pluginDir
|
|
240
|
-
? 'Building in initial folder'
|
|
241
|
-
: `Building in ${buildPath}`
|
|
242
|
-
);
|
|
243
|
-
const srcStylesPath = path.join(pluginDir, 'src/styles.css');
|
|
244
|
-
const rootStylesPath = path.join(pluginDir, 'styles.css');
|
|
245
|
-
const stylePath = (await isValidPath(srcStylesPath))
|
|
246
|
-
? srcStylesPath
|
|
247
|
-
: (await isValidPath(rootStylesPath))
|
|
248
|
-
? rootStylesPath
|
|
249
|
-
: '';
|
|
250
|
-
const mainTsPath = path.join(pluginDir, 'src/main.ts');
|
|
251
|
-
const entryPoints = stylePath ? [mainTsPath, stylePath] : [mainTsPath];
|
|
252
|
-
const context = await createBuildContext(buildPath, isProd, entryPoints);
|
|
253
|
-
|
|
254
|
-
if (isProd) {
|
|
255
|
-
await context.rebuild();
|
|
256
|
-
rl.close();
|
|
257
|
-
process.exit(0);
|
|
258
|
-
} else {
|
|
259
|
-
await context.watch();
|
|
260
|
-
}
|
|
261
|
-
} catch (error) {
|
|
262
|
-
console.error('Build failed:', error);
|
|
263
|
-
rl.close();
|
|
264
|
-
process.exit(1);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
main().catch(console.error);
|
|
1
|
+
import esbuild from 'esbuild';
|
|
2
|
+
import process from 'process';
|
|
3
|
+
import builtins from 'builtin-modules';
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { rm } from 'fs/promises';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import {
|
|
10
|
+
isValidPath,
|
|
11
|
+
copyFilesToTargetDir,
|
|
12
|
+
askQuestion,
|
|
13
|
+
createReadlineInterface
|
|
14
|
+
} from './utils.js';
|
|
15
|
+
|
|
16
|
+
// Determine the plugin directory (where the script is called from)
|
|
17
|
+
const pluginDir = process.cwd();
|
|
18
|
+
|
|
19
|
+
// Create readline interface for prompts
|
|
20
|
+
const rl = createReadlineInterface();
|
|
21
|
+
|
|
22
|
+
async function promptForVaultPath(envKey: string): Promise<string> {
|
|
23
|
+
const vaultType = envKey === 'REAL_VAULT' ? 'real' : 'test';
|
|
24
|
+
const usage =
|
|
25
|
+
envKey === 'REAL_VAULT'
|
|
26
|
+
? 'for final plugin installation'
|
|
27
|
+
: 'for development and testing';
|
|
28
|
+
|
|
29
|
+
console.log(`â ${envKey} path is required ${usage}`);
|
|
30
|
+
const path = await askQuestion(
|
|
31
|
+
`đ Enter your ${vaultType} vault path (or Ctrl+C to cancel): `,
|
|
32
|
+
rl
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!path) {
|
|
36
|
+
console.log('â No path provided, exiting...');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return path;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function updateEnvFile(envKey: string, vaultPath: string): Promise<void> {
|
|
44
|
+
const envPath = path.join(pluginDir, '.env');
|
|
45
|
+
let envContent = '';
|
|
46
|
+
|
|
47
|
+
// Read existing .env if it exists
|
|
48
|
+
try {
|
|
49
|
+
envContent = readFileSync(envPath, 'utf8');
|
|
50
|
+
} catch {
|
|
51
|
+
// File doesn't exist, start with empty content
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Update or add the variable
|
|
55
|
+
const regex = new RegExp(`^${envKey}=.*$`, 'm');
|
|
56
|
+
const newLine = `${envKey}=${vaultPath}`;
|
|
57
|
+
|
|
58
|
+
if (regex.test(envContent)) {
|
|
59
|
+
envContent = envContent.replace(regex, newLine);
|
|
60
|
+
} else {
|
|
61
|
+
envContent += envContent.endsWith('\n') ? '' : '\n';
|
|
62
|
+
envContent += newLine + '\n';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Write back to .env
|
|
66
|
+
await import('fs').then((fs) => fs.writeFileSync(envPath, envContent));
|
|
67
|
+
console.log(`â
Updated ${envKey} in .env file`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function validateVaultPath(vaultPath: string): boolean {
|
|
71
|
+
// Check if the path contains .obsidian directory
|
|
72
|
+
const obsidianPath = path.join(vaultPath, '.obsidian');
|
|
73
|
+
const pluginsPath = path.join(vaultPath, '.obsidian', 'plugins');
|
|
74
|
+
|
|
75
|
+
return fs.existsSync(obsidianPath) && fs.existsSync(pluginsPath);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getVaultPath(vaultPath: string): string {
|
|
79
|
+
// Validate that this is a proper vault path
|
|
80
|
+
if (!validateVaultPath(vaultPath)) {
|
|
81
|
+
console.error(`â Invalid vault path: ${vaultPath}`);
|
|
82
|
+
console.error(` The path must contain a .obsidian/plugins directory`);
|
|
83
|
+
console.error(` Please enter a valid Obsidian vault path`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Check if the path already contains the plugins directory path
|
|
88
|
+
const pluginsPath = path.join('.obsidian', 'plugins');
|
|
89
|
+
if (vaultPath.includes(pluginsPath)) {
|
|
90
|
+
return path.join(vaultPath, manifest.id);
|
|
91
|
+
} else {
|
|
92
|
+
return path.join(vaultPath, '.obsidian', 'plugins', manifest.id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const manifestPath = path.join(pluginDir, 'manifest.json');
|
|
96
|
+
|
|
97
|
+
// Check if manifest exists (for plugin-config itself, it might not exist)
|
|
98
|
+
if (!fs.existsSync(manifestPath)) {
|
|
99
|
+
console.log(
|
|
100
|
+
'â ī¸ No manifest.json found - this script is designed for Obsidian plugins'
|
|
101
|
+
);
|
|
102
|
+
console.log(" If you're building plugin-config itself, use 'tsc' instead");
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
107
|
+
|
|
108
|
+
config();
|
|
109
|
+
|
|
110
|
+
const EXTERNAL_DEPS = [
|
|
111
|
+
'obsidian',
|
|
112
|
+
'electron',
|
|
113
|
+
'@codemirror/autocomplete',
|
|
114
|
+
'@codemirror/collab',
|
|
115
|
+
'@codemirror/commands',
|
|
116
|
+
'@codemirror/language',
|
|
117
|
+
'@codemirror/lint',
|
|
118
|
+
'@codemirror/search',
|
|
119
|
+
'@codemirror/state',
|
|
120
|
+
'@codemirror/view',
|
|
121
|
+
'@lezer/common',
|
|
122
|
+
'@lezer/highlight',
|
|
123
|
+
'@lezer/lr',
|
|
124
|
+
...builtins
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const BANNER = `/*
|
|
128
|
+
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
129
|
+
if you want to view the source, please visit the github repository of this plugin
|
|
130
|
+
*/`;
|
|
131
|
+
|
|
132
|
+
async function validateEnvironment(): Promise<void> {
|
|
133
|
+
const srcMainPath = path.join(pluginDir, 'src/main.ts');
|
|
134
|
+
if (!(await isValidPath(srcMainPath))) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
'Invalid path for src/main.ts. main.ts must be in the src directory'
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (!(await isValidPath(manifestPath))) {
|
|
140
|
+
throw new Error('Invalid path for manifest.json');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function getBuildPath(isProd: boolean): Promise<string> {
|
|
145
|
+
// Check if we should use real vault (either -r flag or "real" argument)
|
|
146
|
+
const useRealVault = process.argv.includes('-r') || process.argv.includes('real');
|
|
147
|
+
|
|
148
|
+
// If production build without redirection, return plugin directory
|
|
149
|
+
if (isProd && !useRealVault) {
|
|
150
|
+
return pluginDir;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Determine which path to use
|
|
154
|
+
const envKey = useRealVault ? 'REAL_VAULT' : 'TEST_VAULT';
|
|
155
|
+
const vaultPath = process.env[envKey]?.trim();
|
|
156
|
+
|
|
157
|
+
// If empty or undefined, we're already in the plugin folder
|
|
158
|
+
if (!vaultPath) {
|
|
159
|
+
// Check if we're in Obsidian plugins folder
|
|
160
|
+
const currentPath = process.cwd();
|
|
161
|
+
const isInObsidianPlugins =
|
|
162
|
+
currentPath.includes('.obsidian/plugins') ||
|
|
163
|
+
currentPath.includes('.obsidian\\plugins');
|
|
164
|
+
|
|
165
|
+
if (isInObsidianPlugins) {
|
|
166
|
+
// In obsidian/plugins: allow in-place development
|
|
167
|
+
console.log(`âšī¸ Building in Obsidian plugins folder (in-place development)`);
|
|
168
|
+
return pluginDir;
|
|
169
|
+
} else {
|
|
170
|
+
// External development: prompt for missing vault path
|
|
171
|
+
const newPath = await promptForVaultPath(envKey);
|
|
172
|
+
await updateEnvFile(envKey, newPath);
|
|
173
|
+
config();
|
|
174
|
+
return getVaultPath(newPath);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// If we reach here, use the vault path directly
|
|
179
|
+
return getVaultPath(vaultPath);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function createBuildContext(
|
|
183
|
+
buildPath: string,
|
|
184
|
+
isProd: boolean,
|
|
185
|
+
entryPoints: string[]
|
|
186
|
+
): Promise<esbuild.BuildContext> {
|
|
187
|
+
return await esbuild.context({
|
|
188
|
+
banner: { js: BANNER },
|
|
189
|
+
minify: isProd,
|
|
190
|
+
entryPoints,
|
|
191
|
+
bundle: true,
|
|
192
|
+
external: EXTERNAL_DEPS,
|
|
193
|
+
format: 'cjs',
|
|
194
|
+
target: 'esNext',
|
|
195
|
+
platform: 'node',
|
|
196
|
+
logLevel: 'info',
|
|
197
|
+
sourcemap: isProd ? false : 'inline',
|
|
198
|
+
treeShaking: true,
|
|
199
|
+
outdir: buildPath,
|
|
200
|
+
outbase: path.join(pluginDir, 'src'),
|
|
201
|
+
plugins: [
|
|
202
|
+
{
|
|
203
|
+
name: 'copy-to-plugins-folder',
|
|
204
|
+
setup: (build): void => {
|
|
205
|
+
build.onEnd(async () => {
|
|
206
|
+
// if real or build
|
|
207
|
+
if (isProd) {
|
|
208
|
+
if (
|
|
209
|
+
process.argv.includes('-r') ||
|
|
210
|
+
process.argv.includes('real')
|
|
211
|
+
) {
|
|
212
|
+
await copyFilesToTargetDir(buildPath);
|
|
213
|
+
console.log(`Successfully installed in ${buildPath}`);
|
|
214
|
+
} else {
|
|
215
|
+
const folderToRemove = path.join(buildPath, '_.._');
|
|
216
|
+
if (await isValidPath(folderToRemove)) {
|
|
217
|
+
await rm(folderToRemove, { recursive: true });
|
|
218
|
+
}
|
|
219
|
+
console.log('Built done in initial folder');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// if watch (dev)
|
|
223
|
+
else {
|
|
224
|
+
await copyFilesToTargetDir(buildPath);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function main(): Promise<void> {
|
|
234
|
+
try {
|
|
235
|
+
await validateEnvironment();
|
|
236
|
+
const isProd = process.argv[2] === 'production';
|
|
237
|
+
const buildPath = await getBuildPath(isProd);
|
|
238
|
+
console.log(
|
|
239
|
+
buildPath === pluginDir
|
|
240
|
+
? 'Building in initial folder'
|
|
241
|
+
: `Building in ${buildPath}`
|
|
242
|
+
);
|
|
243
|
+
const srcStylesPath = path.join(pluginDir, 'src/styles.css');
|
|
244
|
+
const rootStylesPath = path.join(pluginDir, 'styles.css');
|
|
245
|
+
const stylePath = (await isValidPath(srcStylesPath))
|
|
246
|
+
? srcStylesPath
|
|
247
|
+
: (await isValidPath(rootStylesPath))
|
|
248
|
+
? rootStylesPath
|
|
249
|
+
: '';
|
|
250
|
+
const mainTsPath = path.join(pluginDir, 'src/main.ts');
|
|
251
|
+
const entryPoints = stylePath ? [mainTsPath, stylePath] : [mainTsPath];
|
|
252
|
+
const context = await createBuildContext(buildPath, isProd, entryPoints);
|
|
253
|
+
|
|
254
|
+
if (isProd) {
|
|
255
|
+
await context.rebuild();
|
|
256
|
+
rl.close();
|
|
257
|
+
process.exit(0);
|
|
258
|
+
} else {
|
|
259
|
+
await context.watch();
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error('Build failed:', error);
|
|
263
|
+
rl.close();
|
|
264
|
+
process.exit(1);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
main().catch(console.error);
|