@jrc03c/gt-cli 0.1.5 → 0.1.6

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 +27 -4
  2. package/dist/index.js +16 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -89,16 +89,39 @@ gt request <path> -H "X-Custom:value" # Add custom headers
89
89
 
90
90
  ```json
91
91
  {
92
+ "email": "you@example.com",
93
+ "password": "your-password",
92
94
  "programs": {
93
- "my-program": {
94
- "id": 12345,
95
- "key": "abc1234"
95
+ "abc1234": {
96
+ "file": "my-program.gt",
97
+ "id": 12345
96
98
  }
97
99
  }
98
100
  }
99
101
  ```
100
102
 
101
- This file is gitignored. It maps local program file names to their server-side IDs and keys.
103
+ Programs are keyed by their 7-character program key, and each entry maps to a local `.gt` file and its server-side numeric ID.
104
+
105
+ The `email` and `password` fields are optional — they provide an alternative to environment variables for authentication (see [Authentication](#authentication) above).
106
+
107
+ > **NOTE:** 🚨 If storing `email` and `password` values in `gt.config.json`, then **DO NOT** commit that file to the repository history! Instead, add `gt.config.json` to your `.gitignore` file.
108
+
109
+ ### Separate push and pull files
110
+
111
+ If you use a build step to transform your `.gt` files before pushing, you can specify separate source and dist paths:
112
+
113
+ ```json
114
+ {
115
+ "programs": {
116
+ "abc1234": {
117
+ "file": { "src": "src/program.gt", "dist": "dist/program.gt" },
118
+ "id": 12345
119
+ }
120
+ }
121
+ }
122
+ ```
123
+
124
+ With this configuration, `gt pull` writes to `src/program.gt` and `gt push` reads from `dist/program.gt`.
102
125
 
103
126
  ## Development
104
127
 
package/dist/index.js CHANGED
@@ -9,6 +9,12 @@ var ENVIRONMENT_HOSTS = {
9
9
  stage: "https://guidedtrack-stage.herokuapp.com",
10
10
  production: "https://www.guidedtrack.com"
11
11
  };
12
+ function getPullFile(ref) {
13
+ return typeof ref.file === "string" ? ref.file : ref.file.src;
14
+ }
15
+ function getPushFile(ref) {
16
+ return typeof ref.file === "string" ? ref.file : ref.file.dist;
17
+ }
12
18
 
13
19
  // src/lib/api.ts
14
20
  function buildAuthHeader(credentials) {
@@ -300,7 +306,7 @@ function registerBuild(program2) {
300
306
  process.exit(1);
301
307
  }
302
308
  for (const [key, ref] of entries) {
303
- await buildProgram(ref.file, key, credentials, environment);
309
+ await buildProgram(getPushFile(ref), key, credentials, environment);
304
310
  }
305
311
  });
306
312
  }
@@ -433,7 +439,7 @@ function registerInit(program2) {
433
439
  console.log("No .gt files found.");
434
440
  return;
435
441
  }
436
- const linkedFiles = new Set(Object.values(programs).map((p) => p.file));
442
+ const linkedFiles = new Set(Object.values(programs).map((p) => getPullFile(p)));
437
443
  for (const file of files) {
438
444
  if (linkedFiles.has(file)) {
439
445
  console.log(`
@@ -487,7 +493,7 @@ Found "${file}"`);
487
493
  console.log(`found! ("${found.name}")`);
488
494
  if (programs[found.key]) {
489
495
  console.log(
490
- `Program "${found.name}" is already linked to "${programs[found.key].file}", skipping.`
496
+ `Program "${found.name}" is already linked to "${getPullFile(programs[found.key])}", skipping.`
491
497
  );
492
498
  continue;
493
499
  }
@@ -722,15 +728,16 @@ function registerPull(program2) {
722
728
  }
723
729
  console.log(`Pulling from ${environment}...`);
724
730
  for (const [, ref] of entries) {
731
+ const pullFile = getPullFile(ref);
725
732
  process.stdout.write(
726
- `>> Downloading "${ref.file}" (id: ${ref.id})... `
733
+ `>> Downloading "${pullFile}" (id: ${ref.id})... `
727
734
  );
728
735
  const source = await fetchProgramSource(
729
736
  ref.id,
730
737
  credentials,
731
738
  environment
732
739
  );
733
- await writeFile3(resolve3(process.cwd(), ref.file), source);
740
+ await writeFile3(resolve3(process.cwd(), pullFile), source);
734
741
  console.log("done");
735
742
  }
736
743
  });
@@ -765,11 +772,12 @@ function registerPush(program2) {
765
772
  console.log(`Pushing to ${environment}...`);
766
773
  const pushed = [];
767
774
  for (const [key, ref] of entries) {
775
+ const pushFile = getPushFile(ref);
768
776
  process.stdout.write(
769
- `>> Updating "${ref.file}" (id: ${ref.id})... `
777
+ `>> Updating "${pushFile}" (id: ${ref.id})... `
770
778
  );
771
779
  const contents = await readFile2(
772
- resolve4(process.cwd(), ref.file),
780
+ resolve4(process.cwd(), pushFile),
773
781
  "utf-8"
774
782
  );
775
783
  await apiRequest(`/programs/${ref.id}.json`, {
@@ -779,7 +787,7 @@ function registerPush(program2) {
779
787
  body: { contents, program: { description: "" } }
780
788
  });
781
789
  console.log("done");
782
- pushed.push({ file: ref.file, key });
790
+ pushed.push({ file: pushFile, key });
783
791
  }
784
792
  if (options.build && pushed.length > 0) {
785
793
  console.log("\nBuilding pushed programs...");
package/package.json CHANGED
@@ -39,5 +39,5 @@
39
39
  "test:watch": "vitest"
40
40
  },
41
41
  "type": "module",
42
- "version": "0.1.5"
42
+ "version": "0.1.6"
43
43
  }