Skip to content

Commit cac4235

Browse files
authored
Merge pull request #43 from syfxlin/develop
refactor(bin): support global config
2 parents 089064f + 178a132 commit cac4235

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

depker.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
import { fs, path } from "./src/deps.ts";
22

33
const lookup = async () => {
4-
const root = Deno.cwd();
5-
const paths = [
6-
path.join(root, "depker.config.ts"),
7-
path.join(root, ".depker/depker.config.ts"),
8-
path.join(root, "depker.config.js"),
9-
path.join(root, ".depker/depker.config.js"),
10-
path.join(root, "depker.config.cjs"),
11-
path.join(root, ".depker/depker.config.cjs"),
12-
path.join(root, "depker.config.mjs"),
13-
path.join(root, ".depker/depker.config.mjs"),
14-
];
4+
const paths = [] as string[];
5+
const roots = [Deno.cwd(), Deno.build.os === "windows" ? Deno.env.get("USERPROFILE") : Deno.env.get("HOME")];
6+
for (const r of roots) {
7+
if (r) {
8+
paths.push(path.join(r, "depker.config.ts"));
9+
paths.push(path.join(r, "depker.config.js"));
10+
paths.push(path.join(r, "depker.config.cjs"));
11+
paths.push(path.join(r, "depker.config.mjs"));
12+
paths.push(path.join(r, ".depker/depker.config.ts"));
13+
paths.push(path.join(r, ".depker/depker.config.js"));
14+
paths.push(path.join(r, ".depker/depker.config.cjs"));
15+
paths.push(path.join(r, ".depker/depker.config.mjs"));
16+
paths.push(path.join(r, ".depker/depker.ts"));
17+
paths.push(path.join(r, ".depker/depker.js"));
18+
paths.push(path.join(r, ".depker/depker.cjs"));
19+
paths.push(path.join(r, ".depker/depker.mjs"));
20+
paths.push(path.join(r, ".depker/config.ts"));
21+
paths.push(path.join(r, ".depker/config.js"));
22+
paths.push(path.join(r, ".depker/config.cjs"));
23+
paths.push(path.join(r, ".depker/config.mjs"));
24+
}
25+
}
1526
for (const p of paths) {
1627
if (await fs.exists(p)) {
1728
return path.toFileUrl(p).toString();

src/depker.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export interface DepkerModule {
2121
}
2222

2323
export function depker(): DepkerApp {
24-
return new Depker() as DepkerApp;
24+
return Depker.create();
2525
}
2626

2727
export class Depker {
28+
// singleton
29+
private static instance: DepkerApp;
2830
// info
2931
public readonly name: string;
3032
public readonly version: string;
@@ -43,7 +45,14 @@ export class Depker {
4345
// module
4446
private readonly _modules: Array<DepkerModule>;
4547

46-
constructor() {
48+
public static create(): DepkerApp {
49+
if (!Depker.instance) {
50+
Depker.instance = new Depker() as DepkerApp;
51+
}
52+
return Depker.instance;
53+
}
54+
55+
private constructor() {
4756
// info
4857
this.name = "depker";
4958
this.version = "5.1.1";

0 commit comments

Comments
 (0)