UNPKG

34.8 kBMarkdownView Raw
1# [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli)
2
3[![npm](https://img.shields.io/npm/v/@d-cat/tag-cli?color=brightgreen)](https://www.npmjs.com/package/@d-cat/tag-cli) [![node](https://img.shields.io/node/v/@d-cat/tag-cli?color=brightgreen)](<(https://www.npmjs.com/package/@d-cat/tag-cli)>) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![codecov](https://codecov.io/gl/d-cat:templates:ci-cd/tag-cli/branch/master/graph/badge.svg?token=l7O5FqoJsT)](https://codecov.io/gl/d-cat:templates:ci-cd/tag-cli)
4
5> [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli) is a [VZ](https://vodafoneziggo.com) CLI package that should be used to configure containers and tags when using [@d-cat/tag-manager](https://www.npmjs.com/package/@d-cat/tag-manager).
6
7- [Install](#install)
8- [Usage](#usage)
9 * [Tag Manager commands](#tag-manager-commands)
10 + [`create-tag-manager`](#create-tag-manager)
11 - [What's included](#what-s-included)
12 - [Update depedencies](#update-depedencies)
13 - [Examples](#examples)
14 - [GitLab configuration](#gitlab-configuration)
15 * [CI/CD variables to create in GitLab](#cicd-variables-to-create-in-gitlab)
16 + [`bundle-tag-manager`](#bundle-tag-manager)
17 - [Examples](#examples-1)
18 - [Test the bundle](#test-the-bundle)
19 + [`deploy-test-instance`](#deploy-test-instance)
20 - [Examples](#examples-2)
21 + [`deploy-tag-manager`](#deploy-tag-manager)
22 - [Examples](#examples-3)
23 * [Tag Template Commands](#tag-template-commands)
24 + [`deploy-tag-template`](#deploy-tag-template)
25 - [Examples](#examples-4)
26 + [`update-dependents`](#update-dependents)
27 - [Examples](#examples-5)
28 * [Tag commands](#tag-commands)
29 + [`create-new-tag`](#create-new-tag)
30 - [What's included](#what-s-included-1)
31 - [Dependencies](#dependencies)
32 - [Examples](#examples-6)
33 - [Configuring a tag](#configuring-a-tag)
34 * [Pipeline settings](#pipeline-settings)
35 * [Tag Manager settings](#tag-manager-settings)
36 + [`ITrigger`](#itrigger)
37 - [GitLab configuration](#gitlab-configuration-1)
38 * [CI/CD variables to create in GitLab](#cicd-variables-to-create-in-gitlab-1)
39 * [Troubleshooting](#troubleshooting)
40 + [`test-tag`](#test-tag)
41 - [Examples](#examples-7)
42 + [`lint-tag`](#lint-tag)
43 - [Examples](#examples-8)
44 + [`type-tag`](#type-tag)
45 - [Examples](#examples-9)
46 + [`publish-tag`](#publish-tag)
47 - [Examples](#examples-10)
48 * [Miscellaneous commands](#miscellaneous-commands)
49 + [`bundle-dependencies`](#bundle-dependencies)
50 - [Examples](#examples-11)
51 + [`clean-up`](#clean-up)
52 - [Examples](#examples-12)
53 * [Troubleshooting](#troubleshooting-1)
54
55## Install
56
57```bash
58npm i -D @d-cat/tag-cli
59```
60
61# Usage
62@d-cat/tag-cli is a toolkit to deploy and develop a Tag Manager with Tags using GitLab and Google Cloud Platform.
63___
64
65## Tag Manager commands
66---
67A D-CAT Tag Manager is a collective name for all layers that work together to generate and deploy a working JavaScript bundle of multiple GitLab repositories of a single GitLab Group in a defined Google Cloud Storage Bucket. To effectuate this, we depend on the following:
68
69* [@d-cat/tag-manager](https://www.npmjs.com/package/@d-cat/tag-manager);
70* [@d-cat/tag-cli](https://www.npmjs.com/package/@d-cat/tag-cli);
71* [@d-cat/ddm-core](https://www.npmjs.com/package/@d-cat/ddm-core)
72* [GitLab Group](https://docs.gitlab.com/ee/user/group/);
73* [GitLab Group API](https://docs.gitlab.com/ee/api/groups.html);
74* GitLab Tag Manager Repository in a GitLab Group;
75* More than 0 GitLab Tag Repositories (generated through @d-cat/tag-cli) in a GitLab Group;
76
77![bundle-tag-manager](https://www.plantuml.com/plantuml/png/PP4nRuD038Nt-nLFx205MBf46IfbQQTaYpeud8Ee21Tn9b9LyTzxLYyj5zY-Ppy_czjveL6cQsykhhSy8ZkuAsFVoHkTiH_TTClmRH2QkWir0g6sJh5AiKnnOsRpDpkEVULRxxuUqyd7ECs9dKVsSkY4DokbN2dLIgdD38F_s2ErUAU1MXxrc5DW_w5xDRsRhCRY97Pu2LyXlnLBGcVoZCms93aFzzpoNTruf0M7uiBx6Rp0h7wz74MnHGmBN3vnzSJrakEIAgMxBG5vlatILzNuPysE1niU-GS0)
78
79---
80
81### `create-tag-manager`
82The `create-tag-manager` creates a Tag Manager boilerplate designed to use with @d-cat/tag-cli within GitLab CI/CD. Please make sure you update the e2e and unit tests to suite your needs and match the TMS you want to deploy.
83
84```bash
85Options:
86 --version Show version number [boolean]
87 --help Show help [boolean]
88 --force Create Tag Manager without prompt [boolean]
89```
90
91```bash
92# creates default setup
93npx tag-cli create-tag-manager --force
94
95# prompt questions
96npx tag-cli create-tag-manager --no-force
97```
98
99#### What's included
100The Tag Manager boilerplate contains everything to:
101* unit test the build version of the tag manager
102* e2e test the build version of the tag manager in chrome headless browser
103* deploy test/prod containers in a GCP bucket
104* deploy testable open websites with the TMS running on it for functional testing
105* dockerized TMS to run the TMS locally in isolation
106* dockerized TMS that registers images in GitLab private registery
107* stable pipeline file with artifacts enabled both on success as failure
108* babel/ts for browser compatibility
109
110Some parts of the generated boilerplate can look weird as the pipeline will interpolate varialbes/files/libs and build the full version when running `npx tag-cli bundle-tag-manager`.
111
112> The roadmap is to replace interpolated files with a configuration (json/yml) file to make it more intuitive.
113
114#### Update depedencies
115By default dependencies are fixed in the package-lock.json and package.json files. Updating a package manually will break the pipeline as it runs `npm ci`, thus you have to update both package.json as package-lock.json:
116
117```bash
118npm i yourpackage@1.0.0
119```
120
121#### Examples
122Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
123
124```bash
125# create a new tag folder
126mkdir myTag
127
128cd myTag
129
130# creating a tag manager boilerplate
131npx tag-cli create-tag-manager
132
133# running a tag manager locally in isolation on localhost:8080
134docker build -t ${img_name} .
135docker run --name ${container_name} --rm -p 8080:8080 -ti ${img_name}:latest
136
137# running a tag manager locally in isolation with docker-compose
138docker-compose build bundle
139docker-compose up bundle
140
141# running the full tms pipeline (except deployment in gcp/test sites) locally in isolation
142docker-compose build deploy
143docker-compose up deploy
144```
145
146#### GitLab configuration
147Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
148
149- Create a new GitLab (sub)group with name as Container ID: (i.e. 9999);
150- Create a new project, called Tag Manager;
151- Create CI/CD variables.
152
153##### CI/CD variables to create in GitLab
154
155Before you run the pipeline, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in the GitLab TMS Group.
156
157| CI/CD variable | Type | Description |
158| ----------------------- | :------: | :--------------------------------------------------------------------------------------------------------- |
159| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
160| `CONTAINER_ID` | variable | Group ID that should be queried for tags. |
161| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
162| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
163| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
164| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
165
166---
167
168### `bundle-tag-manager`
169The `bundle-tag-manager` command bundles all tag `artifacts` to eventually transpile and deploy a Tag Manager.
170
171```bash
172Options:
173 --version Show version number [boolean]
174 --help Show help [boolean]
175 --access-token, --token The GitLab personal accesstoken with owner rights. [string]
176 --group-id, --id The GitLab Group ID that should be analyzed. [number]
177 --dir-name, --dir Dir where to store artifacts. [string]
178 --branch-name, --branch The current branch. [string]
179 --job-token, --j Unique token: $CI_PIPELINE_ID. [string]
180 --environment --e Either `development` or `production`. [string]
181```
182
183#### Examples
184Note that all flags are either mandatory or are set as a node environment variable.
185
186```bash
187# the environment variable should be used to trigger
188# the tag managers pipeline from another pipeline or API
189# more at: https://docs.gitlab.com/ee/ci/triggers/#making-use-of-trigger-variables
190
191# gitlab variables to set as env variables
192ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
193GROUP_ID=$GITLAB_GROUP_ID
194
195# build a dev bundle
196# variables used are built-in gitlab env variables
197# note that we use ci_pipeline_id as job_token
198# this token is only used for e2e testing
199npx tag-cli bundle-tag-manager --dir-name lib --branch-name $CI_COMMIT_REF_NAME --job-token $CI_PIPELINE_ID --environment $ENV_VAR_FROM_ANOTHER_PIPELINE
200```
201
202#### Test the bundle
203Instead of running the pipeline from a shared runner in GitLab, you could also go for 2 other options to verify if the built is correct.
204
205* [install a GitLab runner](https://docs.gitlab.com/runner/install/) locally and execute the `bundle` job from a Tag Manager project
206* use Docker within a Tag Manager project:
207
208```bash
209docker build -t $MY_TMS_IMG .
210
211# serve the container on localhost:8080
212docker run --name $MY_CONTAINER_NAME --rm -p 8080:8080 -ti $MY_TMS_IMG:latest
213
214# using docker-compose to only build the build job
215docker-compose build build
216
217# serve the container on localhost:8080
218docker-compose up build
219```
220---
221
222### `deploy-test-instance`
223The `deploy-test-instance` command deploys a build version of the Tag Manager on a private or public website at `https://instances.gitlab.io/[tagmanager_id]/[branchName]`. It can take up to 10 minutes before your test instance is deployed, starting from your push.
224
225Note that his commands looks up the `tdn` folder in the root directory of the repo and searches for the build file of the Tag Manager, typically something like `tdn9999.js`. The corresponding deploy url would be `https://instances.gitlab.io/9999`. The command is meant to run it right after a bundle stage.
226
227> Note that you need access to the instances.gitlab.io group before you can publish to it.
228
229```bash
230Options:
231 --version Show version number [boolean]
232 --help Show help [boolean]
233 --access-token, --token Personal accesstoken with enough rights. [string]
234 --group-id, --id The GitLab Group ID that should be analyzed [string]
235 --branch-name, --n The current branch name: $CI_COMMIT_REF_NAME. [string]
236 --job-token, --j $CI_JOB_TOKEN. [string]
237```
238
239#### Examples
240```bash
241# Personal access token that's needed to authenticate
242ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN
243
244# Job Token generated by GitLab so we can see in the
245# TMS interface that we triggered the pipeline of the instances group
246JOB_TOKEN=$CI_JOB_TOKEN
247
248# The Group ID in which the TMS project is placed
249GROUP_ID=$TMS_GROUP_ID
250
251npx tag-cli deploy-test-instance --branch-name $CI_COMMIT_REF_NAME
252```
253---
254
255### `deploy-tag-manager`
256The deploy tag manager commands deploys the build tag manager to a Google Cloud Bucket and optionally sends a success email to a list of receivers.
257
258```bash
259Options:
260 --version Show version number [boolean]
261 --help Show help [boolean]
262 --bucket-name, -b Name of the Google Cloud Bucket. [string]
263 --key-file-name, -k Google Cloud service key. [string]
264 --group-name, -i $CI_PROJECT_NAMESPACE. [string]
265 --branch-name, -n $CI_COMMIT_REF_NAME. [string]
266 --node-email, -gm Gmail email transporter. [string]
267 --node-pass, -pass Gmail password. [string]
268 --receivers, -list Receivers of mail. [string]
269 --is-empty -e If true deploy empty. [string]
270```
271
272#### Examples
273Note that all flags are either mandatory or are set as an environment variable.
274
275```bash
276# The bucket name of the Google Cloud Bucket
277BUCKET_NAME=$MY_GCP_BUCKET_NAME
278
279# The Key file is your GCP IAM json.
280# make sure it has write rights to the
281# correct bucket only
282KEY_FILE=$MY_KEY_FILE
283
284# The namespace of the gitlab group,
285# we use this to determine wether the TMS id
286# equals the namespace to prevent unexpected overrides
287# of a production container
288# so a GitLab Group called 9999
289# must contain a TMS repo with tdn9999.ts entrypoint.
290GROUP_NAME=$CI_PROJECT_NAMESPACE
291
292# GitLab branch var
293BRANCH_NAME=$CI_COMMIT_REF_NAME
294
295# gmail where we send the mail from
296NODE_EMAIL=$EMAIL_ADDRESS_OF_SENDER
297
298# gmail pass
299NODE_PASS=$EMAIL_PASS
300
301# string with spaces of receiver mails
302RECEIVERS=foo.bar@gmail.com
303
304# You can deploy both an empty TMS (for initial release)
305# or a non-empty.
306
307# deploy empty TMS
308npx tag-cli deploy-tag-manager --is-empty
309
310# deploy non-empty (default)
311npx tag-cli deploy-tag-manager --no-is-empty
312```
313___
314
315## Tag Template Commands
316---
317
318A Tag Template functions as the backbone of a tag. It's a NPM package. It contains critical logic of handling tags logic and returns a class with a set of methods that we can use, inherit and override. Typically a Tag Template contains the following:
319
320* it accepts an initializer object;
321* it notifies the dataLayer that a Tag Template has been initialized;
322* it's a class;
323* it returns a render method;
324* it's an NPM package, starting with: @d-cat/tag-template-;
325* it publishes according NPM semver.
326
327![tag-or-tag-template](https://unpkg.com/@d-cat/tag-cli/assets/tag-or-tag-template.png)
328
329---
330
331### `deploy-tag-template`
332The `deploy-tag-template` command deploys a tag template on a NPM registery of choice. The package version is incremented based on the commits done through i.e. [commitizen](https://www.npmjs.com/package/commitizen). Standard-version is used to publish either a major, minor or patch according to [NPM's semver](https://docs.npmjs.com/misc/semver). A CHANGELOG.md is added or updatet within the repo. Please note that you should only use version 1.0.0 on a stable release. Using version 0.* will behave differently using NPM's semver.
333
334```bash
335Options:
336 --version Show version number [boolean]
337 --help Show help [boolean]
338 --access-token, --token Personal accesstoken. [string]
339 --branch-name, --branch The current branch. [string]
340 --dist-dir, --d Dist dir. Default to `lib`. [string]
341 --is-flat-package NPM flatpackage publish. [boolean]
342 --project-path, --p $CI_PROJECT_PATH. [string]
343 --key, --k SSH Key. [string]
344 --user, -u Git username. [string]
345 --email, -e Git email. [string]
346 --o-auth-token, --oauth NPM authentication file. [object]
347```
348
349#### Examples
350Note that all flags are either mandatory or are set as an environment variable.
351
352```bash
353# Personal access token generated within gitlab
354ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
355
356# SSH key is used to increment the version of the npm package
357# based on the commits done, according to commitizen.
358# standard-version is used to update a major, minor or patch and use
359# NPM's semver.
360KEY=$SSH_KEY
361
362# your git user + email for authentication
363GIT_USER=$GIT_USER_VAR
364GIT_EMAIL=$GIT_EMAIL_VAR
365
366# deploy a flat package to a npm registery
367# dist dir is set to dist, thus the build is placed in dist
368# defined in your package.json
369npx tag-cli deploy-tag-template --is-flat-package --dist-dir dist --branch-name $CI_COMMIT_REF_NAME --project-path $CI_PROJECT_PATH
370
371# deploy a standard npm package
372npx tag-cli deploy-tag-template --no-is-flat-package --branch-name $CI_COMMIT_REF_NAME --project-path $CI_PROJECT_PATH
373```
374
375---
376
377### `update-dependents`
378If not using [npm semver](https://docs.npmjs.com/misc/semver), you can use `update-dependents` to keep track of dependencies. The `update-dependents` command updates and triggers the first `1000` [default branches](https://docs.gitlab.com/ee/user/project/repository/branches/#default-branch) of all GitLab projects that either use the current package as dependency or as devDependency, using the [GitLab API](https://docs.gitlab.com/ce/api/projects.html#list-all-projects). Please note when using `npm ci` this will not impact the package-lock.json and thus you have to update that one manually.
379
380```bash
381# flags
382Options:
383 --version Show version number [boolean]
384 --help Show help [boolean]
385 --access-token, --token Personal accesstoken. [string]
386 --dir-name, --dir The dir name. [string]
387 --project-id, --d $CI_PROJECT_ID. [string]
388 --key, --k SSH Key. [string]
389 --user, -u Git username. [string]
390 --email, -e Git email. [string]
391```
392
393![update-dependents](https://www.plantuml.com/plantuml/png/dT4x3iCW40JGtgT0z3Wo7-WYxX5Hh6pa8X1PoVh-yG7C8hOU7iE8-4FuubdBTC3wXZqB6JUr0ZuGTeMv7WKmgqLEz04jwTnqSjihS9qBV2SFLy7hTbeIIZt5RQRJk34COnd6fSOWIwDXunacj1wdavZd1beQHOPXBCCusj1ev5izmmJQnFpPpbh-)
394
395#### Examples
396Note that all flags are either mandatory or are set as an environment variable:
397
398```bash
399ACCESS_TOKEN=myAccesToken
400DIR_NAME=foo
401PROJECT_ID=1210
402SSH_KEY=key
403GIT_EMAIL=myEmail
404```
405
406```bash
407npx tag-cli update-dependents --user myGitName
408```
409___
410
411## Tag commands
412-------------------
413A Tag is used to initialize a [Tag Template](#tag-template-commands) or to handle a Google Tag Manager's data object. A tag should never contain complex logic. Use a tag template instead. A Tag is easy to read and easy to debug. There should be no complexity in a tag. The following is applicable for a Tag:
414
415* it exports a default function without arguments;
416* it initializes a tag template;
417* it contains a `publish-tag` job;
418* it contains no complexity.
419
420### `create-new-tag`
421The `create-new-tag` command creates a new Tag boilerplate designed to use with @d-cat/tag-cli within GitLab CI/CD.
422
423```bash
424Options:
425 --version Show version number [boolean]
426 --help Show help [boolean]
427 --force Force create of tag [boolean]
428```
429
430#### What's included
431The Tag boilerplate contains all configurations to:
432* Jest setup
433* tslint setup
434* prettier
435* husky
436* tag config file (`tag-cli.json`)
437* dockerized tag environment to run the tag locally in isolation
438* dockerized TMS that registers images in GitLab private registery
439* stable pipeline file with artifacts enabled both on success and failure
440* standard-version to created changelog + semver in the pipeline
441
442#### Dependencies
443By default dependencies are fixed in the package-lock.json and package.json files. Updating a package manually will break the pipeline as it runs `npm ci`, thus you have to update both package.json as package-lock.json:
444
445```bash
446npm i yourpackage@1.0.0
447```
448
449#### Examples
450Make sure docker is installed and you've updated your [.env](https://docs.docker.com/compose/environment-variables/) file.
451
452```bash
453# creating a tag boilerplate
454npx tag-cli create-new-tag --force
455
456# creating a tag boilerplate with prompt
457npx tag-cli create-new-tag --no-force
458
459# running a tag locally in isolation on localhost:1234
460docker build -t ${img_name} .
461docker run --name ${tag_name} --rm -p 1234:1234 ${img_name}:latest
462
463# running a tag locally in isolation with docker-compose
464docker-compose build build
465docker-compose up build
466
467# running the full tag pipeline (except uploading artifacts) locally in isolation
468docker-compose build pipeline
469docker-compose up pipeline
470```
471
472#### Configuring a tag
473The `create-new-tag` command will create a file called `tag-cli.json`. This file contains all configurations. The `tag-cli.json` file includes both `pipeline` as `tag manager` settings.
474
475##### Pipeline settings
476This are settings that indicates how a tag should behave inside a pipeline.
477
478| Prop | Type | Desc |
479| ------------- |:-------------:| :-----|
480| `isPipelineActive` | boolean | Boolean that indicates if the tags pipeline should run.|
481| `pipelineBranches` | string[] | String array of branches that should trigger the Tag's pipeline. |
482| `isImportInTagManager` | boolean | Boolean to indicate if the tag should be imported in the tag manager. |
483| `tagManagerBranches` | string[] | String array of tag branches that should be included in a tag manager bundle. |
484| `isActive` | boolean | Boolean that indicates if the tag is active. |
485| `isTrigger` | boolean | Boolean that indicates if the tag should trigger the Tag Managers pipeline after a publish. |
486
487##### Tag Manager settings
488This are settings that determine how the tag should behave inside the Tag Manager.
489
490| Prop | Type | Desc |
491| ------------- |:-------------:| :-----|
492| `firingAmount` | number | Amount a tag should be invoked when all business rules apply. |
493| `priority` | number | Priority of tag. 1 is highest priority. |
494| `id` | string | UUID. |
495| `urls` | IUrl[] | Object Array that contains 2 props: `url` (RegExp) and `reverse` (boolean). |
496| `triggers` | ITrigger[] | Boolean that indicates if the tag is active. |
497
498###### `ITrigger`
499
500| Options | Type | Required Description |
501| --------- | :-----: | :------ |:---- |
502| `type` | string | true | Type of the trigger, this must be one of the following: `instantly`, `datalayer`, `event`, `domEvent`, `persisted`. Note that when using `instantly`, this means the other triggers automatically are ignored, thus the tag will execute immediately. |
503| `id` | string | true | Uniquely generated ID. Using the CLI this will generate an ID using [uuid/v1](https://www.npmjs.com/package/uuid). |
504| `name` | string | false | Depending on the type, the name key has a different function. |
505| `value` | string | false | Depending on the type, the value key has a different function. |
506| `reverse` | boolean | false | Reverse the match on either value or name. |
507| `element` | string | false | `window`, `document` both as string or an element ID. |
508
509#### GitLab configuration
510Make sure you did all necessary steps to [start with GitLab](https://docs.gitlab.com/ee/gitlab-basics/).
511
512
513##### CI/CD variables to create in GitLab
514Before you run the pipeline, make sure you [create the necessary CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) in your GitLab Tag project.
515
516| CI/CD variable | Type | Description |
517| ----------------------- | :------: | :----- |
518| `PERSONAL_ACCESS_TOKEN` | variable | Your personal access token, that has owner rights of the tags group. |
519| `TAG_MANAGER_ID` | variable | Gitlab Project ID of the Tag Manager. |
520| `GCLOUD_SERVICE_KEY` | file | Your [authentication file](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud. |
521| `SSH_KEY` | file | Your SSH key to clone and push repo's of GitLab. |
522| `GIT_USER_EMAIL` | variable | Your git email: `git config user.email`. |
523| `GIT_USER_NAME` | variable | Your git user name: `git config user.name`. |
524| `CODECOV_TOKEN` | variable | Your Codecov token to publish code coverage reports. |
525
526##### Troubleshooting
527> If the pipeline isn't running after the initial commit, trigger the pipeline manually.
528
529---
530
531### `test-tag`
532The `test-tag` command runs the test script as defined in your package.json and uploads a codecoverage report to [Codecov](https://codecov.io/).
533
534```bash
535Options:
536 --version Show version number [boolean]
537 --help Show help [boolean]
538 --codecov, -c CodeCov token [string]
539 --branch-name, --n $CI_COMMIT_REF_NAME [string]
540```
541
542#### Examples
543Note that all flags are either mandatory or are set as an environment variable.
544
545```bash
546# secret codecov token generated in the codecov interface
547CODE_COV_TOKEN=$MY_CODE_COV_TOKEN
548
549# run tests + upload report to codecov
550npx tag-cli test-tag --branch-name $CI_COMMIT_REF_NAME
551```
552
553---
554
555### `lint-tag`
556The `lint-tag` command runs the [TypeScript linter](https://palantir.github.io/tslint/).
557
558```bash
559Options:
560 --version Show version number [boolean]
561 --help Show help [boolean]
562 --branch-name, --n $CI_COMMIT_REF_NAME. [string]
563```
564
565#### Examples
566
567```bash
568npx tag-cli lint-tag --branch-name $CI_COMMIT_REF_NAME
569```
570
571---
572
573### `type-tag`
574The `type-tag` command runs type checks the tag according TypeScript specs.
575
576```bash
577Options:
578 --version Show version number [boolean]
579 --help Show help [boolean]
580 --branch-name, --n $CI_COMMIT_REF_NAME. [string]
581```
582
583#### Examples
584
585```bash
586npx tag-cli type-tag --branch-name $CI_COMMIT_REF_NAME
587```
588
589---
590
591### `publish-tag`
592The `publish-tag` command publishes tag artifacts in GitLab, increments the tag version and additionally triggers the Tag Managers pipeline to deploy a new version. The artifacts you publised can be fetched using [GitLab's API](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#downloading-the-latest-artifacts). Both incrementing the version as triggering the Tag Managers API are optional. However, triggering the Tag Managers pipeline is configured in the `tag-cli.json`.
593
594```bash
595Options:
596 --version Show version number [boolean]
597 --help Show help [boolean]
598 --job-token, -j Unique token. [string]
599 --access-token, -t Access token. [string]
600 --tag-manager-id, -i GitLab\'s Tag Manager project ID. [string]
601 --key, -k SSH Key. [string]
602 --user, -u Git username. [string]
603 --email, -e Git email. [string]
604 --increment-version Update using semver. [boolean]
605```
606
607#### Examples
608Note that all flags are either mandatory or are set as an environment variable.
609
610```bash
611# Personal access token generated within gitlab
612ACCESS_TOKEN=$MY_PERSONAL_ACCESS_TOKEN
613
614# SSH key is used to increment the version of the npm package
615# based on the commits done, according to commitizen.
616# standard-version is used to update a major, minor or patch and use
617# NPM's semver.
618KEY=$SSH_KEY
619
620# your git user + email for authentication
621GIT_USER=$GIT_USER_VAR
622GIT_EMAIL=$GIT_EMAIL_VAR
623
624# we need the job token to trigger the tag managers pipeline
625# using the job token will show the tag managers pipeline
626# to be triggered in GitLabs interface, and in the TMS
627# project it shows our tag defined as the triggerer
628JOB_TOKEN=$CI_JOB_TOKEN
629
630# set a gitlab variable where the project id
631# of the tag manager is saved
632TAG_MANAGER_ID=$TAG_MANAGER_PROJECT_ID
633
634# incrementing version
635npx tag-cli publish-tag --increment-version
636
637# do not increment version
638npx tag-cli publish-tag --no-increment-version
639```
640
641---
642
643## Miscellaneous commands
644-------------------
645Other commands.
646
647---
648
649### `bundle-dependencies`
650The `bundle-dependencies` command bundles the contents of all third party endpoints in `tms.dependencies.json` and writes the bundle to `3rd-party-dependencies.js` or another specified output file.
651
652```bash
653Options:
654 --version Show version number [boolean]
655 --help Show help [boolean]
656 --bucketName -b GCP Bucket Name [string]
657 --input -i Name of the input file [string]
658 --is-uglify -iu Should uglify mangle props [boolean]
659 --output -o Name of the output file [string]
660 --key-file-name -k Service file from GCP [object]
661 --tms-id -id Associated TMS ID [number]
662
663```
664
665#### Examples
666```bash
667npx tag-cli bundle-dependencies --output dependencies.js
668```
669
670#### `tms.dependencies.json`
671The tms.dependencies.json holds an array with objects.
672
673| Prop | Type | Desc |
674| ------------- |:-------------:| :-----|
675| `prepend` | string | A JS snippet placed in front of the SDK.|
676| `endpoint` | string | The endpoint of the SDK, same as binary. |
677| `binary` | string | The endpoint of the SDK, same as endpoint. |
678| `trigger` | string | Event that will be emitted into [DDM's](https://www.npmjs.com/package/@d-cat/digital-data-manager) event emitter, after the SDK is loaded. |
679| `wrapper` | string | An optional special prop is called wrapper. This prop is meant to wrap or add some code in front or behind the SDK. The wrapper prop must contain a `{{CODE}}` string, as that's the place where the SDK will be interpolated. |
680
681```json
682[
683 {
684 "endpoint": "https://www.googletagmanager.com/gtm.js?id=GTM-1234567",
685 "prepend": "window.dataLayer=window.dataLayer||[];window.dataLayer.push({'gtm.start':new Date().getTime(),event:'gtm.js'}",
686 "trigger": "3rd.gtm.loaded"
687 },
688 {
689 "binary": "//snap.licdn.com/li.lms-analytics/insight.min.js",
690 "prepend": "_linkedin_data_partner_id = '234089'",
691 "trigger": "3rd.linkedin.loaded",
692 "wrapper": "var handler = function() {if (_ddm.get('user.cookieConsent') === 2){ {{CODE}} }}; _ddm.listen('user.cookie.accept', handler);handler();"
693 }
694]
695```
696
697The place of `{{CODE}}` in the wrapper vaue will be interpolated with the SDK snippet.
698
699---
700
701
702### `clean-up`
703The `clean-up` command fetches all pipelines from the given project id and analyzes all it's jobs for artifacts. If an artifact found, it will be removed.
704
705> Try to always set a `expire_in` variable for artifacts.
706
707```bash
708Options:
709 --version Show version number [boolean]
710 --help Show help [boolean]
711 --project-id, -i The current project ID: $CI_PROJECT_ID. [string]
712 --access-token, -t Access token. [string]
713 --stage, -s Name of the job\'s stage. Default "build". [string]
714```
715
716#### Examples
717Note that all flags are either mandatory or are set as an environment variable.
718
719```bash
720npx tag-cli clean-up --project-id $CI_PROJECT_ID --access-token 1234
721```
722
723___
724
725## Troubleshooting
726- `Publishing tag TypeError: Cannot read property 'map' of undefined`: make sure your `tag-cli.json` has an string array of both `branchesToImportInTagManager` and `branchesToRunInPipeline`.
727- `Publishing tag This tag didn't triggered the pipeline.`: Make sure the branch that triggered the pipeline equals a branch that is whitelisted in your `tag-cli.json`.
728- `GitLab API: Fetching projects. Unexpected response received from GitLab: [object Object], or the amount of received projects meets the maximum of 1000. Received: undefined` : Retry the pipeline, as the GitLab API didn't returned a correct response. It has probably something to do with a connection lost / timeout.
\No newline at end of file