@depctdev/depct 0.3.2 → 0.3.4

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.cjs +33 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depctdev/depct",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "CLI for running Node apps with Depct instrumentation",
5
5
  "bin": {
6
6
  "depct": "src/index.cjs"
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "depct-loader": "0.1.0",
15
+ "depct-loader": "^0.1.3",
16
16
  "fast-glob": "^3.3.3"
17
17
  }
18
18
  }
package/src/index.cjs CHANGED
@@ -8,17 +8,17 @@ const { spawn } = require("node:child_process");
8
8
  const HELP = `depct CLI
9
9
 
10
10
  Usage:
11
- depct init [options] Register a new project
11
+ depct init project_token=<token> Link to a project from app.depct.dev
12
12
  depct run [options] -- <command> [args...] Run with instrumentation
13
13
  depct generate [options] Generate documentation
14
14
 
15
15
  Commands:
16
- init Register project with the depct server and create .depctrc
16
+ init Link to a project created at app.depct.dev and create .depctrc
17
17
  run Run a command with depct instrumentation
18
18
  generate Package source files, trigger doc generation, poll for completion
19
19
 
20
20
  depct init options:
21
- --name <name> Project name (default: from package.json)
21
+ project_token=<token> Project token from app.depct.dev (required)
22
22
  --server-url <url> Server URL (default: DEPCT_SERVER_URL or http://localhost:3100)
23
23
 
24
24
  depct run options:
@@ -252,17 +252,40 @@ function parseInitArgs(argv) {
252
252
 
253
253
  async function handleInit(argv) {
254
254
  const options = parseInitArgs(argv);
255
+
256
+ // Extract project_token= from arguments
257
+ let projectToken = null;
258
+ for (const arg of argv) {
259
+ if (arg.startsWith("project_token=")) {
260
+ projectToken = arg.split("=").slice(1).join("=");
261
+ }
262
+ }
263
+
264
+ if (!projectToken) {
265
+ // No token provided — direct user to the web app
266
+ process.stdout.write("\n");
267
+ process.stdout.write(" To set up a new project:\n");
268
+ process.stdout.write("\n");
269
+ process.stdout.write(" 1. Go to https://app.depct.dev and create a project\n");
270
+ process.stdout.write(" 2. Copy the init command shown after creation\n");
271
+ process.stdout.write(" 3. Run: npx depct.dev init project_token=<your_token>\n");
272
+ process.stdout.write("\n");
273
+ process.exit(0);
274
+ }
275
+
255
276
  const serverUrl = options.serverUrl || process.env.DEPCT_SERVER_URL || "http://localhost:3100";
256
- const projectName = options.name || inferProjectIdFromPackageJson(process.cwd()) || path.basename(process.cwd());
257
277
 
258
- process.stdout.write(`Registering project "${projectName}" with ${serverUrl}...\n`);
278
+ process.stdout.write(`Linking project from ${serverUrl}...\n`);
259
279
 
260
280
  let response;
261
281
  try {
262
- response = await fetch(`${serverUrl}/v1/projects`, {
282
+ response = await fetch(`${serverUrl}/v1/projects/init`, {
263
283
  method: "POST",
264
- headers: { "content-type": "application/json" },
265
- body: JSON.stringify({ project_name: projectName }),
284
+ headers: {
285
+ "content-type": "application/json",
286
+ "authorization": `Bearer ${projectToken}`,
287
+ },
288
+ body: JSON.stringify({}),
266
289
  });
267
290
  } catch (err) {
268
291
  fail(`Failed to connect to server at ${serverUrl}: ${err.message}`);
@@ -275,7 +298,7 @@ async function handleInit(argv) {
275
298
 
276
299
  const config = {
277
300
  project_id: result.project_id,
278
- project_token: result.project_token,
301
+ project_token: projectToken,
279
302
  project_name: result.project_name,
280
303
  server_url: serverUrl,
281
304
  include: DEFAULT_INCLUDE,
@@ -284,7 +307,7 @@ async function handleInit(argv) {
284
307
 
285
308
  writeDepctrc(config);
286
309
 
287
- process.stdout.write(`Project registered: ${result.project_id}\n`);
310
+ process.stdout.write(`Project linked: ${result.project_name} (${result.project_id})\n`);
288
311
  process.stdout.write(`Config written to ${DEPCTRC_NAME}\n`);
289
312
  }
290
313