Skip to content

Commit 6a2c075

Browse files
Merge pull request #5 from stape-io/package-setup
Add GitHub Actions workflow for automated npm publishing
2 parents a1cd293 + 5c47362 commit 6a2c075

File tree

16 files changed

+5285
-84
lines changed

16 files changed

+5285
-84
lines changed

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'package.json'
9+
- 'server-gtm-sandboxed-apis.d.ts'
10+
- 'web-gtm-sandboxed-apis.d.ts'
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
registry-url: 'https://registry.npmjs.org'
21+
- run: npm install
22+
- run: npm publish --access public
23+
env:
24+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.github/
2+
node_modules/
3+
dist/
4+
examples/
5+
*.log

README.md

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,103 @@
22

33
This guide explains how to use the provided TypeScript Declaration Files (`.d.ts`) to enable IntelliSense (autocompletion and hover-documentation) for Google Tag Manager's Sandboxed JavaScript APIs in your code editor.
44

5-
There are two files:
5+
There are two file definitions:
66
- `server-gtm-sandboxed-apis.d.ts`: For **Server-side** GTM templates.
77
- `web-gtm-sandboxed-apis.d.ts`: For **Web** GTM templates.
88

9-
---
10-
11-
## What Are These Files?
9+
## What Are These Definitions?
1210

1311
Google Tag Manager's custom templates run in a "sandboxed" JavaScript environment that has a special set of APIs (like `copyFromDataLayer` or `sendHttpRequest`). Standard code editors don't know about these custom APIs, so they can't provide any help as you code.
1412

15-
These `.d.ts` files act as a guide for your editor. They define the signatures, parameters, and documentation for every GTM API, effectively teaching your editor how the GTM environment works.
13+
These files act as a guide for your editor. They define the signatures, parameters, and documentation for every GTM API, effectively teaching your editor how the GTM environment works.
1614

1715

1816
https://github.com/user-attachments/assets/868bbe2c-3e28-47b1-b195-cdfc509ec340
1917

20-
2118
---
2219

2320
## How to Use
2421

25-
Choose the file that corresponds to the environment you are developing for (Web or Server) and place it in your project folder. Then, choose one of the following methods to activate IntelliSense.
22+
1. Install the type definitions directly using a package manager like `npm` or `pnpm`:
23+
```bash
24+
pnpm install -D stape-gtm-api-types
25+
# or
26+
npm install --save-dev stape-gtm-api-types
27+
```
28+
29+
This is the recommended way to keep your GTM API types up to date.
30+
31+
2. After installing the package, you can reference the type definitions in your project as follows:
32+
33+
### Method 1: Using a Triple-Slash Directive (File-by-File)
2634

27-
### Method 1: Using a Triple-Slash Directive (File-by-File)
35+
This method is useful if you prefer not to create a `jsconfig.json` file. You must add a special comment to the **very top** of each JavaScript file containing GTM Sandboxed API code where you want IntelliSense.
2836

29-
This method is useful if you prefer not to create a `jsconfig.json` file. You must add a special comment to the **very top** of each JavaScript file where you want IntelliSense.
37+
Add a special comment to the **very top** of each JavaScript file where you want IntelliSense.
38+
Make sure to add it exactly as is (with triple slashes).
3039

31-
1. **Place the `.d.ts` file** in your project directory (e.g., in the same folder as your `.js` file).
32-
2. **Add the following comment** to the first line of your `.js` file:
40+
- For **Web** GTM Sandboxed APIs:
3341
```javascript
34-
/// <reference path="./web-gtm-sandboxed-apis.d.ts" />
42+
/// <reference types="stape-gtm-api-types/web-gtm-sandboxed-apis" />
3543
3644
// Your GTM template code starts here...
3745
const copyFromDataLayer = require('copyFromDataLayer');
3846
```
39-
3. **Adjust the path**: Make sure the `path` in the comment correctly points to the location of your `.d.ts` file relative to your `.js` file.
4047

41-
### Method 2: Using `jsconfig.json`
48+
- For **Server** GTM Sandboxed APIs:
49+
```javascript
50+
/// <reference types="stape-gtm-api-types/server-gtm-sandboxed-apis" />
51+
52+
// Your GTM template code starts here...
53+
const getAllEventData = require('getAllEventData');
54+
```
55+
56+
### Method 2: Using `jsconfig.json`
4257

43-
This is a modern and reliable method for any project, even if it's just a single file. It tells your editor to treat the entire folder as a JavaScript project.
58+
Create a `jsconfig.json` containing the following content in your project's root directory where the code of your template is located.
4459
45-
1. **Place the `.d.ts` file** in your project's root directory.
46-
2. **Create a `jsconfig.json` file** in the same root directory.
47-
3. **Add the following content** to your `jsconfig.json`:
60+
- For **Web** GTM Sandboxed APIs:
4861
```json
4962
{
5063
"compilerOptions": {
51-
"target": "esnext"
64+
"paths": {
65+
"*": ["./node_modules/stape-gtm-api-types/web-gtm-sandboxed-apis"]
66+
}
5267
},
5368
"include": ["**/*"]
5469
}
5570
```
56-
4. **Reload Your Editor**: If IntelliSense doesn't appear immediately, restart your editor or use the "Reload Window" command.
5771
58-
With this setup, the editor will automatically find and use the type definitions for all `.js` files in your project.
72+
- For **Server** GTM Sandboxed APIs:
73+
```json
74+
{
75+
"compilerOptions": {
76+
"paths": {
77+
"*": ["./node_modules/stape-gtm-api-types/server-gtm-sandboxed-apis"]
78+
}
79+
},
80+
"include": ["**/*"]
81+
}
82+
```
83+
84+
3. Reload your editor if IntelliSense does not appear immediately.
5985
6086
---
6187
6288
## Editor-Specific Instructions
6389
90+
6491
### Visual Studio Code
6592
66-
Both `jsconfig.json` and the triple-slash directive methods work perfectly. The `jsconfig.json` approach is generally more robust and requires less maintenance.
93+
Both methods work perfectly. The **Method 2** is recommended for easier updates and maintenance.
6794
6895
### JetBrains IDEs (WebStorm, IntelliJ IDEA, etc.)
6996
70-
JetBrains IDEs offer the simplest setup:
71-
72-
1. **Place the `.d.ts` file** anywhere in your project directory.
73-
74-
That's it. The IDE will automatically index the file and provide IntelliSense across the entire project without any additional configuration. You do not need a `jsconfig.json` file or triple-slash directives.
97+
JetBrains IDEs will automatically index type definitions from installed `npm` packages. No manual copying required.
7598
7699
### Other Editors (Sublime Text, Neovim, etc.)
77100
78-
For other modern editors that use a Language Server Protocol (LSP) for JavaScript and TypeScript, the process is generally the same as for JetBrains:
79-
80-
1. **Ensure your editor has a TypeScript/JavaScript language server** installed and configured.
81-
2. **Place the `.d.ts` file** in the root of your project folder.
82-
83-
The language server should automatically detect and use the type definitions to provide IntelliSense.
101+
Other editors that support TypeScript/JavaScript language servers will automatically detect type definitions from `npm` packages.
84102
85103
---
86104

0 commit comments

Comments
 (0)