Skip to content

Commit

Permalink
Merge pull request #61 from expressots/fix/add-internal-provider-reso…
Browse files Browse the repository at this point in the history
…urce

fix: broken tsconfig deps
  • Loading branch information
rsaz authored Aug 4, 2024
2 parents d40ca91 + d4fbc8b commit 5541d4c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
45 changes: 36 additions & 9 deletions src/commands/project.commands.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { spawn } from "child_process";
import { promises as fs, readFileSync } from "fs";
import { promises as fs, readFileSync, existsSync, mkdirSync } from "fs";
import os from "os";
import path, { join } from "path";
import { CommandModule } from "yargs";
import { printError, printSuccess } from "../utils/cli-ui";
import Compiler from "../utils/compiler";

/**
* Load tsconfig path and extract outDir
* Helper function to load and extract outDir from tsconfig.build.json
*/
const tsconfigBuildPath = join(process.cwd(), "tsconfig.build.json");
const tsconfig = JSON.parse(readFileSync(tsconfigBuildPath, "utf-8"));
const outDir = tsconfig.compilerOptions.outDir;
function getOutDir(): string {
const tsconfigBuildPath = join(process.cwd(), "tsconfig.build.json");

if (!existsSync(tsconfigBuildPath)) {
printError(
"Cannot find tsconfig.build.json. Please create one in the root directory",
"tsconfig-build-path",
);
process.exit(1);
}

const tsconfig = JSON.parse(readFileSync(tsconfigBuildPath, "utf-8"));
const outDir = tsconfig.compilerOptions.outDir;

if (!outDir) {
printError(
"Cannot find outDir in tsconfig.build.json. Please provide an outDir.",
"tsconfig-build-path",
);
process.exit(1);
}

if (!existsSync(outDir)) {
mkdirSync(outDir, { recursive: true });
printSuccess(`Created outDir: ${outDir}`, "outdir-creation");
}

return outDir;
}

/**
* Load the configuration from the compiler
Expand Down Expand Up @@ -107,7 +133,7 @@ function execCmd(
/**
* Helper function to clean the dist directory
*/
const cleanDist = async (): Promise<void> => {
const cleanDist = async (outDir: string): Promise<void> => {
await fs.rm(outDir, { recursive: true, force: true });
printSuccess(`Clean ${outDir} directory`, "clean-dist");
};
Expand All @@ -123,7 +149,7 @@ const compileTypescript = async () => {
/**
* Helper function to copy files to the dist directory
*/
const copyFiles = async () => {
const copyFiles = async (outDir: string) => {
const { opinionated } = await Compiler.loadConfig();
let filesToCopy: Array<string> = [];
if (opinionated) {
Expand Down Expand Up @@ -159,6 +185,7 @@ export const runCommand = async ({
command: string;
}): Promise<void> => {
const { opinionated } = await Compiler.loadConfig();
const outDir = getOutDir();

try {
switch (command) {
Expand All @@ -176,9 +203,9 @@ export const runCommand = async ({
);
process.exit(1);
}
await cleanDist();
await cleanDist(outDir);
await compileTypescript();
await copyFiles();
await copyFiles(outDir);
break;
case "prod": {
if (!outDir) {
Expand Down
5 changes: 3 additions & 2 deletions src/help/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const helpForm = async (): Promise<void> => {
["usecase", "g u", "Generate a usecase"],
["dto", "g d", "Generate a dto"],
["entity", "g e", "Generate an entity"],
["provider", "add", "Add provider to the project"],
["provider", "create", "Create a provider"],
["provider", "g p", "Generate internal provider"],
["provider", "add", "Add external provider to the project"],
["provider", "create", "Create external provider"],
["module", "g mo", "Generate a module"],
["middleware", "g mi", "Generate a middleware"],
);
Expand Down

0 comments on commit 5541d4c

Please sign in to comment.