Skip to content

Commit

Permalink
Merge pull request #43 from syfxlin/develop
Browse files Browse the repository at this point in the history
refactor(bin): support global config
  • Loading branch information
syfxlin authored Jan 7, 2024
2 parents 089064f + 178a132 commit cac4235
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
33 changes: 22 additions & 11 deletions depker.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import { fs, path } from "./src/deps.ts";

const lookup = async () => {
const root = Deno.cwd();
const paths = [
path.join(root, "depker.config.ts"),
path.join(root, ".depker/depker.config.ts"),
path.join(root, "depker.config.js"),
path.join(root, ".depker/depker.config.js"),
path.join(root, "depker.config.cjs"),
path.join(root, ".depker/depker.config.cjs"),
path.join(root, "depker.config.mjs"),
path.join(root, ".depker/depker.config.mjs"),
];
const paths = [] as string[];
const roots = [Deno.cwd(), Deno.build.os === "windows" ? Deno.env.get("USERPROFILE") : Deno.env.get("HOME")];
for (const r of roots) {
if (r) {
paths.push(path.join(r, "depker.config.ts"));
paths.push(path.join(r, "depker.config.js"));
paths.push(path.join(r, "depker.config.cjs"));
paths.push(path.join(r, "depker.config.mjs"));
paths.push(path.join(r, ".depker/depker.config.ts"));
paths.push(path.join(r, ".depker/depker.config.js"));
paths.push(path.join(r, ".depker/depker.config.cjs"));
paths.push(path.join(r, ".depker/depker.config.mjs"));
paths.push(path.join(r, ".depker/depker.ts"));
paths.push(path.join(r, ".depker/depker.js"));
paths.push(path.join(r, ".depker/depker.cjs"));
paths.push(path.join(r, ".depker/depker.mjs"));
paths.push(path.join(r, ".depker/config.ts"));
paths.push(path.join(r, ".depker/config.js"));
paths.push(path.join(r, ".depker/config.cjs"));
paths.push(path.join(r, ".depker/config.mjs"));
}
}
for (const p of paths) {
if (await fs.exists(p)) {
return path.toFileUrl(p).toString();
Expand Down
13 changes: 11 additions & 2 deletions src/depker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export interface DepkerModule {
}

export function depker(): DepkerApp {
return new Depker() as DepkerApp;
return Depker.create();
}

export class Depker {
// singleton
private static instance: DepkerApp;
// info
public readonly name: string;
public readonly version: string;
Expand All @@ -43,7 +45,14 @@ export class Depker {
// module
private readonly _modules: Array<DepkerModule>;

constructor() {
public static create(): DepkerApp {
if (!Depker.instance) {
Depker.instance = new Depker() as DepkerApp;
}
return Depker.instance;
}

private constructor() {
// info
this.name = "depker";
this.version = "5.1.1";
Expand Down

0 comments on commit cac4235

Please sign in to comment.