@snowplow/snowtype 0.1.1 → 0.2.0
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/dist/index.js +35 -10
- package/package.json +14 -8
- package/dist/api/ConsoleAPI.js +0 -60
- package/dist/api/fetchIgluCentralSchema.js +0 -11
- package/dist/api/index.js +0 -18
- package/dist/command-utils/index.js +0 -121
- package/dist/commands/actions/constants.js +0 -53
- package/dist/commands/actions/dispatch.js +0 -30
- package/dist/commands/actions/generate.js +0 -59
- package/dist/commands/actions/index.js +0 -11
- package/dist/commands/actions/init.js +0 -153
- package/dist/commands/actions/patch.js +0 -45
- package/dist/commands/actions/types.js +0 -19
- package/dist/commands/actions/update.js +0 -76
- package/dist/commands/actions/utils/index.js +0 -213
- package/dist/commands/actions/utils/ui.js +0 -110
- package/dist/commands/index.js +0 -92
- package/dist/commands/logger/index.js +0 -43
- package/dist/config/index.js +0 -5
- package/dist/config/schema.js +0 -52
- package/dist/errors/index.js +0 -82
- package/dist/utils/index.js +0 -24
- package/dist/version.js +0 -4
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initAction = void 0;
|
|
4
|
-
const prompts_1 = require("@inquirer/prompts");
|
|
5
|
-
const errors_1 = require("../../errors");
|
|
6
|
-
const api_1 = require("../../api");
|
|
7
|
-
const config_1 = require("../../config");
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const types_1 = require("./types");
|
|
11
|
-
const dispatch_1 = require("./dispatch");
|
|
12
|
-
const initPrompts = [
|
|
13
|
-
{
|
|
14
|
-
type: "password",
|
|
15
|
-
message: "Enter your Snowplow organization ID:",
|
|
16
|
-
mask: true,
|
|
17
|
-
validate: utils_1.isNonEmpty,
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
type: "select",
|
|
21
|
-
message: "Select the Snowplow Tracker to use:",
|
|
22
|
-
choices: [
|
|
23
|
-
{
|
|
24
|
-
value: "@snowplow/javascript-tracker",
|
|
25
|
-
name: "JavaScript Tracker",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
value: "@snowplow/browser-tracker",
|
|
29
|
-
name: "Browser Tracker",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
value: "@snowplow/node-tracker",
|
|
33
|
-
name: "Node Tracker",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
value: "snowplow-android-tracker",
|
|
37
|
-
name: "Android Tracker",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
value: "snowplow-ios-tracker",
|
|
41
|
-
name: "iOS Tracker",
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
value: "snowplow-golang-tracker",
|
|
45
|
-
name: "Golang Tracker",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
// placeholder
|
|
51
|
-
type: "select",
|
|
52
|
-
message: "Select the language to use:",
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
type: "input",
|
|
56
|
-
message: "Enter the directory for Snowtype output:",
|
|
57
|
-
default: "./snowtype",
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
const defaultOptions = {
|
|
61
|
-
organizationId: "",
|
|
62
|
-
tracker: "",
|
|
63
|
-
language: "",
|
|
64
|
-
outpath: "",
|
|
65
|
-
};
|
|
66
|
-
function getOrAsk(key, opts, inquire, override = "") {
|
|
67
|
-
if (override) {
|
|
68
|
-
return Promise.resolve(override);
|
|
69
|
-
}
|
|
70
|
-
// @ts-expect-error index signature
|
|
71
|
-
if (Object.prototype.hasOwnProperty.call(opts, key) && opts[key] != null) {
|
|
72
|
-
// @ts-expect-error index signature
|
|
73
|
-
const provided = opts[key];
|
|
74
|
-
if (typeof provided === "string") {
|
|
75
|
-
return Promise.resolve(provided);
|
|
76
|
-
}
|
|
77
|
-
throw new errors_1.SnowtypeInternalError("Invalid default options.");
|
|
78
|
-
}
|
|
79
|
-
if ((0, types_1.isInputPrompt)(inquire)) {
|
|
80
|
-
return (0, prompts_1.input)(inquire);
|
|
81
|
-
}
|
|
82
|
-
if ((0, types_1.isPasswordPrompt)(inquire)) {
|
|
83
|
-
return (0, prompts_1.password)(inquire);
|
|
84
|
-
}
|
|
85
|
-
if ((0, types_1.isSelectPrompt)(inquire)) {
|
|
86
|
-
return (0, prompts_1.select)(inquire);
|
|
87
|
-
}
|
|
88
|
-
throw new errors_1.SnowtypeInternalError("Unknown Prompt inquired.");
|
|
89
|
-
}
|
|
90
|
-
function mkChoices(languages, prompt) {
|
|
91
|
-
if ((0, types_1.isSelectPrompt)(prompt)) {
|
|
92
|
-
prompt.choices = languages;
|
|
93
|
-
}
|
|
94
|
-
return prompt;
|
|
95
|
-
}
|
|
96
|
-
async function checkInitOptions(options, logger) {
|
|
97
|
-
const initOptions = { ...defaultOptions };
|
|
98
|
-
logger.debug("Checking for existing configuration file..");
|
|
99
|
-
(0, utils_1.guardConfigNotExistsValid)();
|
|
100
|
-
const orgId = await getOrAsk("organizationId", options, initPrompts[0]);
|
|
101
|
-
initOptions.organizationId = orgId;
|
|
102
|
-
const tracker = await getOrAsk("tracker", options, initPrompts[1]);
|
|
103
|
-
if (!(0, utils_1.isValidTracker)(tracker)) {
|
|
104
|
-
throw new errors_1.SnowtypeOptionError("tracker", tracker);
|
|
105
|
-
}
|
|
106
|
-
initOptions.tracker = tracker;
|
|
107
|
-
const langs = constants_1.TRACKER_LANGUAGES[tracker];
|
|
108
|
-
if (!Array.isArray(langs) || langs.length === 0) {
|
|
109
|
-
throw new errors_1.SnowtypeInternalError("Missing language entry.");
|
|
110
|
-
}
|
|
111
|
-
let language;
|
|
112
|
-
if (langs.length === 1) {
|
|
113
|
-
const languageSelection = langs[0];
|
|
114
|
-
if (typeof languageSelection === "undefined") {
|
|
115
|
-
throw new errors_1.SnowtypeInternalError("Missing language.");
|
|
116
|
-
}
|
|
117
|
-
language = await getOrAsk("language", options, initPrompts[2], languageSelection.value);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
language = await getOrAsk("language", options, mkChoices(langs, initPrompts[2]));
|
|
121
|
-
}
|
|
122
|
-
if (!(0, utils_1.isValidLanguage)(initOptions.tracker, language)) {
|
|
123
|
-
throw new errors_1.SnowtypeOptionError("language", language);
|
|
124
|
-
}
|
|
125
|
-
initOptions.language = language;
|
|
126
|
-
const outpath = await getOrAsk("outpath", options, initPrompts[3]);
|
|
127
|
-
initOptions.outpath = outpath;
|
|
128
|
-
logger.debug("Assempling initialization options..");
|
|
129
|
-
return initOptions;
|
|
130
|
-
}
|
|
131
|
-
async function execInit(apiKey, logger, spinner, options) {
|
|
132
|
-
const initOpts = await checkInitOptions(options, logger);
|
|
133
|
-
spinner.setSpinnerTitle("Initialising...");
|
|
134
|
-
if (spinner.isSpinning() === false) {
|
|
135
|
-
spinner.start();
|
|
136
|
-
}
|
|
137
|
-
logger.debug("Creating configuration with options: ".concat(JSON.stringify(initOpts)));
|
|
138
|
-
const config = (0, utils_1.completeInitConfig)(initOpts);
|
|
139
|
-
// @ts-expect-error fix
|
|
140
|
-
(0, config_1.validateConfig)(config);
|
|
141
|
-
const consoleApi = new api_1.ConsoleAPI({
|
|
142
|
-
apiKey,
|
|
143
|
-
organizationId: config.organizationId,
|
|
144
|
-
});
|
|
145
|
-
const isAuthenticated = await consoleApi.authenticate();
|
|
146
|
-
if (!isAuthenticated) {
|
|
147
|
-
throw new errors_1.SnowtypeAuthError();
|
|
148
|
-
}
|
|
149
|
-
logger.success("Authentication succeeded");
|
|
150
|
-
(0, utils_1.writeConfigToFile)(config);
|
|
151
|
-
logger.success("Configuration created");
|
|
152
|
-
}
|
|
153
|
-
exports.initAction = (0, dispatch_1.act)(execInit);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchAction = void 0;
|
|
4
|
-
const command_utils_1 = require("../../command-utils");
|
|
5
|
-
const errors_1 = require("../../errors");
|
|
6
|
-
const generate_1 = require("./generate");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
const dispatch_1 = require("./dispatch");
|
|
9
|
-
const defaultOptions = {
|
|
10
|
-
trackingScenarioIds: [],
|
|
11
|
-
dataStructures: [],
|
|
12
|
-
igluCentralSchemas: [],
|
|
13
|
-
yes: false
|
|
14
|
-
};
|
|
15
|
-
function checkPatchOptions(options, logger) {
|
|
16
|
-
const patchOptions = { ...defaultOptions, ...options };
|
|
17
|
-
if (Object.values(patchOptions).every((v) => typeof v === 'boolean' || v.length === 0)) {
|
|
18
|
-
throw new errors_1.SnowtypeMissingOptionsError();
|
|
19
|
-
}
|
|
20
|
-
logger.debug("Checking for existing configuration..");
|
|
21
|
-
(0, utils_1.guardConfigExistsValid)();
|
|
22
|
-
logger.success("Valid configuration found");
|
|
23
|
-
return patchOptions;
|
|
24
|
-
}
|
|
25
|
-
function execPatch(apiKey, logger, spinner, options) {
|
|
26
|
-
const patchOptions = checkPatchOptions(options, logger);
|
|
27
|
-
logger.debug("Starting patch process with options: ".concat(JSON.stringify(patchOptions)));
|
|
28
|
-
const patchEntries = Object.entries(patchOptions);
|
|
29
|
-
patchEntries.forEach(([key, value]) => {
|
|
30
|
-
if (key !== "yes" && Array.isArray(value) && value.length !== 0) {
|
|
31
|
-
value.forEach((element) => {
|
|
32
|
-
(0, command_utils_1.addConfigAttribute)(key, element);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
logger.success("Configuration patched");
|
|
37
|
-
if (patchOptions.yes === true) {
|
|
38
|
-
return (0, generate_1.execGenerate)(apiKey, logger, spinner);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
logger.log("Code is not generated yet for the patched configuration");
|
|
42
|
-
}
|
|
43
|
-
return Promise.resolve(undefined);
|
|
44
|
-
}
|
|
45
|
-
exports.patchAction = (0, dispatch_1.act)(execPatch);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSelectPrompt = exports.isConfirmPrompt = exports.isPasswordPrompt = exports.isInputPrompt = void 0;
|
|
4
|
-
function isInputPrompt(p) {
|
|
5
|
-
return p.type === 'input';
|
|
6
|
-
}
|
|
7
|
-
exports.isInputPrompt = isInputPrompt;
|
|
8
|
-
function isPasswordPrompt(p) {
|
|
9
|
-
return p.type === 'password';
|
|
10
|
-
}
|
|
11
|
-
exports.isPasswordPrompt = isPasswordPrompt;
|
|
12
|
-
function isConfirmPrompt(p) {
|
|
13
|
-
return p.type === 'confirm';
|
|
14
|
-
}
|
|
15
|
-
exports.isConfirmPrompt = isConfirmPrompt;
|
|
16
|
-
function isSelectPrompt(p) {
|
|
17
|
-
return p.type === 'select';
|
|
18
|
-
}
|
|
19
|
-
exports.isSelectPrompt = isSelectPrompt;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateAction = void 0;
|
|
4
|
-
const process_1 = require("process");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const api_1 = require("../../api");
|
|
7
|
-
const command_utils_1 = require("../../command-utils");
|
|
8
|
-
const errors_1 = require("../../errors");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
|
-
const generate_1 = require("./generate");
|
|
12
|
-
const dispatch_1 = require("./dispatch");
|
|
13
|
-
const defaultOptions = {
|
|
14
|
-
yes: false
|
|
15
|
-
};
|
|
16
|
-
function checkUpdateOptions(options, logger) {
|
|
17
|
-
// check**Updates
|
|
18
|
-
// says if/diff available update
|
|
19
|
-
// if not force (just show)
|
|
20
|
-
// if force .. generate
|
|
21
|
-
const updateOptions = { ...defaultOptions, ...options };
|
|
22
|
-
logger.debug("Checking for existing configuration..");
|
|
23
|
-
(0, utils_1.guardConfigExistsValid)();
|
|
24
|
-
logger.success("Valid configuration found");
|
|
25
|
-
return updateOptions;
|
|
26
|
-
}
|
|
27
|
-
async function execUpdate(apiKey, logger, spinner, options) {
|
|
28
|
-
const updateOptions = checkUpdateOptions(options, logger);
|
|
29
|
-
logger.debug("Starting update process with options: ".concat(JSON.stringify(updateOptions)));
|
|
30
|
-
// guarded config exists and valid
|
|
31
|
-
const config = (0, utils_1.getConfig)();
|
|
32
|
-
const lockPath = (0, path_1.resolve)((0, process_1.cwd)(), config.outpath, constants_1.DEFAULT_STORAGE_FILENAME);
|
|
33
|
-
const api = new api_1.ConsoleAPI({
|
|
34
|
-
apiKey,
|
|
35
|
-
organizationId: config.organizationId,
|
|
36
|
-
});
|
|
37
|
-
spinner.setSpinnerTitle("Checking for updates...");
|
|
38
|
-
if (spinner.isSpinning() === false) {
|
|
39
|
-
spinner.start();
|
|
40
|
-
}
|
|
41
|
-
let tsUpdates = {};
|
|
42
|
-
if (!(0, utils_1.fileExists)(lockPath) && config.trackingScenarioIds.length) {
|
|
43
|
-
throw new errors_1.SnowtypeMissingLockError();
|
|
44
|
-
}
|
|
45
|
-
else if ((0, utils_1.fileExists)(lockPath) && config.trackingScenarioIds.length) {
|
|
46
|
-
const latestGenerationConfig = (0, utils_1.getSnowtypeLock)(lockPath);
|
|
47
|
-
tsUpdates = (await (0, command_utils_1.checkScenarioUpdates)(api, config.trackingScenarioIds, latestGenerationConfig));
|
|
48
|
-
}
|
|
49
|
-
const dsUpdates = await (0, command_utils_1.checkDataStructureUpdates)(api, config.dataStructures);
|
|
50
|
-
const dsToUpdate = dsUpdates.filter((upd) => upd.previous !== upd.next);
|
|
51
|
-
const update = Object.entries(tsUpdates).length > 0 || dsToUpdate.length > 0;
|
|
52
|
-
if (update === true) {
|
|
53
|
-
logger.success("Available updates found!");
|
|
54
|
-
(0, utils_1.presentAvailableUpdates)(tsUpdates, dsToUpdate, logger);
|
|
55
|
-
if (updateOptions.yes === true) {
|
|
56
|
-
if (dsToUpdate.length > 0) {
|
|
57
|
-
dsToUpdate.forEach((upd) => {
|
|
58
|
-
const idx = config.dataStructures.indexOf(upd.previous);
|
|
59
|
-
config.dataStructures[idx] = upd.next;
|
|
60
|
-
});
|
|
61
|
-
(0, utils_1.writeConfigToFile)(config);
|
|
62
|
-
}
|
|
63
|
-
logger.debug("Applying the updates..");
|
|
64
|
-
return (0, generate_1.execGenerate)(apiKey, logger, spinner);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
logger.log("No updates applied");
|
|
68
|
-
logger.log("To apply the available updates run update with --yes flag");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
logger.success("No updates found. Everything is up-to-date!");
|
|
73
|
-
}
|
|
74
|
-
return Promise.resolve(undefined);
|
|
75
|
-
}
|
|
76
|
-
exports.updateAction = (0, dispatch_1.act)(execUpdate);
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.isEmpty = exports.getGlobalOptions = exports.presentAvailableUpdates = exports.mkDataStructures = exports.mkIgluSchemas = exports.writeLockFile = exports.mkDataProducts = exports.getExtension = exports.guardConfigNotExistsValid = exports.guardConfigExistsValid = exports.getSnowtypeLock = exports.getConfig = exports.readFile = exports.fileExists = exports.writeConfigToFile = exports.completeInitConfig = exports.isValidLanguage = exports.isValidTracker = exports.isNonEmpty = void 0;
|
|
18
|
-
const process_1 = require("process");
|
|
19
|
-
const path_1 = require("path");
|
|
20
|
-
const fs_1 = require("fs");
|
|
21
|
-
const api_1 = require("../../../api");
|
|
22
|
-
const errors_1 = require("../../../errors");
|
|
23
|
-
const constants_1 = require("../constants");
|
|
24
|
-
const config_1 = require("../../../config");
|
|
25
|
-
__exportStar(require("./ui"), exports);
|
|
26
|
-
const validTrackers = { ...constants_1.TRACKER_LANGUAGES };
|
|
27
|
-
const defaultConfigPath = `./${constants_1.DEFAULT_CONFIG_NAME}`;
|
|
28
|
-
function isNonEmpty(str) {
|
|
29
|
-
return str.length !== 0;
|
|
30
|
-
}
|
|
31
|
-
exports.isNonEmpty = isNonEmpty;
|
|
32
|
-
function isValidTracker(tracker) {
|
|
33
|
-
return Array.isArray(validTrackers[tracker]);
|
|
34
|
-
}
|
|
35
|
-
exports.isValidTracker = isValidTracker;
|
|
36
|
-
function isValidLanguage(tracker, language) {
|
|
37
|
-
const validLangChoices = validTrackers[tracker];
|
|
38
|
-
if (!Array.isArray(validLangChoices)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const validLangs = validLangChoices.map((l) => l.value);
|
|
42
|
-
return !!validLangs.includes(language);
|
|
43
|
-
}
|
|
44
|
-
exports.isValidLanguage = isValidLanguage;
|
|
45
|
-
function completeInitConfig(initOpts) {
|
|
46
|
-
const initOptions = {
|
|
47
|
-
organizationId: initOpts.organizationId,
|
|
48
|
-
tracker: initOpts.tracker,
|
|
49
|
-
language: initOpts.language,
|
|
50
|
-
outpath: initOpts.outpath,
|
|
51
|
-
};
|
|
52
|
-
const initOmitted = {
|
|
53
|
-
igluCentralSchemas: [],
|
|
54
|
-
dataStructures: [],
|
|
55
|
-
trackingScenarioIds: [],
|
|
56
|
-
};
|
|
57
|
-
return Object.assign(initOmitted, initOptions);
|
|
58
|
-
}
|
|
59
|
-
exports.completeInitConfig = completeInitConfig;
|
|
60
|
-
function writeConfigToFile(config) {
|
|
61
|
-
const resolvedPath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
|
|
62
|
-
return (0, fs_1.writeFileSync)(resolvedPath, JSON.stringify(config, null, 2));
|
|
63
|
-
}
|
|
64
|
-
exports.writeConfigToFile = writeConfigToFile;
|
|
65
|
-
function fileExists(path) {
|
|
66
|
-
const stat = (0, fs_1.statSync)(path, { throwIfNoEntry: false });
|
|
67
|
-
if (stat === undefined) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return stat.isFile();
|
|
71
|
-
}
|
|
72
|
-
exports.fileExists = fileExists;
|
|
73
|
-
function readFile(path) {
|
|
74
|
-
return (0, fs_1.readFileSync)(path, { encoding: "utf-8" });
|
|
75
|
-
}
|
|
76
|
-
exports.readFile = readFile;
|
|
77
|
-
function getConfig() {
|
|
78
|
-
const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
|
|
79
|
-
return JSON.parse(readFile(truePath));
|
|
80
|
-
}
|
|
81
|
-
exports.getConfig = getConfig;
|
|
82
|
-
function getSnowtypeLock(path) {
|
|
83
|
-
return JSON.parse(readFile(path));
|
|
84
|
-
}
|
|
85
|
-
exports.getSnowtypeLock = getSnowtypeLock;
|
|
86
|
-
function guardConfigExistsValid() {
|
|
87
|
-
const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
|
|
88
|
-
if (fileExists(truePath) === false) {
|
|
89
|
-
throw new errors_1.SnowtypeConfigMissingError();
|
|
90
|
-
}
|
|
91
|
-
const cfg = JSON.parse(readFile(truePath));
|
|
92
|
-
return (0, config_1.validateConfig)(cfg);
|
|
93
|
-
}
|
|
94
|
-
exports.guardConfigExistsValid = guardConfigExistsValid;
|
|
95
|
-
function guardConfigNotExistsValid() {
|
|
96
|
-
const truePath = (0, path_1.resolve)((0, process_1.cwd)(), defaultConfigPath);
|
|
97
|
-
if (fileExists(truePath) === true) {
|
|
98
|
-
const cfg = readFile(truePath);
|
|
99
|
-
try {
|
|
100
|
-
(0, config_1.validateConfig)(JSON.parse(cfg));
|
|
101
|
-
// if we are here, means a valid config exists already, so guard fails
|
|
102
|
-
throw new errors_1.SnowtypeConfigExistsError();
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
// if we caught what we just thrown
|
|
106
|
-
if (err instanceof errors_1.SnowtypeConfigExistsError) {
|
|
107
|
-
throw err;
|
|
108
|
-
}
|
|
109
|
-
// else means invalid config exists, so guard proceeds ok
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
exports.guardConfigNotExistsValid = guardConfigNotExistsValid;
|
|
115
|
-
function getExtension(langId) {
|
|
116
|
-
const langExtMap = {
|
|
117
|
-
javascript: ".js",
|
|
118
|
-
typescript: ".ts",
|
|
119
|
-
kotlin: ".kt",
|
|
120
|
-
swift: ".swift",
|
|
121
|
-
go: ".go",
|
|
122
|
-
};
|
|
123
|
-
return langExtMap[langId] || "";
|
|
124
|
-
}
|
|
125
|
-
exports.getExtension = getExtension;
|
|
126
|
-
async function mkDataProducts(api, scenarios) {
|
|
127
|
-
const dataProducts = [];
|
|
128
|
-
for (const scenarioId of scenarios) {
|
|
129
|
-
const scenario = await api.fetchTrackingScenario({ scenarioId });
|
|
130
|
-
const scenarioName = scenario.data[0]?.name;
|
|
131
|
-
const scenarioVersion = scenario.data[0]?.version;
|
|
132
|
-
const event = scenario.data[0]?.event;
|
|
133
|
-
const eventSchema = await api.fetchSchemaVersion({
|
|
134
|
-
schema: event?.source || "",
|
|
135
|
-
});
|
|
136
|
-
const entitiesSchemas = [];
|
|
137
|
-
const entitySchemasToFetch = [];
|
|
138
|
-
scenario.data[0]?.entities?.tracked?.forEach((entity) => entitySchemasToFetch.push(entity.source));
|
|
139
|
-
await Promise.all(entitySchemasToFetch.map(async (schemaUrl) => {
|
|
140
|
-
const entitySchema = await api.fetchSchemaVersion({
|
|
141
|
-
schema: schemaUrl,
|
|
142
|
-
});
|
|
143
|
-
entitiesSchemas.push(entitySchema);
|
|
144
|
-
}));
|
|
145
|
-
dataProducts.push({
|
|
146
|
-
scenario: { name: scenarioName || "", id: scenarioId },
|
|
147
|
-
version: scenarioVersion || 0,
|
|
148
|
-
eventSchema,
|
|
149
|
-
entitiesSchemas,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return dataProducts;
|
|
153
|
-
}
|
|
154
|
-
exports.mkDataProducts = mkDataProducts;
|
|
155
|
-
function writeLockFile(dataProducts, outpath) {
|
|
156
|
-
const storage = {
|
|
157
|
-
trackingScenarios: {},
|
|
158
|
-
};
|
|
159
|
-
dataProducts.forEach((dp) => {
|
|
160
|
-
storage.trackingScenarios[dp.scenario.id] = dp.version;
|
|
161
|
-
});
|
|
162
|
-
const truePath = (0, path_1.resolve)((0, process_1.cwd)(), outpath, constants_1.DEFAULT_STORAGE_FILENAME);
|
|
163
|
-
try {
|
|
164
|
-
(0, fs_1.writeFileSync)(truePath, JSON.stringify(storage, null, 2));
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
throw new errors_1.SnowtypeWriteLockError();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.writeLockFile = writeLockFile;
|
|
171
|
-
async function mkIgluSchemas(igluSchemas) {
|
|
172
|
-
const igluCentralSchemas = await Promise.all(igluSchemas.map(async (schemaUrl) => JSON.parse(await (0, api_1.fetchIgluCentralSchema)({ schema: schemaUrl }))));
|
|
173
|
-
return igluCentralSchemas;
|
|
174
|
-
}
|
|
175
|
-
exports.mkIgluSchemas = mkIgluSchemas;
|
|
176
|
-
async function mkDataStructures(api, dsa) {
|
|
177
|
-
const dataStructureSchemas = await Promise.all(dsa.map((dataStructureUrl) => api.fetchSchemaVersion({ schema: dataStructureUrl })));
|
|
178
|
-
return dataStructureSchemas;
|
|
179
|
-
}
|
|
180
|
-
exports.mkDataStructures = mkDataStructures;
|
|
181
|
-
function presentAvailableUpdates(tsUpdates, dsUpdates, logger) {
|
|
182
|
-
const tsUpdatesEntries = Object.entries(tsUpdates);
|
|
183
|
-
if (tsUpdatesEntries.length > 0) {
|
|
184
|
-
logger.success("Available Tracking Scenario Updates");
|
|
185
|
-
}
|
|
186
|
-
tsUpdatesEntries.forEach(([key, value]) => {
|
|
187
|
-
const current = `${key}: version ${value.previous}`;
|
|
188
|
-
const next = `${key}: version ${value.next}`;
|
|
189
|
-
logger.diff(current, next);
|
|
190
|
-
});
|
|
191
|
-
if (dsUpdates.length > 0) {
|
|
192
|
-
logger.success("Available Data Structures Updates");
|
|
193
|
-
}
|
|
194
|
-
dsUpdates.forEach((schemaUpdate) => {
|
|
195
|
-
const current = `${schemaUpdate.previous}`;
|
|
196
|
-
const next = `${schemaUpdate.next}`;
|
|
197
|
-
logger.diff(current, next);
|
|
198
|
-
});
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
exports.presentAvailableUpdates = presentAvailableUpdates;
|
|
202
|
-
function getGlobalOptions(cmd) {
|
|
203
|
-
const cmdGlobals = cmd.optsWithGlobals();
|
|
204
|
-
return {
|
|
205
|
-
...cmdGlobals,
|
|
206
|
-
apiKey: cmdGlobals.apiKey || process.env['SNOWPLOW_CONSOLE_API_KEY']
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
exports.getGlobalOptions = getGlobalOptions;
|
|
210
|
-
function isEmpty(arr) {
|
|
211
|
-
return Boolean(Array.isArray(arr) && !arr.length);
|
|
212
|
-
}
|
|
213
|
-
exports.isEmpty = isEmpty;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderDiff = exports.renderErrorMessage = exports.renderDebug = exports.renderLog = exports.renderWarn = exports.renderSuccess = exports.renderHelp = exports.createSpinner = void 0;
|
|
7
|
-
const cli_spinner_1 = require("cli-spinner");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
function createSpinner() {
|
|
10
|
-
const spinner = new cli_spinner_1.Spinner();
|
|
11
|
-
spinner.setSpinnerString(18);
|
|
12
|
-
return spinner;
|
|
13
|
-
}
|
|
14
|
-
exports.createSpinner = createSpinner;
|
|
15
|
-
const website = "https://snowplow.io";
|
|
16
|
-
const docs = "https://docs.snowplow.io/docs/collecting-data/code-generation/";
|
|
17
|
-
const icons = {
|
|
18
|
-
SUCCESS: "✔",
|
|
19
|
-
LOG: "ℹ",
|
|
20
|
-
DEBUG: "➤",
|
|
21
|
-
ERROR: "✗",
|
|
22
|
-
WARN: "⚠",
|
|
23
|
-
};
|
|
24
|
-
const colors = {
|
|
25
|
-
LINK: "#9911BB",
|
|
26
|
-
OPTION: "#9911DD",
|
|
27
|
-
};
|
|
28
|
-
function renderLink(link) {
|
|
29
|
-
return chalk_1.default.hex(colors.LINK).bold(link);
|
|
30
|
-
}
|
|
31
|
-
function renderOption(option) {
|
|
32
|
-
return chalk_1.default.hex(colors.OPTION).italic(option);
|
|
33
|
-
}
|
|
34
|
-
function renderHeader(headerType, headerContent) {
|
|
35
|
-
switch (headerType) {
|
|
36
|
-
case "h1":
|
|
37
|
-
return chalk_1.default.bold.underline(headerContent);
|
|
38
|
-
default:
|
|
39
|
-
return chalk_1.default.bold(headerContent);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function renderHelp() {
|
|
43
|
-
const helpText = `
|
|
44
|
-
${renderHeader("h1", "CLI Help")}
|
|
45
|
-
|
|
46
|
-
For more information visit the Snowplow website ${renderLink(website)}
|
|
47
|
-
|
|
48
|
-
For details see the CLI documentation ${renderLink(docs)}
|
|
49
|
-
|
|
50
|
-
${renderHeader("h2", "How to get started")}
|
|
51
|
-
1. Use ${chalk_1.default.cyanBright('snowtype init')} to initialize the setup.
|
|
52
|
-
2. Use ${chalk_1.default.cyanBright('snowtype patch')} to add a Data Structure or Tracking Scenario.
|
|
53
|
-
3. Use ${chalk_1.default.cyanBright('snowtype generate')} to generate tracking code.
|
|
54
|
-
|
|
55
|
-
${renderHeader("h2", "Available commands")}
|
|
56
|
-
To learn more about each CLI command, use the ${renderOption("--help")} option, for example, ${renderOption("snowtype init --help")}.
|
|
57
|
-
|
|
58
|
-
${renderOption("snowtype init")}
|
|
59
|
-
Initialize the setup of Snowtype code generation in a project. Creates the \`snowtype.config.json\` file.
|
|
60
|
-
|
|
61
|
-
${renderOption("snowtype patch")}
|
|
62
|
-
Adds new Data Structures and Tracking Scenarios in the \`snowtype.config.json\` file.
|
|
63
|
-
|
|
64
|
-
${renderOption("snowtype generate")}
|
|
65
|
-
Generates tracking code based on configuration on the \`snowtype.config.json\` file.
|
|
66
|
-
|
|
67
|
-
${renderOption("snowtype update")}
|
|
68
|
-
Checks for latest version updates in Data Structures and Tracking Scenarios.
|
|
69
|
-
|
|
70
|
-
${renderHeader("h2", "Debug")}
|
|
71
|
-
Use the ${renderOption("-v")} to output verbose logs
|
|
72
|
-
`;
|
|
73
|
-
return helpText;
|
|
74
|
-
}
|
|
75
|
-
exports.renderHelp = renderHelp;
|
|
76
|
-
function renderSuccess(msg) {
|
|
77
|
-
const successMsg = `${icons.SUCCESS}: `;
|
|
78
|
-
return chalk_1.default.cyanBright(successMsg) + msg;
|
|
79
|
-
}
|
|
80
|
-
exports.renderSuccess = renderSuccess;
|
|
81
|
-
function renderWarn(msg) {
|
|
82
|
-
const successMsg = `${icons.WARN} Warning: `;
|
|
83
|
-
return chalk_1.default.hex("#FFA500")(successMsg) + msg;
|
|
84
|
-
}
|
|
85
|
-
exports.renderWarn = renderWarn;
|
|
86
|
-
function renderLog(msg) {
|
|
87
|
-
const logMsg = `${icons.LOG} ${msg}`;
|
|
88
|
-
return chalk_1.default.yellowBright(logMsg);
|
|
89
|
-
}
|
|
90
|
-
exports.renderLog = renderLog;
|
|
91
|
-
function renderDebug(msg) {
|
|
92
|
-
const debugMsg = `${icons.DEBUG} Debug: `;
|
|
93
|
-
return chalk_1.default.magenta(debugMsg) + msg;
|
|
94
|
-
}
|
|
95
|
-
exports.renderDebug = renderDebug;
|
|
96
|
-
function renderErrorMessage(msg) {
|
|
97
|
-
const errorMsg = `${icons.ERROR} Error: `;
|
|
98
|
-
return chalk_1.default.redBright(errorMsg) + msg;
|
|
99
|
-
}
|
|
100
|
-
exports.renderErrorMessage = renderErrorMessage;
|
|
101
|
-
function renderDiff(current, next) {
|
|
102
|
-
const minus = `- ${current}`;
|
|
103
|
-
const plus = `+ ${next}`;
|
|
104
|
-
const diff = `
|
|
105
|
-
${chalk_1.default.magenta(minus)}
|
|
106
|
-
${chalk_1.default.cyanBright(plus)}
|
|
107
|
-
`;
|
|
108
|
-
return diff;
|
|
109
|
-
}
|
|
110
|
-
exports.renderDiff = renderDiff;
|