@abhinav2-3/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +115 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +2505 -0
- package/dist/index.mjs +2493 -0
- package/package.json +26 -0
- package/src/constants/paths.ts +55 -0
- package/src/environment/index.ts +16 -0
- package/src/features/apply-features.ts +171 -0
- package/src/features/index.ts +3 -0
- package/src/features/registry.ts +222 -0
- package/src/features/resolver.ts +19 -0
- package/src/filesystem/index.ts +45 -0
- package/src/generator/generateProject.ts +91 -0
- package/src/git/index.ts +22 -0
- package/src/index.ts +3 -0
- package/src/installers/base.ts +31 -0
- package/src/installers/implementations.ts +28 -0
- package/src/installers/index.ts +16 -0
- package/src/resolvers/templateResolver.ts +26 -0
- package/src/template-engine/index.ts +21 -0
- package/src/types.ts +38 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import execa from 'execa';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
export interface Installer {
|
|
5
|
+
install(projectPath: string): Promise<void>;
|
|
6
|
+
getName(): string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export abstract class BaseInstaller implements Installer {
|
|
10
|
+
abstract getName(): string;
|
|
11
|
+
abstract getInstallCommand(): { command: string; args: string[] };
|
|
12
|
+
|
|
13
|
+
async install(projectPath: string): Promise<void> {
|
|
14
|
+
const { command, args } = this.getInstallCommand();
|
|
15
|
+
|
|
16
|
+
console.log(
|
|
17
|
+
chalk.cyan(`\n📦 Installing dependencies using ${this.getName()}...`),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await execa(command, args, {
|
|
22
|
+
cwd: projectPath,
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Failed to install dependencies using ${this.getName()}: ${error}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseInstaller } from './base';
|
|
2
|
+
|
|
3
|
+
export class NpmInstaller extends BaseInstaller {
|
|
4
|
+
getName(): string {
|
|
5
|
+
return 'npm';
|
|
6
|
+
}
|
|
7
|
+
getInstallCommand() {
|
|
8
|
+
return { command: 'npm', args: ['install'] };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PnpmInstaller extends BaseInstaller {
|
|
13
|
+
getName(): string {
|
|
14
|
+
return 'pnpm';
|
|
15
|
+
}
|
|
16
|
+
getInstallCommand() {
|
|
17
|
+
return { command: 'pnpm', args: ['install'] };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class YarnInstaller extends BaseInstaller {
|
|
22
|
+
getName(): string {
|
|
23
|
+
return 'yarn';
|
|
24
|
+
}
|
|
25
|
+
getInstallCommand() {
|
|
26
|
+
return { command: 'yarn', args: ['install'] };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Installer } from './base';
|
|
2
|
+
import { NpmInstaller, PnpmInstaller, YarnInstaller } from './implementations';
|
|
3
|
+
import { PackageManager } from '../types';
|
|
4
|
+
|
|
5
|
+
export const resolveInstaller = (packageManager: PackageManager): Installer => {
|
|
6
|
+
switch (packageManager) {
|
|
7
|
+
case 'npm':
|
|
8
|
+
return new NpmInstaller();
|
|
9
|
+
case 'pnpm':
|
|
10
|
+
return new PnpmInstaller();
|
|
11
|
+
case 'yarn':
|
|
12
|
+
return new YarnInstaller();
|
|
13
|
+
default:
|
|
14
|
+
return new NpmInstaller();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { GeneratorConfig } from '../types';
|
|
3
|
+
import { exists } from '../filesystem';
|
|
4
|
+
import { getTemplatesPath } from '../constants/paths';
|
|
5
|
+
|
|
6
|
+
export const resolveTemplatePath = async (
|
|
7
|
+
config: GeneratorConfig,
|
|
8
|
+
assetsRoot?: string,
|
|
9
|
+
): Promise<string> => {
|
|
10
|
+
const templateBaseDir = assetsRoot
|
|
11
|
+
? path.join(assetsRoot, 'templates')
|
|
12
|
+
: getTemplatesPath();
|
|
13
|
+
|
|
14
|
+
const templatePath = path.join(
|
|
15
|
+
templateBaseDir,
|
|
16
|
+
config.framework,
|
|
17
|
+
config.architecture,
|
|
18
|
+
config.database,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (!(await exists(templatePath))) {
|
|
22
|
+
throw new Error(`Template not found at: ${templatePath}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return templatePath;
|
|
26
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ejs from 'ejs';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
export const renderTemplate = async (
|
|
5
|
+
filePath: string,
|
|
6
|
+
data: Record<string, any>,
|
|
7
|
+
): Promise<string> => {
|
|
8
|
+
const templateContent = await fs.readFile(filePath, 'utf-8');
|
|
9
|
+
return ejs.render(templateContent, data);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const isTemplateFile = (filePath: string): boolean => {
|
|
13
|
+
return filePath.endsWith('.ejs');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getTargetFileName = (filePath: string): string => {
|
|
17
|
+
if (isTemplateFile(filePath)) {
|
|
18
|
+
return filePath.replace(/\.ejs$/, '');
|
|
19
|
+
}
|
|
20
|
+
return filePath;
|
|
21
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type Framework = 'express';
|
|
2
|
+
|
|
3
|
+
export type Architecture = 'traditional' | 'modular';
|
|
4
|
+
|
|
5
|
+
export type Database = 'mongodb' | 'postgres';
|
|
6
|
+
|
|
7
|
+
export type ORM = 'mongoose' | 'prisma';
|
|
8
|
+
|
|
9
|
+
export type PackageManager = 'npm' | 'pnpm' | 'yarn';
|
|
10
|
+
|
|
11
|
+
export interface GeneratorConfig {
|
|
12
|
+
projectName: string;
|
|
13
|
+
framework: Framework;
|
|
14
|
+
architecture: Architecture;
|
|
15
|
+
database: Database;
|
|
16
|
+
orm: ORM;
|
|
17
|
+
packageManager: PackageManager;
|
|
18
|
+
features: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FeatureMetadata {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
frameworks?: Framework[];
|
|
25
|
+
architectures?: Architecture[];
|
|
26
|
+
databases?: Database[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FeatureDependencies {
|
|
30
|
+
dependencies?: Record<string, string>;
|
|
31
|
+
devDependencies?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Feature {
|
|
35
|
+
metadata: FeatureMetadata;
|
|
36
|
+
dependencies: FeatureDependencies;
|
|
37
|
+
apply?: (projectPath: string, config: GeneratorConfig) => Promise<void>;
|
|
38
|
+
}
|
package/tsconfig.json
ADDED