|
|
|
|
@@ -36,20 +36,20 @@ const PRESETS: Record<string, { description: string; config: interfaces.IBundleC
|
|
|
|
|
|
|
|
|
|
export class InitHandler {
|
|
|
|
|
private cwd: string;
|
|
|
|
|
private npmextraPath: string;
|
|
|
|
|
private smartconfigPath: string;
|
|
|
|
|
|
|
|
|
|
constructor(cwd: string = paths.cwd) {
|
|
|
|
|
this.cwd = cwd;
|
|
|
|
|
this.npmextraPath = plugins.path.join(this.cwd, 'npmextra.json');
|
|
|
|
|
this.smartconfigPath = plugins.path.join(this.cwd, 'smartconfig.json');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load existing npmextra.json or create empty config
|
|
|
|
|
*/
|
|
|
|
|
private async loadExistingConfig(): Promise<any> {
|
|
|
|
|
const fileExists = await plugins.fs.file(this.npmextraPath).exists();
|
|
|
|
|
const fileExists = await plugins.fs.file(this.smartconfigPath).exists();
|
|
|
|
|
if (fileExists) {
|
|
|
|
|
const content = (await plugins.fs.file(this.npmextraPath).encoding('utf8').read()) as string;
|
|
|
|
|
const content = (await plugins.fs.file(this.smartconfigPath).encoding('utf8').read()) as string;
|
|
|
|
|
try {
|
|
|
|
|
return JSON.parse(content);
|
|
|
|
|
} catch {
|
|
|
|
|
@@ -64,8 +64,8 @@ export class InitHandler {
|
|
|
|
|
*/
|
|
|
|
|
private async saveConfig(config: any): Promise<void> {
|
|
|
|
|
const content = JSON.stringify(config, null, 2);
|
|
|
|
|
await plugins.fs.file(this.npmextraPath).encoding('utf8').write(content);
|
|
|
|
|
console.log(`\n✅ Configuration saved to npmextra.json`);
|
|
|
|
|
await plugins.fs.file(this.smartconfigPath).encoding('utf8').write(content);
|
|
|
|
|
console.log(`\n✅ Configuration saved to smartconfig.json`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -73,15 +73,15 @@ export class InitHandler {
|
|
|
|
|
*/
|
|
|
|
|
public async runWizard(): Promise<void> {
|
|
|
|
|
console.log('\n🚀 tsbundle configuration wizard\n');
|
|
|
|
|
console.log('This wizard will help you configure bundle settings in npmextra.json.\n');
|
|
|
|
|
console.log('This wizard will help you configure bundle settings in smartconfig.json.\n');
|
|
|
|
|
|
|
|
|
|
const npmextraJson = await this.loadExistingConfig();
|
|
|
|
|
const smartconfigJson = await this.loadExistingConfig();
|
|
|
|
|
|
|
|
|
|
if (!npmextraJson['@git.zone/tsbundle']) {
|
|
|
|
|
npmextraJson['@git.zone/tsbundle'] = { bundles: [] };
|
|
|
|
|
if (!smartconfigJson['@git.zone/tsbundle']) {
|
|
|
|
|
smartconfigJson['@git.zone/tsbundle'] = { bundles: [] };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const existingBundles = npmextraJson['@git.zone/tsbundle'].bundles || [];
|
|
|
|
|
const existingBundles = smartconfigJson['@git.zone/tsbundle'].bundles || [];
|
|
|
|
|
|
|
|
|
|
if (existingBundles.length > 0) {
|
|
|
|
|
console.log(`Found ${existingBundles.length} existing bundle configuration(s):\n`);
|
|
|
|
|
@@ -95,7 +95,7 @@ export class InitHandler {
|
|
|
|
|
while (addMore) {
|
|
|
|
|
const bundle = await this.configureSingleBundle();
|
|
|
|
|
if (bundle) {
|
|
|
|
|
npmextraJson['@git.zone/tsbundle'].bundles.push(bundle);
|
|
|
|
|
smartconfigJson['@git.zone/tsbundle'].bundles.push(bundle);
|
|
|
|
|
console.log(`\n✅ Bundle configuration added!`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -112,10 +112,10 @@ export class InitHandler {
|
|
|
|
|
addMore = answers.getAnswerFor('addAnother');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.saveConfig(npmextraJson);
|
|
|
|
|
await this.saveConfig(smartconfigJson);
|
|
|
|
|
|
|
|
|
|
console.log('\n📋 Final configuration:\n');
|
|
|
|
|
const bundles = npmextraJson['@git.zone/tsbundle'].bundles;
|
|
|
|
|
const bundles = smartconfigJson['@git.zone/tsbundle'].bundles;
|
|
|
|
|
bundles.forEach((bundle: interfaces.IBundleConfig, i: number) => {
|
|
|
|
|
console.log(` Bundle ${i + 1}:`);
|
|
|
|
|
console.log(` From: ${bundle.from}`);
|
|
|
|
|
|