@dac-tech-team-tw/gtm-cli 0.0.0-stage → 1.6.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/LICENSE +21 -0
- package/README.md +43 -2
- package/bin/gtm +44 -0
- package/install.js +77 -0
- package/package.json +44 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 owntag
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dac-tech-team-tw/gtm-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line interface for Google Tag Manager. See the [project documentation](https://github.com/dac-tech-team-tw/gtm-cli) for configuration and commands.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Node.js 16 or newer and npm are required. Supported platforms are Windows x64, macOS x64 and arm64, and Linux x64. Installing downloads the matching binary for the package version from the project's GitHub Releases, so network access to GitHub and its release asset host is required. npm lifecycle scripts must be enabled for the automatic download; if scripts were disabled, the wrapper attempts the download on first use.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @dac-tech-team-tw/gtm-cli
|
|
11
|
+
gtm --help
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Alternatively, run without a global installation:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx @dac-tech-team-tw/gtm-cli --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For reproducible CI, pin a released version, for example:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @dac-tech-team-tw/gtm-cli@1.6.2
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gtm auth login
|
|
30
|
+
gtm accounts list
|
|
31
|
+
gtm containers list --account-id <account-id>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Google Tag Manager access and appropriate credentials are required. Use `gtm auth login --help` for authentication options.
|
|
35
|
+
|
|
36
|
+
## Publishing setup
|
|
37
|
+
|
|
38
|
+
The release script synchronizes `npm/package.json` with the version in `deno.json` and creates a version tag. The `release.yml` GitHub Actions workflow builds all four binaries, uploads them to the GitHub release, then publishes the npm package. Do not publish a package version before its matching `v<version>` release assets exist.
|
|
39
|
+
|
|
40
|
+
Configure npm trusted publishing for `@dac-tech-team-tw/gtm-cli` with GitHub organization/user `dac-tech-team-tw`, repository `gtm-cli`, and workflow filename `release.yml`. The package must exist on npm before configuring its trusted publisher; if necessary, an authorized maintainer must perform the initial public publish after the matching release assets are available. Subsequent workflow publishes use GitHub Actions OIDC and do not require an npm token. The workflow also requires the `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` repository secrets for release builds.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT; see [LICENSE](LICENSE) for the original copyright notice.
|
package/bin/gtm
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GTM CLI wrapper script
|
|
5
|
+
*
|
|
6
|
+
* This script runs the downloaded binary. If the binary doesn't exist,
|
|
7
|
+
* it will attempt to download it first.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { spawn, spawnSync } = require("child_process");
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const path = require("path");
|
|
13
|
+
|
|
14
|
+
const BIN_NAME = process.platform === "win32" ? "gtm-binary.exe" : "gtm-binary";
|
|
15
|
+
const BIN_PATH = path.join(__dirname, BIN_NAME);
|
|
16
|
+
const INSTALL_SCRIPT = path.join(__dirname, "..", "install.js");
|
|
17
|
+
|
|
18
|
+
// Check if the binary exists
|
|
19
|
+
if (!fs.existsSync(BIN_PATH)) {
|
|
20
|
+
console.error("GTM CLI binary not found. Running install script...");
|
|
21
|
+
const install = spawnSync(process.execPath, [INSTALL_SCRIPT], { stdio: "inherit" });
|
|
22
|
+
if (install.error || install.status !== 0) {
|
|
23
|
+
if (install.error) console.error(`Failed to run installer: ${install.error.message}`);
|
|
24
|
+
process.exit(install.status || 1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Run the binary with all arguments
|
|
29
|
+
const child = spawn(BIN_PATH, process.argv.slice(2), {
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
child.on("close", (code, signal) => {
|
|
34
|
+
if (signal) {
|
|
35
|
+
process.kill(process.pid, signal);
|
|
36
|
+
} else {
|
|
37
|
+
process.exit(code ?? 1);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
child.on("error", (error) => {
|
|
42
|
+
console.error(`Failed to run GTM CLI: ${error.message}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Download the binary corresponding to this package's exact version.
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { pipeline } = require("stream");
|
|
8
|
+
const { promisify } = require("util");
|
|
9
|
+
|
|
10
|
+
const REPO = "dac-tech-team-tw/gtm-cli";
|
|
11
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
12
|
+
const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "gtm-binary.exe" : "gtm-binary");
|
|
13
|
+
const streamPipeline = promisify(pipeline);
|
|
14
|
+
|
|
15
|
+
function getBinaryName() {
|
|
16
|
+
const target = `${process.platform}-${process.arch}`;
|
|
17
|
+
const binaries = {
|
|
18
|
+
"darwin-x64": "gtm-darwin-x64",
|
|
19
|
+
"darwin-arm64": "gtm-darwin-arm64",
|
|
20
|
+
"linux-x64": "gtm-linux-x64",
|
|
21
|
+
"win32-x64": "gtm-windows-x64.exe",
|
|
22
|
+
};
|
|
23
|
+
if (!binaries[target]) {
|
|
24
|
+
throw new Error(`Unsupported platform: ${target}. Supported: ${Object.keys(binaries).join(", ")}.`);
|
|
25
|
+
}
|
|
26
|
+
return binaries[target];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function download(url, dest, redirects = 0) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
https.get(url, (response) => {
|
|
32
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
|
|
33
|
+
const location = response.headers.location;
|
|
34
|
+
response.resume();
|
|
35
|
+
if (!location || redirects >= 10) {
|
|
36
|
+
reject(new Error("Invalid or excessive download redirects"));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const next = new URL(location, url);
|
|
40
|
+
if (next.protocol !== "https:") {
|
|
41
|
+
reject(new Error("Refusing non-HTTPS download redirect"));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
resolve(download(next, dest, redirects + 1));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (response.statusCode !== 200) {
|
|
48
|
+
response.resume();
|
|
49
|
+
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
resolve(streamPipeline(response, fs.createWriteStream(dest)));
|
|
53
|
+
}).on("error", reject);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function main() {
|
|
58
|
+
const version = require("./package.json").version;
|
|
59
|
+
const binaryName = getBinaryName();
|
|
60
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${binaryName}`;
|
|
61
|
+
const temporaryPath = `${BIN_PATH}.${process.pid}.tmp`;
|
|
62
|
+
console.log(`Downloading GTM CLI v${version} for ${process.platform}-${process.arch}...`);
|
|
63
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
64
|
+
try {
|
|
65
|
+
await download(url, temporaryPath);
|
|
66
|
+
if (process.platform !== "win32") fs.chmodSync(temporaryPath, 0o755);
|
|
67
|
+
fs.renameSync(temporaryPath, BIN_PATH);
|
|
68
|
+
console.log("GTM CLI installed successfully!");
|
|
69
|
+
} finally {
|
|
70
|
+
if (fs.existsSync(temporaryPath)) fs.unlinkSync(temporaryPath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch((error) => {
|
|
75
|
+
console.error(`Failed to install GTM CLI: ${error.message}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dac-tech-team-tw/gtm-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.6.2",
|
|
4
|
+
"description": "Command-line interface for Google Tag Manager",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"google-tag-manager",
|
|
7
|
+
"gtm",
|
|
8
|
+
"cli",
|
|
9
|
+
"google",
|
|
10
|
+
"tag-manager",
|
|
11
|
+
"analytics"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/dac-tech-team-tw/gtm-cli",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/dac-tech-team-tw/gtm-cli/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/dac-tech-team-tw/gtm-cli.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "dac-tech-team-tw",
|
|
23
|
+
"bin": {
|
|
24
|
+
"gtm": "bin/gtm"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin",
|
|
28
|
+
"install.js",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"postinstall": "node install.js"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=16"
|
|
36
|
+
},
|
|
37
|
+
"os": [
|
|
38
|
+
"darwin",
|
|
39
|
+
"linux",
|
|
40
|
+
"win32"
|
|
41
|
+
],
|
|
42
|
+
"cpu": [
|
|
43
|
+
"x64",
|
|
44
|
+
"arm64"
|
|
45
|
+
]
|
|
46
|
+
}
|