@btc-vision/cli 1.0.5 → 1.0.7
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/build/index.js +3 -4
- package/build/lib/config.js +1 -6
- package/build/lib/ipfs.d.ts +0 -2
- package/build/lib/ipfs.js +29 -32
- package/build/lib/wallet.js +1 -1
- package/package.json +4 -1
- package/.gitattributes +0 -2
- package/.github/dependabot.yml +0 -9
- package/.github/workflows/ci.yml +0 -48
- package/.prettierrc.json +0 -12
- package/CONTRIBUTING.md +0 -56
- package/NOTICE +0 -17
- package/SECURITY.md +0 -35
- package/eslint.config.js +0 -41
- package/gulpfile.js +0 -41
- package/src/commands/AcceptCommand.ts +0 -224
- package/src/commands/BaseCommand.ts +0 -59
- package/src/commands/CompileCommand.ts +0 -195
- package/src/commands/ConfigCommand.ts +0 -117
- package/src/commands/DeprecateCommand.ts +0 -193
- package/src/commands/InfoCommand.ts +0 -293
- package/src/commands/InitCommand.ts +0 -541
- package/src/commands/InstallCommand.ts +0 -179
- package/src/commands/KeygenCommand.ts +0 -157
- package/src/commands/ListCommand.ts +0 -169
- package/src/commands/LoginCommand.ts +0 -197
- package/src/commands/LogoutCommand.ts +0 -76
- package/src/commands/PublishCommand.ts +0 -340
- package/src/commands/ScopeRegisterCommand.ts +0 -164
- package/src/commands/SearchCommand.ts +0 -140
- package/src/commands/SignCommand.ts +0 -110
- package/src/commands/TransferCommand.ts +0 -363
- package/src/commands/UndeprecateCommand.ts +0 -167
- package/src/commands/UpdateCommand.ts +0 -200
- package/src/commands/VerifyCommand.ts +0 -228
- package/src/commands/WhoamiCommand.ts +0 -113
- package/src/index.ts +0 -88
- package/src/lib/PackageRegistry.abi.json +0 -765
- package/src/lib/PackageRegistry.abi.ts +0 -365
- package/src/lib/binary.ts +0 -338
- package/src/lib/config.ts +0 -265
- package/src/lib/credentials.ts +0 -176
- package/src/lib/ipfs.ts +0 -382
- package/src/lib/manifest.ts +0 -195
- package/src/lib/provider.ts +0 -121
- package/src/lib/registry.ts +0 -467
- package/src/lib/transaction.ts +0 -205
- package/src/lib/wallet.ts +0 -262
- package/src/types/PackageRegistry.ts +0 -344
- package/src/types/index.ts +0 -147
- package/tsconfig.json +0 -25
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Init command - Initialize a new OPNet plugin project
|
|
3
|
-
*
|
|
4
|
-
* @module commands/InitCommand
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as fs from 'fs';
|
|
8
|
-
import * as path from 'path';
|
|
9
|
-
import { confirm, input, select } from '@inquirer/prompts';
|
|
10
|
-
import { BaseCommand } from './BaseCommand.js';
|
|
11
|
-
import { validatePluginName } from '../lib/manifest.js';
|
|
12
|
-
|
|
13
|
-
interface InitOptions {
|
|
14
|
-
template: 'standalone' | 'library' | undefined;
|
|
15
|
-
yes?: boolean;
|
|
16
|
-
force?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class InitCommand extends BaseCommand {
|
|
20
|
-
constructor() {
|
|
21
|
-
super('init', 'Initialize a new OPNet plugin project');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected configure(): void {
|
|
25
|
-
this.command
|
|
26
|
-
.argument('[name]', 'Plugin name')
|
|
27
|
-
.option('-t, --template <type>', 'Template type (standalone, library)', 'standalone')
|
|
28
|
-
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
29
|
-
.option('--force', 'Overwrite existing files')
|
|
30
|
-
.action((name?: string, options?: InitOptions) => this.execute(name, options));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private async execute(name?: string, options?: InitOptions): Promise<void> {
|
|
34
|
-
try {
|
|
35
|
-
const config = await this.gatherConfig(name, options);
|
|
36
|
-
await this.createProject(config, options?.force);
|
|
37
|
-
|
|
38
|
-
this.logger.success('Plugin initialized successfully!');
|
|
39
|
-
this.logger.log('');
|
|
40
|
-
this.logger.log('Next steps:');
|
|
41
|
-
this.logger.log(' 1. npm install');
|
|
42
|
-
this.logger.log(' 2. Edit src/index.ts');
|
|
43
|
-
this.logger.log(' 3. npm run build');
|
|
44
|
-
this.logger.log(' 4. opnet compile');
|
|
45
|
-
this.logger.log('');
|
|
46
|
-
} catch (error) {
|
|
47
|
-
if (this.isUserCancelled(error)) {
|
|
48
|
-
this.logger.warn('Initialization cancelled.');
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
this.exitWithError(this.formatError(error));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private async gatherConfig(
|
|
56
|
-
name?: string,
|
|
57
|
-
options?: InitOptions,
|
|
58
|
-
): Promise<{
|
|
59
|
-
pluginName: string;
|
|
60
|
-
authorName: string;
|
|
61
|
-
authorEmail?: string;
|
|
62
|
-
description?: string;
|
|
63
|
-
pluginType: 'standalone' | 'library';
|
|
64
|
-
}> {
|
|
65
|
-
if (options?.yes && name) {
|
|
66
|
-
return {
|
|
67
|
-
pluginName: name,
|
|
68
|
-
authorName: 'Author',
|
|
69
|
-
pluginType: (options.template as 'standalone' | 'library') || 'standalone',
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.logger.info('\nOPNet Plugin Initialization\n');
|
|
74
|
-
|
|
75
|
-
const pluginName =
|
|
76
|
-
name ||
|
|
77
|
-
(await input({
|
|
78
|
-
message: 'Plugin name:',
|
|
79
|
-
default: path.basename(process.cwd()),
|
|
80
|
-
validate: (value) => {
|
|
81
|
-
const errors = validatePluginName(value);
|
|
82
|
-
return errors.length > 0 ? errors[0] : true;
|
|
83
|
-
},
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
const description = (await input({ message: 'Description:', default: '' })) || undefined;
|
|
87
|
-
const authorName = await input({
|
|
88
|
-
message: 'Author name:',
|
|
89
|
-
default: process.env.USER || 'Author',
|
|
90
|
-
});
|
|
91
|
-
const authorEmail =
|
|
92
|
-
(await input({ message: 'Author email (optional):', default: '' })) || undefined;
|
|
93
|
-
|
|
94
|
-
const pluginType = await select({
|
|
95
|
-
message: 'Plugin type:',
|
|
96
|
-
choices: [
|
|
97
|
-
{
|
|
98
|
-
name: 'Standalone',
|
|
99
|
-
value: 'standalone' as const,
|
|
100
|
-
description: 'Independent plugin',
|
|
101
|
-
},
|
|
102
|
-
{ name: 'Library', value: 'library' as const, description: 'Shared library' },
|
|
103
|
-
],
|
|
104
|
-
default: options?.template || 'standalone',
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return { pluginName, authorName, authorEmail, description, pluginType };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private async createProject(
|
|
111
|
-
config: {
|
|
112
|
-
pluginName: string;
|
|
113
|
-
authorName: string;
|
|
114
|
-
authorEmail?: string;
|
|
115
|
-
description?: string;
|
|
116
|
-
pluginType: 'standalone' | 'library';
|
|
117
|
-
},
|
|
118
|
-
force?: boolean,
|
|
119
|
-
): Promise<void> {
|
|
120
|
-
const nameErrors = validatePluginName(config.pluginName);
|
|
121
|
-
if (nameErrors.length > 0) {
|
|
122
|
-
this.exitWithError(`Invalid plugin name: ${nameErrors.join(', ')}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const projectDir = process.cwd();
|
|
126
|
-
const pluginJsonPath = path.join(projectDir, 'plugin.json');
|
|
127
|
-
|
|
128
|
-
if (fs.existsSync(pluginJsonPath) && !force) {
|
|
129
|
-
const overwrite = await confirm({
|
|
130
|
-
message: 'plugin.json exists. Overwrite?',
|
|
131
|
-
default: false,
|
|
132
|
-
});
|
|
133
|
-
if (!overwrite) {
|
|
134
|
-
this.logger.warn('Initialization cancelled.');
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
this.logger.info('Creating project structure...');
|
|
140
|
-
|
|
141
|
-
// Create directories
|
|
142
|
-
for (const dir of ['src', 'dist', 'build', 'test']) {
|
|
143
|
-
const dirPath = path.join(projectDir, dir);
|
|
144
|
-
if (!fs.existsSync(dirPath)) {
|
|
145
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Create plugin.json
|
|
150
|
-
this.createPluginJson(projectDir, config);
|
|
151
|
-
this.logger.success(' Created plugin.json');
|
|
152
|
-
|
|
153
|
-
// Create package.json
|
|
154
|
-
this.createPackageJson(projectDir, config, force);
|
|
155
|
-
|
|
156
|
-
// Create tsconfig.json
|
|
157
|
-
this.createTsConfig(projectDir, force);
|
|
158
|
-
|
|
159
|
-
// Create src/index.ts
|
|
160
|
-
this.createEntryPoint(projectDir, config, force);
|
|
161
|
-
|
|
162
|
-
// Create .gitignore
|
|
163
|
-
this.createGitignore(projectDir, force);
|
|
164
|
-
|
|
165
|
-
// Create README.md
|
|
166
|
-
this.createReadme(projectDir, config, force);
|
|
167
|
-
|
|
168
|
-
// Create ESLint config
|
|
169
|
-
this.createEslintConfig(projectDir, force);
|
|
170
|
-
|
|
171
|
-
// Create Prettier config
|
|
172
|
-
this.createPrettierConfig(projectDir, force);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private createPluginJson(
|
|
176
|
-
projectDir: string,
|
|
177
|
-
config: {
|
|
178
|
-
pluginName: string;
|
|
179
|
-
authorName: string;
|
|
180
|
-
authorEmail?: string;
|
|
181
|
-
description?: string;
|
|
182
|
-
pluginType: 'standalone' | 'library';
|
|
183
|
-
},
|
|
184
|
-
): void {
|
|
185
|
-
const manifest: Record<string, unknown> = {
|
|
186
|
-
name: config.pluginName,
|
|
187
|
-
version: '1.0.0',
|
|
188
|
-
opnetVersion: '>=0.0.1',
|
|
189
|
-
main: 'dist/index.jsc',
|
|
190
|
-
target: 'bytenode',
|
|
191
|
-
type: 'plugin',
|
|
192
|
-
author: config.authorEmail
|
|
193
|
-
? { name: config.authorName, email: config.authorEmail }
|
|
194
|
-
: { name: config.authorName },
|
|
195
|
-
pluginType: config.pluginType,
|
|
196
|
-
permissions: {
|
|
197
|
-
database: {
|
|
198
|
-
enabled: false,
|
|
199
|
-
collections: [],
|
|
200
|
-
},
|
|
201
|
-
blocks: {
|
|
202
|
-
preProcess: false,
|
|
203
|
-
postProcess: false,
|
|
204
|
-
onChange: false,
|
|
205
|
-
},
|
|
206
|
-
epochs: {
|
|
207
|
-
onChange: false,
|
|
208
|
-
onFinalized: false,
|
|
209
|
-
},
|
|
210
|
-
mempool: {
|
|
211
|
-
txFeed: false,
|
|
212
|
-
txSubmit: false,
|
|
213
|
-
},
|
|
214
|
-
api: {
|
|
215
|
-
addEndpoints: false,
|
|
216
|
-
addWebsocket: false,
|
|
217
|
-
},
|
|
218
|
-
threading: {
|
|
219
|
-
maxWorkers: 1,
|
|
220
|
-
maxMemoryMB: 256,
|
|
221
|
-
},
|
|
222
|
-
filesystem: {
|
|
223
|
-
configDir: false,
|
|
224
|
-
tempDir: false,
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
resources: {
|
|
228
|
-
memory: {
|
|
229
|
-
maxHeapMB: 256,
|
|
230
|
-
maxOldGenMB: 128,
|
|
231
|
-
maxYoungGenMB: 64,
|
|
232
|
-
},
|
|
233
|
-
cpu: {
|
|
234
|
-
maxThreads: 2,
|
|
235
|
-
priority: 'normal',
|
|
236
|
-
},
|
|
237
|
-
timeout: {
|
|
238
|
-
initMs: 30000,
|
|
239
|
-
hookMs: 5000,
|
|
240
|
-
shutdownMs: 10000,
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
lifecycle: {
|
|
244
|
-
loadPriority: 100,
|
|
245
|
-
enabledByDefault: true,
|
|
246
|
-
requiresRestart: false,
|
|
247
|
-
},
|
|
248
|
-
dependencies: {},
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
if (config.description) {
|
|
252
|
-
manifest.description = config.description;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
fs.writeFileSync(path.join(projectDir, 'plugin.json'), JSON.stringify(manifest, null, 4));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private createPackageJson(
|
|
259
|
-
projectDir: string,
|
|
260
|
-
config: {
|
|
261
|
-
pluginName: string;
|
|
262
|
-
authorName: string;
|
|
263
|
-
authorEmail?: string;
|
|
264
|
-
description?: string;
|
|
265
|
-
},
|
|
266
|
-
force?: boolean,
|
|
267
|
-
): void {
|
|
268
|
-
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
269
|
-
if (fs.existsSync(packageJsonPath) && !force) return;
|
|
270
|
-
|
|
271
|
-
const packageJson = {
|
|
272
|
-
name: config.pluginName,
|
|
273
|
-
version: '1.0.0',
|
|
274
|
-
description: config.description || 'OPNet plugin',
|
|
275
|
-
type: 'module',
|
|
276
|
-
main: 'dist/index.js',
|
|
277
|
-
scripts: {
|
|
278
|
-
build: 'tsc',
|
|
279
|
-
compile: 'npx opnet compile',
|
|
280
|
-
verify: 'npx opnet verify',
|
|
281
|
-
lint: 'eslint src/',
|
|
282
|
-
format: 'prettier --write src/',
|
|
283
|
-
},
|
|
284
|
-
author: config.authorEmail
|
|
285
|
-
? `${config.authorName} <${config.authorEmail}>`
|
|
286
|
-
: config.authorName,
|
|
287
|
-
license: 'Apache-2.0',
|
|
288
|
-
dependencies: { '@btc-vision/plugin-sdk': '^1.0.0' },
|
|
289
|
-
devDependencies: {
|
|
290
|
-
'@eslint/js': '^9.39.0',
|
|
291
|
-
'@types/node': '^25.0.0',
|
|
292
|
-
eslint: '^9.39.0',
|
|
293
|
-
prettier: '^3.6.0',
|
|
294
|
-
typescript: '^5.8.0',
|
|
295
|
-
'typescript-eslint': '^8.39.0',
|
|
296
|
-
'@btc-vision/cli': '^1.0.0',
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4));
|
|
301
|
-
this.logger.success(' Created package.json');
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
private createTsConfig(projectDir: string, force?: boolean): void {
|
|
305
|
-
const tsconfigPath = path.join(projectDir, 'tsconfig.json');
|
|
306
|
-
if (fs.existsSync(tsconfigPath) && !force) return;
|
|
307
|
-
|
|
308
|
-
const tsconfig = {
|
|
309
|
-
compilerOptions: {
|
|
310
|
-
target: 'ES2022',
|
|
311
|
-
module: 'NodeNext',
|
|
312
|
-
moduleResolution: 'NodeNext',
|
|
313
|
-
lib: ['ES2022'],
|
|
314
|
-
outDir: './dist',
|
|
315
|
-
rootDir: './src',
|
|
316
|
-
strict: true,
|
|
317
|
-
esModuleInterop: true,
|
|
318
|
-
skipLibCheck: true,
|
|
319
|
-
forceConsistentCasingInFileNames: true,
|
|
320
|
-
declaration: true,
|
|
321
|
-
sourceMap: true,
|
|
322
|
-
},
|
|
323
|
-
include: ['src/**/*'],
|
|
324
|
-
exclude: ['node_modules', 'dist', 'build'],
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
328
|
-
this.logger.success(' Created tsconfig.json');
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
private createEntryPoint(
|
|
332
|
-
projectDir: string,
|
|
333
|
-
config: { pluginName: string; pluginType: 'standalone' | 'library' },
|
|
334
|
-
force?: boolean,
|
|
335
|
-
): void {
|
|
336
|
-
const indexPath = path.join(projectDir, 'src', 'index.ts');
|
|
337
|
-
if (fs.existsSync(indexPath) && !force) return;
|
|
338
|
-
|
|
339
|
-
const className = this.toPascalCase(config.pluginName);
|
|
340
|
-
const content =
|
|
341
|
-
config.pluginType === 'standalone'
|
|
342
|
-
? `import { PluginBase, IPluginContext } from '@btc-vision/plugin-sdk';
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* ${className} Plugin
|
|
346
|
-
*
|
|
347
|
-
* Extend PluginBase and override only the hooks you need.
|
|
348
|
-
* See the plugin-sdk documentation for available hooks.
|
|
349
|
-
*/
|
|
350
|
-
export default class ${className}Plugin extends PluginBase {
|
|
351
|
-
/**
|
|
352
|
-
* Called when the plugin is loaded.
|
|
353
|
-
* Always call super.onLoad(context) first to initialize this.context.
|
|
354
|
-
*/
|
|
355
|
-
public async onLoad(context: IPluginContext): Promise<void> {
|
|
356
|
-
await super.onLoad(context);
|
|
357
|
-
this.context.logger.info('${className} plugin loaded');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Called when the plugin is being unloaded.
|
|
362
|
-
* Clean up any resources here.
|
|
363
|
-
*/
|
|
364
|
-
public async onUnload(): Promise<void> {
|
|
365
|
-
this.context.logger.info('${className} plugin unloading');
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Called when the plugin is enabled.
|
|
370
|
-
*/
|
|
371
|
-
public async onEnable(): Promise<void> {
|
|
372
|
-
this.context.logger.info('${className} plugin enabled');
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Called when the plugin is disabled.
|
|
377
|
-
*/
|
|
378
|
-
public async onDisable(): Promise<void> {
|
|
379
|
-
this.context.logger.info('${className} plugin disabled');
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
`
|
|
383
|
-
: `export * from './lib/index.js';
|
|
384
|
-
`;
|
|
385
|
-
|
|
386
|
-
fs.writeFileSync(indexPath, content);
|
|
387
|
-
this.logger.success(' Created src/index.ts');
|
|
388
|
-
|
|
389
|
-
if (config.pluginType === 'library') {
|
|
390
|
-
const libDir = path.join(projectDir, 'src', 'lib');
|
|
391
|
-
fs.mkdirSync(libDir, { recursive: true });
|
|
392
|
-
fs.writeFileSync(
|
|
393
|
-
path.join(libDir, 'index.ts'),
|
|
394
|
-
`export function hello(): string {
|
|
395
|
-
return 'Hello from ${config.pluginName}!';
|
|
396
|
-
}
|
|
397
|
-
`,
|
|
398
|
-
);
|
|
399
|
-
this.logger.success(' Created src/lib/index.ts');
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
private createGitignore(projectDir: string, force?: boolean): void {
|
|
404
|
-
const gitignorePath = path.join(projectDir, '.gitignore');
|
|
405
|
-
if (fs.existsSync(gitignorePath) && !force) return;
|
|
406
|
-
|
|
407
|
-
fs.writeFileSync(
|
|
408
|
-
gitignorePath,
|
|
409
|
-
`node_modules/
|
|
410
|
-
dist/
|
|
411
|
-
build/
|
|
412
|
-
*.jsc
|
|
413
|
-
*.opnet
|
|
414
|
-
.idea/
|
|
415
|
-
.vscode/
|
|
416
|
-
.DS_Store
|
|
417
|
-
.env
|
|
418
|
-
*.log
|
|
419
|
-
coverage/
|
|
420
|
-
`,
|
|
421
|
-
);
|
|
422
|
-
this.logger.success(' Created .gitignore');
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
private createReadme(
|
|
426
|
-
projectDir: string,
|
|
427
|
-
config: { pluginName: string; description?: string; pluginType: string },
|
|
428
|
-
force?: boolean,
|
|
429
|
-
): void {
|
|
430
|
-
const readmePath = path.join(projectDir, 'README.md');
|
|
431
|
-
if (fs.existsSync(readmePath) && !force) return;
|
|
432
|
-
|
|
433
|
-
fs.writeFileSync(
|
|
434
|
-
readmePath,
|
|
435
|
-
`# ${config.pluginName}
|
|
436
|
-
|
|
437
|
-
${config.description || `An OPNet ${config.pluginType} plugin.`}
|
|
438
|
-
|
|
439
|
-
## Installation
|
|
440
|
-
|
|
441
|
-
\`\`\`bash
|
|
442
|
-
npm install
|
|
443
|
-
\`\`\`
|
|
444
|
-
|
|
445
|
-
## Development
|
|
446
|
-
|
|
447
|
-
\`\`\`bash
|
|
448
|
-
npm run build # Build TypeScript
|
|
449
|
-
npm run compile # Compile to .opnet
|
|
450
|
-
npm run verify # Verify binary
|
|
451
|
-
\`\`\`
|
|
452
|
-
|
|
453
|
-
## License
|
|
454
|
-
|
|
455
|
-
Apache-2.0
|
|
456
|
-
`,
|
|
457
|
-
);
|
|
458
|
-
this.logger.success(' Created README.md');
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
private createEslintConfig(projectDir: string, force?: boolean): void {
|
|
462
|
-
const eslintPath = path.join(projectDir, 'eslint.config.js');
|
|
463
|
-
if (fs.existsSync(eslintPath) && !force) return;
|
|
464
|
-
|
|
465
|
-
const content = `// @ts-check
|
|
466
|
-
|
|
467
|
-
import eslint from '@eslint/js';
|
|
468
|
-
import tseslint from 'typescript-eslint';
|
|
469
|
-
|
|
470
|
-
export default tseslint.config(
|
|
471
|
-
eslint.configs.recommended,
|
|
472
|
-
...tseslint.configs.strictTypeChecked,
|
|
473
|
-
{
|
|
474
|
-
languageOptions: {
|
|
475
|
-
parserOptions: {
|
|
476
|
-
projectService: true,
|
|
477
|
-
tsconfigDirName: import.meta.dirname,
|
|
478
|
-
},
|
|
479
|
-
},
|
|
480
|
-
rules: {
|
|
481
|
-
'no-undef': 'off',
|
|
482
|
-
'@typescript-eslint/no-unused-vars': 'off',
|
|
483
|
-
'no-empty': 'off',
|
|
484
|
-
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
485
|
-
'@typescript-eslint/only-throw-error': 'off',
|
|
486
|
-
'@typescript-eslint/no-unnecessary-condition': 'off',
|
|
487
|
-
'@typescript-eslint/unbound-method': 'warn',
|
|
488
|
-
'@typescript-eslint/no-confusing-void-expression': 'off',
|
|
489
|
-
'@typescript-eslint/no-extraneous-class': 'off',
|
|
490
|
-
'no-async-promise-executor': 'off',
|
|
491
|
-
'@typescript-eslint/no-misused-promises': 'off',
|
|
492
|
-
'@typescript-eslint/no-unnecessary-type-parameters': 'off',
|
|
493
|
-
'@typescript-eslint/no-duplicate-enum-values': 'off',
|
|
494
|
-
'prefer-spread': 'off',
|
|
495
|
-
'@typescript-eslint/no-empty-object-type': 'off',
|
|
496
|
-
'@typescript-eslint/no-base-to-string': 'off',
|
|
497
|
-
'@typescript-eslint/no-dynamic-delete': 'off',
|
|
498
|
-
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
|
499
|
-
},
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
files: ['**/*.js'],
|
|
503
|
-
...tseslint.configs.disableTypeChecked,
|
|
504
|
-
},
|
|
505
|
-
);
|
|
506
|
-
`;
|
|
507
|
-
|
|
508
|
-
fs.writeFileSync(eslintPath, content);
|
|
509
|
-
this.logger.success(' Created eslint.config.js');
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
private createPrettierConfig(projectDir: string, force?: boolean): void {
|
|
513
|
-
const prettierPath = path.join(projectDir, '.prettierrc.json');
|
|
514
|
-
if (fs.existsSync(prettierPath) && !force) return;
|
|
515
|
-
|
|
516
|
-
const config = {
|
|
517
|
-
printWidth: 100,
|
|
518
|
-
trailingComma: 'all',
|
|
519
|
-
tabWidth: 4,
|
|
520
|
-
semi: true,
|
|
521
|
-
singleQuote: true,
|
|
522
|
-
quoteProps: 'as-needed',
|
|
523
|
-
bracketSpacing: true,
|
|
524
|
-
bracketSameLine: true,
|
|
525
|
-
arrowParens: 'always',
|
|
526
|
-
singleAttributePerLine: true,
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
fs.writeFileSync(prettierPath, JSON.stringify(config, null, 4));
|
|
530
|
-
this.logger.success(' Created .prettierrc.json');
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
private toPascalCase(str: string): string {
|
|
534
|
-
return str
|
|
535
|
-
.split(/[-_]/)
|
|
536
|
-
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
537
|
-
.join('');
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
export const initCommand = new InitCommand().getCommand();
|