@andrestobelem/clone 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +16 -0
  2. package/bin/clone.js +45 -12
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Run a local issue and project workspace without installing Python.
4
4
 
5
+ Website: <https://clone-andrestobelem-prod.web.app>
6
+
5
7
  ```sh
6
8
  npx @andrestobelem/clone
7
9
  ```
@@ -12,10 +14,24 @@ Clone stores its database, attachments, snapshots, and backups in the operating
12
14
 
13
15
  ```sh
14
16
  npx @andrestobelem/clone start --port 5000
17
+ npx @andrestobelem/clone --local
18
+ npx @andrestobelem/clone --data-dir ./project-data
15
19
  npx @andrestobelem/clone teams list --json
16
20
  npx @andrestobelem/clone --help
17
21
  ```
18
22
 
19
23
  Use `--no-open` with `start` to keep the browser closed. Set `CLONE_DATA_DIR` to select another data directory.
20
24
 
25
+ `--local` stores the workspace in `.clone/` in the current directory. Add `.clone/` to the repository's `.gitignore` unless you have a specific backup workflow. `--data-dir PATH` selects an explicit directory.
26
+
27
+ ## Data locations
28
+
29
+ | System | Workspace data | Downloaded executable cache |
30
+ | --- | --- | --- |
31
+ | macOS | `~/Library/Application Support/Clone/` | `~/Library/Caches/Clone/` |
32
+ | Linux | `$XDG_DATA_HOME/clone/` or `~/.local/share/clone/` | `$XDG_CACHE_HOME/clone/` or `~/.cache/clone/` |
33
+ | Windows | `%APPDATA%\Clone\` | `%LOCALAPPDATA%\Clone\cache\` |
34
+
35
+ The workspace data directory contains `workspace.sqlite3`, snapshots, attachments, and backups. Set `CLONE_CACHE_DIR` to select another executable cache.
36
+
21
37
  Clone supports macOS on ARM64 and x64, Linux on ARM64 and x64, and Windows on x64.
package/bin/clone.js CHANGED
@@ -37,13 +37,39 @@ function cacheDirectory(platform = process.platform, environment = process.env)
37
37
  return path.join(environment.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"), "clone");
38
38
  }
39
39
 
40
- function dataDirectory(platform = process.platform, environment = process.env) {
40
+ function dataDirectory(platform = process.platform, environment = process.env, override = null) {
41
+ if (override) return path.resolve(override);
41
42
  if (environment.CLONE_DATA_DIR) return path.resolve(environment.CLONE_DATA_DIR);
42
43
  if (platform === "darwin") return path.join(os.homedir(), "Library", "Application Support", "Clone");
43
44
  if (platform === "win32") return path.join(environment.APPDATA || os.homedir(), "Clone");
44
45
  return path.join(environment.XDG_DATA_HOME || path.join(os.homedir(), ".local", "share"), "clone");
45
46
  }
46
47
 
48
+ function parseLauncherArguments(arguments_, workingDirectory = process.cwd()) {
49
+ let storage = null;
50
+ const forwarded = [];
51
+ for (let index = 0; index < arguments_.length; index += 1) {
52
+ const value = arguments_[index];
53
+ if (value === "--local") {
54
+ if (storage) throw new Error("Use only one data directory option.");
55
+ storage = path.join(workingDirectory, ".clone");
56
+ } else if (value === "--data-dir") {
57
+ if (storage) throw new Error("Use only one data directory option.");
58
+ const directory = arguments_[++index];
59
+ if (!directory) throw new Error("--data-dir requires a path.");
60
+ storage = path.resolve(workingDirectory, directory);
61
+ } else if (value.startsWith("--data-dir=")) {
62
+ if (storage) throw new Error("Use only one data directory option.");
63
+ const directory = value.slice(11);
64
+ if (!directory) throw new Error("--data-dir requires a path.");
65
+ storage = path.resolve(workingDirectory, directory);
66
+ } else {
67
+ forwarded.push(value);
68
+ }
69
+ }
70
+ return { arguments: forwarded, storage };
71
+ }
72
+
47
73
  async function download(url, destination) {
48
74
  const response = await fetch(url, { headers: { "user-agent": `clone/${packageMetadata.version}` } });
49
75
  if (!response.ok) throw new Error(`Download failed (${response.status}): ${url}`);
@@ -124,14 +150,14 @@ function initialize(binary, database, storage) {
124
150
  if (result.status !== 0) throw new Error(`Clone initialization failed with exit code ${result.status}.`);
125
151
  }
126
152
 
127
- async function start(binary, arguments_) {
153
+ async function start(binary, arguments_, environment = process.env) {
128
154
  const options = parseStartArguments(arguments_);
129
- const storage = dataDirectory();
155
+ const storage = dataDirectory(process.platform, environment);
130
156
  const database = path.join(storage, "workspace.sqlite3");
131
157
  initialize(binary, database, storage);
132
158
  const url = `http://127.0.0.1:${options.port}`;
133
159
  const child = spawn(binary, ["--db", database, "serve"], {
134
- env: { ...process.env, CLONE_HOST: "127.0.0.1", PORT: options.port },
160
+ env: { ...environment, CLONE_HOST: "127.0.0.1", PORT: options.port },
135
161
  stdio: "inherit",
136
162
  });
137
163
  const errorState = { value: null };
@@ -150,34 +176,41 @@ async function start(binary, arguments_) {
150
176
  });
151
177
  }
152
178
 
153
- function help() {
179
+ function help(storage = null) {
154
180
  console.log(`Clone ${packageMetadata.version}
155
181
 
156
182
  Usage:
157
- clone [start] [--port PORT] [--no-open]
158
- clone <CLI command> [options]
183
+ clone [--local | --data-dir PATH] [start] [--port PORT] [--no-open]
184
+ clone [--local | --data-dir PATH] <CLI command> [options]
159
185
 
160
186
  Examples:
161
187
  npx @andrestobelem/clone
188
+ npx @andrestobelem/clone --local
189
+ npx @andrestobelem/clone --data-dir ./project-data
162
190
  npx @andrestobelem/clone start --port 5000
163
191
  npx @andrestobelem/clone teams list --json
164
192
 
165
- Data: ${dataDirectory()}`);
193
+ Data: ${dataDirectory(process.platform, process.env, storage)}`);
166
194
  }
167
195
 
168
196
  async function main(arguments_ = process.argv.slice(2)) {
197
+ const launcher = parseLauncherArguments(arguments_);
198
+ arguments_ = launcher.arguments;
169
199
  if (arguments_.includes("--version") || arguments_.includes("-V")) {
170
200
  console.log(packageMetadata.version);
171
201
  return 0;
172
202
  }
173
203
  if (arguments_.includes("--help") || arguments_.includes("-h")) {
174
- help();
204
+ help(launcher.storage);
175
205
  return 0;
176
206
  }
177
207
  const binary = await binaryPath();
178
208
  const command = arguments_[0];
179
- if (!command || command === "start") return start(binary, command ? arguments_.slice(1) : arguments_);
180
- const storage = dataDirectory();
209
+ if (!command || command === "start") {
210
+ const environment = launcher.storage ? { ...process.env, CLONE_DATA_DIR: launcher.storage } : process.env;
211
+ return start(binary, command ? arguments_.slice(1) : arguments_, environment);
212
+ }
213
+ const storage = dataDirectory(process.platform, process.env, launcher.storage);
181
214
  const database = path.join(storage, "workspace.sqlite3");
182
215
  initialize(binary, database, storage);
183
216
  const result = spawnSync(binary, ["--db", database, ...arguments_], { stdio: "inherit" });
@@ -192,4 +225,4 @@ if (require.main === module) {
192
225
  });
193
226
  }
194
227
 
195
- module.exports = { cacheDirectory, dataDirectory, parseStartArguments, target };
228
+ module.exports = { cacheDirectory, dataDirectory, parseLauncherArguments, parseStartArguments, target };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@andrestobelem/clone",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Run the Clone issue and project workspace locally.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/andrestobelem/clone.git"
9
9
  },
10
- "homepage": "https://github.com/andrestobelem/clone#readme",
10
+ "homepage": "https://clone-andrestobelem-prod.web.app",
11
11
  "bugs": "https://github.com/andrestobelem/clone/issues",
12
12
  "type": "commonjs",
13
13
  "bin": {