diff --git a/actions/index.ts b/actions/index.ts index bc3eb35b..29083e82 100644 --- a/actions/index.ts +++ b/actions/index.ts @@ -2,6 +2,7 @@ export * from './abstract.action'; export * from './build.action'; export * from './generate.action'; export * from './info.action'; +export * from './list.action'; export * from './new.action'; export * from './start.action'; export * from './add.action'; diff --git a/actions/list.action.ts b/actions/list.action.ts new file mode 100644 index 00000000..e246cdfb --- /dev/null +++ b/actions/list.action.ts @@ -0,0 +1,39 @@ +import * as chalk from 'chalk'; +import * as fs from 'fs'; +import { platform, release } from 'os'; +import osName = require('os-name'); +import { join } from 'path'; +import { + AbstractPackageManager, + PackageManagerFactory, +} from '../lib/package-managers'; +import { BANNER, MESSAGES } from '../lib/ui'; +import { AbstractAction } from './abstract.action'; + + +export class ListAction extends AbstractAction { + private manager!: AbstractPackageManager; + + public async handle() { + this.manager = await PackageManagerFactory.find(); + await this.loadRegistry(); + } + private async loadRegistry(): Promise { + const stencilFilePath = join(process.cwd(), '.stencil'); + try { + const stencilFileContent = await fs.promises.readFile(stencilFilePath, 'utf-8'); + + if (stencilFileContent.trim() === '') { + console.log(chalk.yellow('No modules found')); + } else { + console.log(chalk.green('Installed Modules:')); + console.log(stencilFileContent); + } + }catch (error) { + console.error(chalk.red('Error reading .stencil file')); + } + + } + + +} diff --git a/actions/new.action.ts b/actions/new.action.ts index 739256fc..044efca9 100644 --- a/actions/new.action.ts +++ b/actions/new.action.ts @@ -145,6 +145,7 @@ export class NewAction extends AbstractAction { if (!shouldSkipGit) { await initializeGitRepository(projectDirectory); await createGitIgnoreFile(projectDirectory); + await createRegistry(projectDirectory, shouldInitializePrima,shouldInitializeUserService,shouldInstallMonitoring, shouldInitializeMonitoring,shouldInitializeTemporal,shouldInitializeLogging,shouldInitializeFileUpload); await copyEnvFile(projectDirectory, 'env-example', '.env'); } @@ -672,6 +673,38 @@ const copyEnvFile = async (dir: string, envExample: string, envFile: string) => } }; +const createRegistry = async ( + dir: string, + shouldInitializePrisma: boolean, + shouldInitializeUserService: boolean, + shouldInstallMonitoring: boolean, + shouldInitializeMonitoring: boolean, + shouldInitializeTemporal: boolean, + shouldInitializeLogging: boolean, + shouldInitializeFileUpload: boolean +): Promise => { + const filePath = join(process.cwd(), dir, '.stencil'); + + const setupInfo = [ + shouldInitializePrisma ? 'Prisma Setup' : '', + shouldInitializeUserService ? 'User Services Setup' : '', + shouldInstallMonitoring ? 'Monitoring Installed' : '', + shouldInitializeMonitoring ? 'Monitoring Setup' : '', + shouldInitializeTemporal ? 'Temporal Setup' : '', + shouldInitializeLogging ? 'Logging Setup' : '', + shouldInitializeFileUpload ? 'File Upload Setup' : '' + ].filter(info => info !== '').join('\n'); + + try { + await fs.promises.access(filePath, fs.constants.F_OK); + console.log('.stencil file already exists'); + } catch (error) { + await fs.promises.writeFile(filePath, setupInfo); + console.log('.stencil file created'); + } +}; + + const printCollective = () => { const dim = print('dim'); const yellow = print('yellow'); diff --git a/commands/command.loader.ts b/commands/command.loader.ts index ba570a19..deb98590 100644 --- a/commands/command.loader.ts +++ b/commands/command.loader.ts @@ -5,6 +5,7 @@ import { BuildAction, GenerateAction, InfoAction, + ListAction, NewAction, StartAction, } from '../actions'; @@ -13,6 +14,7 @@ import { AddCommand } from './add.command'; import { BuildCommand } from './build.command'; import { GenerateCommand } from './generate.command'; import { InfoCommand } from './info.command'; +import { ListCommand } from './list.command'; import { NewCommand } from './new.command'; import { StartCommand } from './start.command'; export class CommandLoader { @@ -21,6 +23,7 @@ export class CommandLoader { new BuildCommand(new BuildAction()).load(program); new StartCommand(new StartAction()).load(program); new InfoCommand(new InfoAction()).load(program); + new ListCommand(new ListAction()).load(program); new AddCommand(new AddAction()).load(program); await new GenerateCommand(new GenerateAction()).load(program); diff --git a/commands/list.command.ts b/commands/list.command.ts new file mode 100644 index 00000000..0052f1a7 --- /dev/null +++ b/commands/list.command.ts @@ -0,0 +1,14 @@ +import { CommanderStatic } from 'commander'; +import { AbstractCommand } from './abstract.command'; + +export class ListCommand extends AbstractCommand{ + public load(program: CommanderStatic) { + program + .command('list') + .alias('ls') + .description('List installed modules.') + .action(async () => { + await this.action.handle(); + }); + } +}