Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Registry #20

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
39 changes: 39 additions & 0 deletions actions/list.action.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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'));
}

}


}
33 changes: 33 additions & 0 deletions actions/new.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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<void> => {
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');
Expand Down
3 changes: 3 additions & 0 deletions commands/command.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BuildAction,
GenerateAction,
InfoAction,
ListAction,
NewAction,
StartAction,
} from '../actions';
Expand All @@ -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 {
Expand All @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions commands/list.command.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}
}