Skip to content

Commit

Permalink
fix: dynamically lookup local registry modules path (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 12, 2024
1 parent 9fc8c4f commit 40921f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/template/module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { ModuleConfig } from "../config/module.ts";
import { resolve, stringify } from "../deps.ts";
import { Project } from "../project/mod.ts";
import { getLocalRegistry, Project } from "../project/mod.ts";
import { dedent } from "./deps.ts";

export async function templateModule(project: Project, moduleName: string) {
const localRegistry = getLocalRegistry(project);
if (!localRegistry) throw new Error("Local registry not configured");
const localModulesPath = localRegistry.path;

if (project.modules.has(moduleName)) {
throw new Error("Module already exists");
}

// Create directires
const modulePath = resolve(project.path, "modules", moduleName);
const modulePath = resolve(localModulesPath, moduleName);
await Deno.mkdir(modulePath);
await Deno.mkdir(resolve(modulePath, "scripts"));
await Deno.mkdir(resolve(modulePath, "tests"));
Expand Down
19 changes: 9 additions & 10 deletions src/template/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ export async function templateScript(
moduleName: string,
scriptName: string,
) {
// if (!project.localRegistry) throw new Error("Local registry not configured");
// const modulesPath = project.localRegistry.path;

const mod = project.modules.get(moduleName);
if (!mod) {
throw new Error(`Missing module ${moduleName}`);
}
if (!mod) throw new Error(`Missing module ${moduleName}`);
if (!("local" in mod.registry.config)) throw new Error(`Module ${moduleName} is not in a local registry`);
if (mod.registry.isExternal) throw new Error(`Module ${moduleName} is in an external registry`);

// Create scripts
const scriptPath = resolve(
project.path,
"modules",
moduleName,
mod.path,
"scripts",
scriptName + ".ts",
);
Expand All @@ -31,9 +32,7 @@ export async function templateScript(
// Create test if doesn't already exist
let createTest = false;
const testPath = resolve(
project.path,
"modules",
moduleName,
mod.path,
"tests",
scriptName + ".ts",
);
Expand All @@ -52,7 +51,7 @@ export async function templateScript(
newConfig.scripts[scriptName] = {};
const newConfigRaw = stringify(newConfig);
await Deno.writeTextFile(
resolve(project.path, "modules", moduleName, "module.yaml"),
resolve(mod.path, "module.yaml"),
newConfigRaw,
);

Expand Down

0 comments on commit 40921f0

Please sign in to comment.