Skip to content

Commit

Permalink
don't fail when addon are not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed Sep 12, 2024
1 parent 8a9423d commit 885d2f6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/create-reciple/src/classes/TemplateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,42 @@ export class TemplateBuilder implements TemplateBuilderOptions {
let packageJson = JSON.parse(packageJsonData) as PackageJson;
let packageJsonIndentSize = detectIndent(packageJsonData).indent || ' ';
let done: number = 0;
let failed: number = 0;

for (const addon of addons) {
await addon.fetch();
await addon.readTarball();
try {
await addon.fetch();
await addon.readTarball();

const moduleContent = this.setup.isTypescript ? addon.tarballData?.initialModuleContent.ts : addon.tarballData?.initialModuleContent.js;
if (!moduleContent) continue;
const moduleContent = this.setup.isTypescript ? addon.tarballData?.initialModuleContent.ts : addon.tarballData?.initialModuleContent.js;
if (!moduleContent) continue;

const modulesFolder = path.join(this.dir, this.setup.isTypescript ? 'src' : 'modules', 'addons');
await mkdir(modulesFolder, { recursive: true });
const modulesFolder = path.join(this.dir, this.setup.isTypescript ? 'src' : 'modules', 'addons');
await mkdir(modulesFolder, { recursive: true });

const modulePath = path.join(modulesFolder, `${addon.module}.${this.setup.isTypescript ? 'ts' : 'js'}`);
await writeFile(modulePath, moduleContent);
const modulePath = path.join(modulesFolder, `${addon.module}.${this.setup.isTypescript ? 'ts' : 'js'}`);
await writeFile(modulePath, moduleContent);

packageJson.dependencies = {
...packageJson.dependencies,
[addon.module]: addon.version,
};
packageJson.dependencies = {
...packageJson.dependencies,
[addon.module]: addon.version,
};

done++;
done++;

this.persistSpinner({ symbol: kleur.bold().green(' +'), text: `Installed addon ${kleur.cyan(addon.module + '@' + (addon.version ?? 'latest'))}` });
} catch (err) {
failed++;
const message = err instanceof Error ? err.message : String(err);

this.persistSpinner({ symbol: kleur.bold().red(' ×'), text: `${kleur.gray(addon.module + '@' + (addon.version ?? 'latest'))} ${kleur.red(message)}` });
}

this.persistSpinner({ symbol: kleur.bold().green(' +'), text: `Installed addon ${kleur.cyan(addon.module + '@' + (addon.version ?? 'latest'))}` });
this.setSpinnerText(`Installing ${kleur.cyan(addons.length + ' addons')} ${kleur.gray('('+ done +'/'+ addons.length +')')}...`);
}

await writeFile(this.packageJsonPath, JSON.stringify(packageJson, null, packageJsonIndentSize), 'utf-8');
this.persistSpinner({ symbol: kleur.bold().green('✔'), text: `${kleur.green('Addons installed.')}` });
this.persistSpinner({ symbol: kleur.bold().green('✔'), text: `${kleur.green('Addons installed.')}` + (failed ? kleur.red(` Failed (${failed}/${addons.length})`) : '') });
}

/**
Expand Down
19 changes: 19 additions & 0 deletions packages/utils/src/helpers/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ export function isValidSnowflake(snowflake: unknown): snowflake is Snowflake {
return false;
}
}

/**
* Check if the terminal supports unicode
*/
export function isUnicodeSupported() {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}

return Boolean(process.env.CI)
|| Boolean(process.env.WT_SESSION) // Windows Terminal
|| Boolean(process.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|| process.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|| process.env.TERM_PROGRAM === 'Terminus-Sublime'
|| process.env.TERM_PROGRAM === 'vscode'
|| process.env.TERM === 'xterm-256color'
|| process.env.TERM === 'alacritty'
|| process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
}

0 comments on commit 885d2f6

Please sign in to comment.