@jrc03c/gt-cli 0.1.4 → 0.1.5

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 +6 -6
  2. package/dist/index.js +54 -76
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -37,14 +37,14 @@ Set `GT_ENV` to target different GuidedTrack environments:
37
37
  ```bash
38
38
  gt init # Create gt.config.json by scanning for program files
39
39
  gt config # Print current project configuration
40
- gt push # Upload all local program files to the server
41
- gt push --only <name> # Push a single program
42
- gt push --build # Push and build
40
+ gt push # Upload local programs and build
41
+ gt push --only <key> # Push a single program
42
+ gt push --no-build # Push without building
43
43
  gt pull # Download all program sources from the server
44
- gt pull --only <name> # Pull a single program
45
- gt create [names...] # Create new programs on the server
44
+ gt pull --only <key> # Pull a single program
45
+ gt create [names...] # Create new programs (updates gt.config.json)
46
46
  gt build # Compile programs and report errors
47
- gt compare [args...] # Compare programs using gt-compare
47
+ gt build --only <key> # Build a single program
48
48
  ```
49
49
 
50
50
  ### Program management
package/dist/index.js CHANGED
@@ -3,10 +3,6 @@
3
3
  // src/index.ts
4
4
  import { Command } from "commander";
5
5
 
6
- // src/commands/build.ts
7
- import { readFile as readFile2 } from "fs/promises";
8
- import { resolve as resolve2 } from "path";
9
-
10
6
  // src/types.ts
11
7
  var ENVIRONMENT_HOSTS = {
12
8
  development: "https://localhost:3000",
@@ -136,10 +132,10 @@ async function saveConfig(config, dir) {
136
132
  // src/lib/auth.ts
137
133
  function prompt(question) {
138
134
  const rl2 = createInterface({ input: process.stdin, output: process.stdout });
139
- return new Promise((resolve7) => {
135
+ return new Promise((resolve5) => {
140
136
  rl2.question(question, (answer) => {
141
137
  rl2.close();
142
- resolve7(answer);
138
+ resolve5(answer);
143
139
  });
144
140
  });
145
141
  }
@@ -153,13 +149,13 @@ function promptSecret(question) {
153
149
  }
154
150
  return originalWrite(...args);
155
151
  });
156
- return new Promise((resolve7) => {
152
+ return new Promise((resolve5) => {
157
153
  rl2.question(question, (answer) => {
158
154
  muted = false;
159
155
  process.stdout.write = originalWrite;
160
156
  originalWrite("\n");
161
157
  rl2.close();
162
- resolve7(answer);
158
+ resolve5(answer);
163
159
  });
164
160
  muted = true;
165
161
  });
@@ -200,7 +196,7 @@ async function pollJob(jobId, credentials, options) {
200
196
  if (job.status !== "running") {
201
197
  return job;
202
198
  }
203
- await new Promise((resolve7) => setTimeout(resolve7, interval));
199
+ await new Promise((resolve5) => setTimeout(resolve5, interval));
204
200
  }
205
201
  }
206
202
 
@@ -282,68 +278,32 @@ async function buildProgram(name, key, credentials, environment) {
282
278
  }
283
279
 
284
280
  // src/commands/build.ts
285
- var PROJECTS_FILENAME = ".gt_projects";
286
281
  function registerBuild(program2) {
287
- program2.command("build").description("Compile programs and report errors").action(async () => {
282
+ program2.command("build").description("Compile programs and report errors").option("-o, --only <key>", "Build only the specified program (by key)").action(async (options) => {
288
283
  const credentials = await resolveCredentials();
289
284
  const environment = getEnvironment();
290
- const projects = await loadProjects();
291
- if (!projects) {
292
- console.log(`No ${PROJECTS_FILENAME} file, nothing to build`);
293
- return;
294
- }
295
- for (const project of projects) {
296
- const found = await findProgramByTitle(project, credentials, environment);
297
- if (!found) {
298
- console.error(`>> Program "${project}" not found, skipping...`);
299
- continue;
285
+ const config = await loadConfig();
286
+ const programs = config.programs ?? {};
287
+ let entries = Object.entries(programs);
288
+ if (options.only) {
289
+ const ref = programs[options.only];
290
+ if (!ref) {
291
+ console.error(
292
+ `Program with key "${options.only}" not found in config.`
293
+ );
294
+ process.exit(1);
300
295
  }
301
- await buildProgram(project, found.key, credentials, environment);
296
+ entries = [[options.only, ref]];
302
297
  }
303
- });
304
- }
305
- async function loadProjects() {
306
- try {
307
- const raw = await readFile2(
308
- resolve2(process.cwd(), PROJECTS_FILENAME),
309
- "utf-8"
310
- );
311
- return raw.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
312
- } catch {
313
- return null;
314
- }
315
- }
316
-
317
- // src/commands/compare.ts
318
- import { execFileSync } from "child_process";
319
- import { dirname, resolve as resolve3 } from "path";
320
- function registerCompare(program2) {
321
- program2.command("compare").description("Compare programs using gt-compare").allowUnknownOption().argument("[args...]", "Arguments to pass to gt-compare").action((args) => {
322
- const gtPath = process.env.GT_COMPARE_PATH ?? findGtCompare();
323
- if (!gtPath) {
324
- console.error(
325
- "Could not find gt-compare. Set GT_COMPARE_PATH to the gt-compare directory."
326
- );
298
+ if (entries.length === 0) {
299
+ console.error("No programs in config. Run `gt init` first.");
327
300
  process.exit(1);
328
301
  }
329
- try {
330
- execFileSync("./gt-compare", args, {
331
- cwd: gtPath,
332
- stdio: "inherit"
333
- });
334
- } catch {
335
- process.exit(1);
302
+ for (const [key, ref] of entries) {
303
+ await buildProgram(ref.file, key, credentials, environment);
336
304
  }
337
305
  });
338
306
  }
339
- function findGtCompare() {
340
- try {
341
- const gtBin = execFileSync("which", ["gt"], { encoding: "utf-8" }).trim();
342
- return resolve3(dirname(gtBin), "gt-compare");
343
- } catch {
344
- return null;
345
- }
346
- }
347
307
 
348
308
  // src/commands/config.ts
349
309
  function registerConfig(program2) {
@@ -387,6 +347,9 @@ function registerCreate(program2) {
387
347
  process.exit(1);
388
348
  }
389
349
  console.log(`Creating programs in ${environment}...`);
350
+ const config = await loadConfig();
351
+ const programs = config.programs ?? {};
352
+ let configChanged = false;
390
353
  for (const filename of filenames) {
391
354
  process.stdout.write(`>> Creating "${filename}"... `);
392
355
  try {
@@ -398,7 +361,19 @@ function registerCreate(program2) {
398
361
  });
399
362
  const data = await response.json();
400
363
  if (data.job_id) {
401
- console.log("done");
364
+ await pollJob(data.job_id, credentials, {
365
+ environment,
366
+ intervalMs: 1e3
367
+ }).catch(() => {
368
+ });
369
+ const found = await findProgramByTitle(filename, credentials, environment);
370
+ if (found) {
371
+ console.log(`done (id: ${found.id}, key: ${found.key})`);
372
+ programs[found.key] = { file: filename, id: found.id };
373
+ configChanged = true;
374
+ } else {
375
+ console.log("done");
376
+ }
402
377
  } else {
403
378
  console.error("failed");
404
379
  console.error(`${JSON.stringify(data)} -- skipping`);
@@ -409,6 +384,10 @@ function registerCreate(program2) {
409
384
  process.exit(1);
410
385
  }
411
386
  }
387
+ if (configChanged) {
388
+ await saveConfig({ ...config, programs });
389
+ console.log("Updated gt.config.json");
390
+ }
412
391
  });
413
392
  }
414
393
 
@@ -417,10 +396,10 @@ import { createInterface as createInterface2 } from "readline";
417
396
  var rl = () => createInterface2({ input: process.stdin, output: process.stdout });
418
397
  async function ask(question) {
419
398
  const iface = rl();
420
- return new Promise((resolve7) => {
399
+ return new Promise((resolve5) => {
421
400
  iface.question(question, (answer) => {
422
401
  iface.close();
423
- resolve7(answer.trim());
402
+ resolve5(answer.trim());
424
403
  });
425
404
  });
426
405
  }
@@ -526,7 +505,7 @@ Wrote ${CONFIG_FILENAME}`);
526
505
  // src/commands/program.ts
527
506
  import { exec } from "child_process";
528
507
  import { writeFile as writeFile2 } from "fs/promises";
529
- import { resolve as resolve4 } from "path";
508
+ import { resolve as resolve2 } from "path";
530
509
  import { createInterface as createInterface3 } from "readline";
531
510
  function registerProgram(parent) {
532
511
  const program2 = parent.command("program").description("Manage programs on the server");
@@ -693,7 +672,7 @@ function registerProgram(parent) {
693
672
  });
694
673
  const csv = await response.text();
695
674
  if (options.output) {
696
- await writeFile2(resolve4(process.cwd(), options.output), csv);
675
+ await writeFile2(resolve2(process.cwd(), options.output), csv);
697
676
  console.log(`Saved to ${options.output}`);
698
677
  } else {
699
678
  process.stdout.write(csv);
@@ -702,10 +681,10 @@ function registerProgram(parent) {
702
681
  }
703
682
  function confirm2(prompt2) {
704
683
  const rl2 = createInterface3({ input: process.stdin, output: process.stdout });
705
- return new Promise((resolve7) => {
684
+ return new Promise((resolve5) => {
706
685
  rl2.question(prompt2, (answer) => {
707
686
  rl2.close();
708
- resolve7(answer.toLowerCase() === "y");
687
+ resolve5(answer.toLowerCase() === "y");
709
688
  });
710
689
  });
711
690
  }
@@ -717,7 +696,7 @@ function openBrowser(url) {
717
696
 
718
697
  // src/commands/pull.ts
719
698
  import { writeFile as writeFile3 } from "fs/promises";
720
- import { resolve as resolve5 } from "path";
699
+ import { resolve as resolve3 } from "path";
721
700
  function registerPull(program2) {
722
701
  program2.command("pull").description("Download program source from the server").option("-o, --only <key>", "Pull only the specified program (by key)").action(async (options) => {
723
702
  const credentials = await resolveCredentials();
@@ -751,17 +730,17 @@ function registerPull(program2) {
751
730
  credentials,
752
731
  environment
753
732
  );
754
- await writeFile3(resolve5(process.cwd(), ref.file), source);
733
+ await writeFile3(resolve3(process.cwd(), ref.file), source);
755
734
  console.log("done");
756
735
  }
757
736
  });
758
737
  }
759
738
 
760
739
  // src/commands/push.ts
761
- import { readFile as readFile3 } from "fs/promises";
762
- import { resolve as resolve6 } from "path";
740
+ import { readFile as readFile2 } from "fs/promises";
741
+ import { resolve as resolve4 } from "path";
763
742
  function registerPush(program2) {
764
- program2.command("push").description("Upload local program files to the server").option("-o, --only <key>", "Push only the specified program (by key)").option("-b, --build", "Build after pushing").action(async (options) => {
743
+ program2.command("push").description("Upload local program files to the server").option("-o, --only <key>", "Push only the specified program (by key)").option("--no-build", "Skip building after push").action(async (options) => {
765
744
  const credentials = await resolveCredentials();
766
745
  const environment = getEnvironment();
767
746
  const config = await loadConfig();
@@ -789,8 +768,8 @@ function registerPush(program2) {
789
768
  process.stdout.write(
790
769
  `>> Updating "${ref.file}" (id: ${ref.id})... `
791
770
  );
792
- const contents = await readFile3(
793
- resolve6(process.cwd(), ref.file),
771
+ const contents = await readFile2(
772
+ resolve4(process.cwd(), ref.file),
794
773
  "utf-8"
795
774
  );
796
775
  await apiRequest(`/programs/${ref.id}.json`, {
@@ -865,7 +844,6 @@ registerPush(program);
865
844
  registerPull(program);
866
845
  registerCreate(program);
867
846
  registerBuild(program);
868
- registerCompare(program);
869
847
  registerInit(program);
870
848
  registerConfig(program);
871
849
  registerProgram(program);
package/package.json CHANGED
@@ -39,5 +39,5 @@
39
39
  "test:watch": "vitest"
40
40
  },
41
41
  "type": "module",
42
- "version": "0.1.4"
42
+ "version": "0.1.5"
43
43
  }