ohmydashboard 0.1.0 → 0.1.2

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/cli.d.ts CHANGED
@@ -1,15 +1,29 @@
1
- import type fs from "fs";
2
- import type path from "path";
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
3
  export interface ExecFn {
4
4
  (command: string, args: string[], options?: {
5
5
  cwd?: string;
6
6
  }): Promise<void>;
7
7
  }
8
+ export interface DownloadRepoFn {
9
+ (opts: {
10
+ owner: string;
11
+ repo: string;
12
+ branch: string;
13
+ targetPath: string;
14
+ }): Promise<void>;
15
+ }
8
16
  export interface CliDeps {
9
17
  exec?: ExecFn;
18
+ downloadRepo?: DownloadRepoFn;
10
19
  cwd?: string;
11
20
  log?: (line: string) => void;
12
21
  fs: typeof fs;
13
22
  path: typeof path;
14
23
  }
24
+ export declare function parseGitHubRepo(repoUrl: string): {
25
+ owner: string;
26
+ repo: string;
27
+ } | null;
28
+ export declare function buildTarballUrl(owner: string, repo: string, branch: string): string;
15
29
  export declare function runCli(args: string[], deps: CliDeps): Promise<void>;
package/dist/cli.js CHANGED
@@ -1,13 +1,61 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.parseGitHubRepo = parseGitHubRepo;
40
+ exports.buildTarballUrl = buildTarballUrl;
3
41
  exports.runCli = runCli;
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
4
44
  const child_process_1 = require("child_process");
5
- const DEFAULT_REPO = "https://github.com/gvrizzo/ohmydashboard";
45
+ const os_1 = __importDefault(require("os"));
46
+ const https_1 = __importDefault(require("https"));
47
+ const promises_1 = require("stream/promises");
48
+ const DEFAULT_REPO = "https://github.com/gvrizzo/ohmydashboard.git";
49
+ const DEFAULT_SSH_REPO = "git@github.com:gvrizzo/ohmydashboard.git";
6
50
  const DEFAULT_DIR = "ohmydashboard";
51
+ const DEFAULT_BRANCH = "main";
7
52
  function parseArgs(args) {
8
53
  let repoUrl = DEFAULT_REPO;
9
54
  let targetDir = DEFAULT_DIR;
10
55
  let showHelp = false;
56
+ let useSsh = false;
57
+ let branch = DEFAULT_BRANCH;
58
+ let useGit = false;
11
59
  for (let i = 0; i < args.length; i += 1) {
12
60
  const arg = args[i];
13
61
  if (!arg)
@@ -16,6 +64,14 @@ function parseArgs(args) {
16
64
  showHelp = true;
17
65
  continue;
18
66
  }
67
+ if (arg === "--git") {
68
+ useGit = true;
69
+ continue;
70
+ }
71
+ if (arg === "--ssh") {
72
+ useSsh = true;
73
+ continue;
74
+ }
19
75
  if (arg === "--repo") {
20
76
  const next = args[i + 1];
21
77
  if (next) {
@@ -24,11 +80,19 @@ function parseArgs(args) {
24
80
  }
25
81
  continue;
26
82
  }
83
+ if (arg === "--branch") {
84
+ const next = args[i + 1];
85
+ if (next) {
86
+ branch = next;
87
+ i += 1;
88
+ }
89
+ continue;
90
+ }
27
91
  if (!arg.startsWith("-") && targetDir === DEFAULT_DIR) {
28
92
  targetDir = arg;
29
93
  }
30
94
  }
31
- return { targetDir, repoUrl, showHelp };
95
+ return { targetDir, repoUrl, showHelp, useSsh, branch, useGit };
32
96
  }
33
97
  function defaultExec(command, args, options) {
34
98
  return new Promise((resolve, reject) => {
@@ -45,21 +109,83 @@ function defaultExec(command, args, options) {
45
109
  });
46
110
  });
47
111
  }
112
+ function parseGitHubRepo(repoUrl) {
113
+ const trimmed = repoUrl.trim();
114
+ if (/^[^/]+\/[^/]+$/.test(trimmed)) {
115
+ const [owner, repo] = trimmed.split("/");
116
+ return { owner, repo: repo.replace(/\.git$/, "") };
117
+ }
118
+ const sshMatch = trimmed.match(/^git@github\.com:([^/]+)\/(.+?)(\.git)?$/i);
119
+ if (sshMatch) {
120
+ return { owner: sshMatch[1], repo: sshMatch[2] };
121
+ }
122
+ const httpsMatch = trimmed.match(/^https?:\/\/github\.com\/([^/]+)\/(.+?)(\.git)?$/i);
123
+ if (httpsMatch) {
124
+ return { owner: httpsMatch[1], repo: httpsMatch[2] };
125
+ }
126
+ return null;
127
+ }
128
+ function buildTarballUrl(owner, repo, branch) {
129
+ return `https://codeload.github.com/${owner}/${repo}/tar.gz/${branch}`;
130
+ }
131
+ async function defaultDownloadRepo(opts) {
132
+ const { owner, repo, branch, targetPath } = opts;
133
+ await fs.promises.mkdir(targetPath, { recursive: true });
134
+ const tmpFile = await fs.promises.mkdtemp(path.join(os_1.default.tmpdir(), "ohmydashboard-"));
135
+ const tarPath = path.join(tmpFile, `${repo}.tar.gz`);
136
+ const url = buildTarballUrl(owner, repo, branch);
137
+ await new Promise((resolve, reject) => {
138
+ https_1.default.get(url, (res) => {
139
+ if (res.statusCode && res.statusCode >= 400) {
140
+ reject(new Error(`Failed to download repo (HTTP ${res.statusCode})`));
141
+ return;
142
+ }
143
+ const fileStream = fs.createWriteStream(tarPath);
144
+ (0, promises_1.pipeline)(res, fileStream).then(resolve).catch(reject);
145
+ }).on("error", reject);
146
+ });
147
+ const tar = await Promise.resolve().then(() => __importStar(require("tar")));
148
+ await tar.x({
149
+ file: tarPath,
150
+ cwd: targetPath,
151
+ strip: 1,
152
+ });
153
+ }
48
154
  async function runCli(args, deps) {
49
155
  const { fs, path } = deps;
50
156
  const exec = deps.exec ?? defaultExec;
157
+ const downloadRepo = deps.downloadRepo ?? defaultDownloadRepo;
51
158
  const cwd = deps.cwd ?? process.cwd();
52
159
  const log = deps.log ?? console.log;
53
- const { targetDir, repoUrl, showHelp } = parseArgs(args);
160
+ const { targetDir, repoUrl, showHelp, useSsh, branch, useGit } = parseArgs(args);
54
161
  if (showHelp) {
55
- log("Usage: npx ohmydashboard [target-dir] [--repo <url>]");
162
+ log("Usage: npx ohmydashboard [target-dir] [--repo <url>] [--branch <name>] [--git] [--ssh]");
56
163
  return;
57
164
  }
58
165
  const targetPath = path.join(cwd, targetDir);
59
166
  if (fs.existsSync(targetPath)) {
60
167
  throw new Error("Target directory already exists");
61
168
  }
62
- await exec("git", ["clone", repoUrl, targetDir], { cwd });
169
+ if (useGit) {
170
+ const cloneArgs = ["clone"];
171
+ if (branch) {
172
+ cloneArgs.push("--branch", branch);
173
+ }
174
+ cloneArgs.push(useSsh ? DEFAULT_SSH_REPO : repoUrl, targetDir);
175
+ await exec("git", cloneArgs, { cwd });
176
+ }
177
+ else {
178
+ const parsed = parseGitHubRepo(repoUrl);
179
+ if (!parsed) {
180
+ throw new Error("Repo must be a GitHub URL or owner/repo (use --git for other hosts).");
181
+ }
182
+ await downloadRepo({
183
+ owner: parsed.owner,
184
+ repo: parsed.repo,
185
+ branch,
186
+ targetPath,
187
+ });
188
+ }
63
189
  await exec("pnpm", ["install"], { cwd: targetPath });
64
190
  log("");
65
191
  log("Setup complete!");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohmydashboard",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "OhMyDashboard CLI",
6
6
  "license": "MIT",
@@ -16,6 +16,9 @@
16
16
  "files": [
17
17
  "dist"
18
18
  ],
19
+ "dependencies": {
20
+ "tar": "^7.5.1"
21
+ },
19
22
  "publishConfig": {
20
23
  "access": "public"
21
24
  },