sinotron
Version:
Simple framework for Typescript Electron projects
38 lines (37 loc) • 1.53 kB
JavaScript
import { Dirs } from '../../constants.js';
import { logError, logInfo } from '../../utils/log.js';
import { ask } from '../../utils/ask.js';
import { fsutil } from '@utilis/fs';
import chalk from 'chalk';
import shell from 'shelljs';
import { DirFactory } from './DirFactory.js';
import { IpcDirFactory } from './IpcDirFactory.js';
export class FrameworkFactory {
constructor() { }
static async setup(opts = {}) {
const { force = false } = opts;
const frameworkDir = Dirs.framework();
const projectDir = process.cwd();
if (fsutil.isDir(frameworkDir)) {
if (force) {
const resultId = 'answer';
const result = await ask.input(resultId, `The framework directory already exists. Do you want to overwrite it? (y/n)`);
const answer = result[resultId] || '';
if (['y', 'yes'].includes(answer.toLowerCase())) {
fsutil.dir.delete(frameworkDir);
}
}
else {
logError(`${frameworkDir} already exists. Run with --force option to overwrite it.`);
return;
}
}
logInfo(`-> Installing sinotron dependency...`);
shell.exec('npm install sinotron', { cwd: projectDir });
logInfo(`--> Adding framework contents to ${chalk.yellowBright(projectDir)}`);
DirFactory.create(frameworkDir, () => {
DirFactory.create(Dirs.db());
IpcDirFactory.setup();
});
}
}