@hubspot/local-dev-lib 0.0.2 → 0.0.4
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/config/CLIConfiguration.d.ts +55 -0
- package/config/CLIConfiguration.js +392 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +109 -0
- package/config/configUtils.d.ts +24 -0
- package/config/configUtils.js +85 -0
- package/config/environment.d.ts +3 -0
- package/config/environment.js +64 -0
- package/constants/auth.d.ts +24 -0
- package/constants/auth.js +31 -0
- package/constants/config.d.ts +8 -0
- package/constants/config.js +12 -0
- package/constants/environments.d.ts +13 -0
- package/constants/environments.js +16 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +23 -0
- package/constants/files.d.ts +5 -0
- package/constants/files.js +8 -0
- package/constants/github.d.ts +4 -0
- package/constants/github.js +7 -0
- package/constants/index.d.ts +16 -0
- package/constants/index.js +12 -0
- package/errors/HubSpotAuthError.d.ts +3 -0
- package/errors/HubSpotAuthError.js +6 -0
- package/errors/fileSystemErrors.d.ts +8 -0
- package/errors/fileSystemErrors.js +28 -0
- package/errors/standardErrors.d.ts +19 -0
- package/errors/standardErrors.js +67 -0
- package/http/requestOptions.d.ts +20 -0
- package/http/requestOptions.js +27 -0
- package/lib/archive.d.ts +7 -0
- package/lib/archive.js +111 -0
- package/lib/cms/handleFieldsJS.d.ts +32 -0
- package/lib/cms/handleFieldsJS.js +143 -0
- package/lib/cms/index.d.ts +10 -0
- package/lib/cms/index.js +13 -0
- package/lib/cms/modules.d.ts +24 -0
- package/lib/cms/modules.js +124 -0
- package/lib/cms/themes.d.ts +2 -0
- package/lib/cms/themes.js +34 -0
- package/lib/environment.d.ts +1 -0
- package/lib/environment.js +16 -0
- package/lib/fs.d.ts +4 -0
- package/lib/fs.js +71 -0
- package/lib/github.d.ts +17 -0
- package/lib/github.js +133 -0
- package/lib/gitignore.d.ts +1 -0
- package/lib/gitignore.js +76 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +14 -0
- package/lib/path.d.ts +10 -0
- package/lib/path.js +84 -0
- package/lib/text.d.ts +1 -0
- package/lib/text.js +16 -0
- package/lib/urls.d.ts +2 -0
- package/lib/urls.js +20 -0
- package/package.json +8 -11
- package/types/Accounts.d.ts +50 -0
- package/types/Accounts.js +2 -0
- package/types/CLIOptions.d.ts +3 -0
- package/types/CLIOptions.js +2 -0
- package/types/Config.d.ts +10 -0
- package/types/Config.js +2 -0
- package/types/Error.d.ts +31 -0
- package/types/Error.js +2 -0
- package/types/Files.d.ts +8 -0
- package/types/Files.js +2 -0
- package/types/Github.d.ts +58 -0
- package/types/Github.js +2 -0
- package/types/LogCallbacks.d.ts +6 -0
- package/types/LogCallbacks.js +2 -0
- package/types/Modules.d.ts +5 -0
- package/types/Modules.js +2 -0
- package/types/Utils.d.ts +1 -0
- package/types/Utils.js +2 -0
- package/utils/escapeRegExp.d.ts +1 -0
- package/utils/escapeRegExp.js +7 -0
- package/utils/fieldsJS.d.ts +3 -0
- package/utils/fieldsJS.js +18 -0
- package/utils/git.d.ts +4 -0
- package/utils/git.js +40 -0
- package/utils/lang.d.ts +8 -0
- package/utils/lang.js +83 -0
- package/utils/logger.d.ts +10 -0
- package/utils/logger.js +22 -0
- package/utils/modules.d.ts +4 -0
- package/utils/modules.js +53 -0
package/lib/gitignore.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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.checkAndAddConfigToGitignore = void 0;
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
|
+
const git_1 = require("../utils/git");
|
|
11
|
+
const config_1 = require("../constants/config");
|
|
12
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
13
|
+
const GITIGNORE_FILE = '.gitignore';
|
|
14
|
+
// Get all .gitignore files since they can cascade down directory structures
|
|
15
|
+
function getGitignoreFiles(configPath) {
|
|
16
|
+
const gitDir = (0, git_1.getGitComparisonDir)();
|
|
17
|
+
const files = [];
|
|
18
|
+
if (!gitDir) {
|
|
19
|
+
// Not in git
|
|
20
|
+
return files;
|
|
21
|
+
}
|
|
22
|
+
// Start findup from config dir
|
|
23
|
+
let cwd = configPath && path_1.default.dirname(configPath);
|
|
24
|
+
while (cwd) {
|
|
25
|
+
const ignorePath = (0, findup_sync_1.default)(GITIGNORE_FILE, { cwd });
|
|
26
|
+
const ignorePathComparisonDir = (0, git_1.makeComparisonDir)(ignorePath);
|
|
27
|
+
const gitComparisonDir = (0, git_1.makeComparisonDir)(gitDir);
|
|
28
|
+
if (ignorePath &&
|
|
29
|
+
ignorePathComparisonDir &&
|
|
30
|
+
gitComparisonDir &&
|
|
31
|
+
ignorePathComparisonDir.startsWith(gitComparisonDir)) {
|
|
32
|
+
const file = path_1.default.resolve(ignorePath);
|
|
33
|
+
files.push(file);
|
|
34
|
+
cwd = path_1.default.resolve(path_1.default.dirname(file) + '..');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
cwd = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return files;
|
|
41
|
+
}
|
|
42
|
+
function checkGitInclusion(configPath) {
|
|
43
|
+
const result = {
|
|
44
|
+
inGit: false,
|
|
45
|
+
configIgnored: false,
|
|
46
|
+
gitignoreFiles: [],
|
|
47
|
+
};
|
|
48
|
+
if ((0, git_1.isConfigPathInGitRepo)(configPath)) {
|
|
49
|
+
result.inGit = true;
|
|
50
|
+
result.gitignoreFiles = getGitignoreFiles(configPath);
|
|
51
|
+
if ((0, git_1.configFilenameIsIgnoredByGitignore)(result.gitignoreFiles, configPath)) {
|
|
52
|
+
// Found ignore statement in .gitignore that matches config filename
|
|
53
|
+
result.configIgnored = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function checkAndAddConfigToGitignore(configPath) {
|
|
59
|
+
try {
|
|
60
|
+
const { configIgnored, gitignoreFiles } = checkGitInclusion(configPath);
|
|
61
|
+
if (configIgnored)
|
|
62
|
+
return;
|
|
63
|
+
let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
|
|
64
|
+
if (!gitignoreFilePath) {
|
|
65
|
+
gitignoreFilePath = path_1.default.resolve(configPath, GITIGNORE_FILE);
|
|
66
|
+
(0, fs_extra_1.writeFileSync)(gitignoreFilePath, '');
|
|
67
|
+
}
|
|
68
|
+
const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignoreFilePath).toString();
|
|
69
|
+
const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
|
|
70
|
+
(0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
(0, standardErrors_1.throwErrorWithMessage)('utils.git.configIgnore', {}, e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { extractZipArchive as __extractZipArchive } from './archive';
|
|
2
|
+
import { getValidEnv as __getValidEnv } from './environment';
|
|
3
|
+
import { walk as __walk } from './fs';
|
|
4
|
+
import { commaSeparatedValues as __commaSeparatedValues } from './text';
|
|
5
|
+
import { getHubSpotApiOrigin as __getHubSpotApiOrigin } from './urls';
|
|
6
|
+
export declare const extractZipArchive: typeof __extractZipArchive;
|
|
7
|
+
export declare const getValidEnv: typeof __getValidEnv;
|
|
8
|
+
export declare const walk: typeof __walk;
|
|
9
|
+
export declare const commaSeparatedValues: typeof __commaSeparatedValues;
|
|
10
|
+
export declare const getHubSpotApiOrigin: typeof __getHubSpotApiOrigin;
|
|
11
|
+
export declare const getHubSpotWebsiteOrigin: (env: string) => string;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHubSpotWebsiteOrigin = exports.getHubSpotApiOrigin = exports.commaSeparatedValues = exports.walk = exports.getValidEnv = exports.extractZipArchive = void 0;
|
|
4
|
+
const archive_1 = require("./archive");
|
|
5
|
+
const environment_1 = require("./environment");
|
|
6
|
+
const fs_1 = require("./fs");
|
|
7
|
+
const text_1 = require("./text");
|
|
8
|
+
const urls_1 = require("./urls");
|
|
9
|
+
exports.extractZipArchive = archive_1.extractZipArchive;
|
|
10
|
+
exports.getValidEnv = environment_1.getValidEnv;
|
|
11
|
+
exports.walk = fs_1.walk;
|
|
12
|
+
exports.commaSeparatedValues = text_1.commaSeparatedValues;
|
|
13
|
+
exports.getHubSpotApiOrigin = urls_1.getHubSpotApiOrigin;
|
|
14
|
+
exports.getHubSpotWebsiteOrigin = urls_1.getHubSpotWebsiteOrigin;
|
package/lib/path.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export declare function convertToUnixPath(_path: string): string;
|
|
4
|
+
export declare function convertToLocalFileSystemPath(_path: string): string;
|
|
5
|
+
export declare function splitLocalPath(filepath: string, pathImplementation?: path.PlatformPath): Array<string>;
|
|
6
|
+
export declare function splitHubSpotPath(filepath: string): Array<string>;
|
|
7
|
+
export declare function getCwd(): string;
|
|
8
|
+
export declare function getExt(filepath: string): string;
|
|
9
|
+
export declare function isAllowedExtension(filepath: string): boolean;
|
|
10
|
+
export declare function getAbsoluteFilePath(_path: string): string;
|
package/lib/path.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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.getAbsoluteFilePath = exports.isAllowedExtension = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const unixify_1 = __importDefault(require("unixify"));
|
|
9
|
+
const extensions_1 = require("../constants/extensions");
|
|
10
|
+
function convertToUnixPath(_path) {
|
|
11
|
+
return (0, unixify_1.default)(path_1.default.normalize(_path));
|
|
12
|
+
}
|
|
13
|
+
exports.convertToUnixPath = convertToUnixPath;
|
|
14
|
+
function convertToWindowsPath(_path) {
|
|
15
|
+
const rgx = new RegExp(`\\${path_1.default.posix.sep}`, 'g');
|
|
16
|
+
return path_1.default.normalize(_path).replace(rgx, path_1.default.win32.sep);
|
|
17
|
+
}
|
|
18
|
+
function convertToLocalFileSystemPath(_path) {
|
|
19
|
+
switch (path_1.default.sep) {
|
|
20
|
+
case path_1.default.posix.sep:
|
|
21
|
+
return convertToUnixPath(_path);
|
|
22
|
+
case path_1.default.win32.sep:
|
|
23
|
+
return convertToWindowsPath(_path);
|
|
24
|
+
default:
|
|
25
|
+
return path_1.default.normalize(_path);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.convertToLocalFileSystemPath = convertToLocalFileSystemPath;
|
|
29
|
+
function removeTrailingSlashFromSplits(parts) {
|
|
30
|
+
if (parts.length > 1 && parts[parts.length - 1] === '') {
|
|
31
|
+
return parts.slice(0, parts.length - 1);
|
|
32
|
+
}
|
|
33
|
+
return parts;
|
|
34
|
+
}
|
|
35
|
+
// Splits a filepath for local file system sources.
|
|
36
|
+
function splitLocalPath(filepath, pathImplementation = path_1.default) {
|
|
37
|
+
if (!filepath)
|
|
38
|
+
return [];
|
|
39
|
+
const { sep } = pathImplementation;
|
|
40
|
+
const rgx = new RegExp(`\\${sep}+`, 'g');
|
|
41
|
+
const parts = pathImplementation.normalize(filepath).split(rgx);
|
|
42
|
+
// Restore posix root if present
|
|
43
|
+
if (sep === path_1.default.posix.sep && parts[0] === '') {
|
|
44
|
+
parts[0] = '/';
|
|
45
|
+
}
|
|
46
|
+
return removeTrailingSlashFromSplits(parts);
|
|
47
|
+
}
|
|
48
|
+
exports.splitLocalPath = splitLocalPath;
|
|
49
|
+
// Splits a filepath for remote sources (HubSpot).
|
|
50
|
+
function splitHubSpotPath(filepath) {
|
|
51
|
+
if (!filepath)
|
|
52
|
+
return [];
|
|
53
|
+
const rgx = new RegExp(`\\${path_1.default.posix.sep}+`, 'g');
|
|
54
|
+
const parts = convertToUnixPath(filepath).split(rgx);
|
|
55
|
+
// Restore root if present
|
|
56
|
+
if (parts[0] === '') {
|
|
57
|
+
parts[0] = '/';
|
|
58
|
+
}
|
|
59
|
+
return removeTrailingSlashFromSplits(parts);
|
|
60
|
+
}
|
|
61
|
+
exports.splitHubSpotPath = splitHubSpotPath;
|
|
62
|
+
function getCwd() {
|
|
63
|
+
if (process.env.INIT_CWD) {
|
|
64
|
+
return process.env.INIT_CWD;
|
|
65
|
+
}
|
|
66
|
+
return process.cwd();
|
|
67
|
+
}
|
|
68
|
+
exports.getCwd = getCwd;
|
|
69
|
+
function getExt(filepath) {
|
|
70
|
+
if (typeof filepath !== 'string')
|
|
71
|
+
return '';
|
|
72
|
+
const ext = path_1.default.extname(filepath).trim().toLowerCase();
|
|
73
|
+
return ext[0] === '.' ? ext.slice(1) : ext;
|
|
74
|
+
}
|
|
75
|
+
exports.getExt = getExt;
|
|
76
|
+
function isAllowedExtension(filepath) {
|
|
77
|
+
const ext = getExt(filepath);
|
|
78
|
+
return extensions_1.ALLOWED_EXTENSIONS.has(ext);
|
|
79
|
+
}
|
|
80
|
+
exports.isAllowedExtension = isAllowedExtension;
|
|
81
|
+
function getAbsoluteFilePath(_path) {
|
|
82
|
+
return path_1.default.resolve(getCwd(), _path);
|
|
83
|
+
}
|
|
84
|
+
exports.getAbsoluteFilePath = getAbsoluteFilePath;
|
package/lib/text.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function commaSeparatedValues(arr: Array<string>, conjunction?: string, ifempty?: string): string;
|
package/lib/text.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commaSeparatedValues = void 0;
|
|
4
|
+
function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
|
|
5
|
+
const l = arr.length;
|
|
6
|
+
if (!l)
|
|
7
|
+
return ifempty;
|
|
8
|
+
if (l < 2)
|
|
9
|
+
return arr[0];
|
|
10
|
+
if (l < 3)
|
|
11
|
+
return arr.join(` ${conjunction} `);
|
|
12
|
+
arr = arr.slice();
|
|
13
|
+
arr[l - 1] = `${conjunction} ${arr[l - 1]}`;
|
|
14
|
+
return arr.join(', ');
|
|
15
|
+
}
|
|
16
|
+
exports.commaSeparatedValues = commaSeparatedValues;
|
package/lib/urls.d.ts
ADDED
package/lib/urls.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHubSpotApiOrigin = exports.getHubSpotWebsiteOrigin = void 0;
|
|
4
|
+
const environments_1 = require("../constants/environments");
|
|
5
|
+
function getEnvUrlString(env) {
|
|
6
|
+
if (typeof env !== 'string') {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
return env.toLowerCase() === environments_1.ENVIRONMENTS.QA ? environments_1.ENVIRONMENTS.QA : '';
|
|
10
|
+
}
|
|
11
|
+
const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
|
|
12
|
+
exports.getHubSpotWebsiteOrigin = getHubSpotWebsiteOrigin;
|
|
13
|
+
function getHubSpotApiOrigin(env, useLocalHost) {
|
|
14
|
+
let domain = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
15
|
+
if (!domain || typeof domain !== 'string') {
|
|
16
|
+
domain = `${useLocalHost ? 'local' : 'api'}.hubapi${getEnvUrlString(env)}`;
|
|
17
|
+
}
|
|
18
|
+
return `https://${domain}.com`;
|
|
19
|
+
}
|
|
20
|
+
exports.getHubSpotApiOrigin = getHubSpotApiOrigin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc --rootDir . --outdir dist",
|
|
16
16
|
"check-main": "branch=$(git rev-parse --abbrev-ref HEAD) && [ $branch = main ] || (echo 'Error: New release can only be published on main branch' && exit 1)",
|
|
17
|
-
"lint": "eslint --max-warnings=0 . && prettier --check
|
|
17
|
+
"lint": "eslint --max-warnings=0 . && prettier --check ./**/*.ts",
|
|
18
18
|
"local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
|
|
19
19
|
"_postinstall": "husky install",
|
|
20
20
|
"prepack": "pinst --disable",
|
|
21
21
|
"postpack": "pinst --enable",
|
|
22
|
-
"prettier:write": "prettier --write
|
|
22
|
+
"prettier:write": "prettier --write ./**/*.{js,json}",
|
|
23
23
|
"pub": "cd dist && npm publish --tag latest && cd ..",
|
|
24
24
|
"push": "git push --atomic origin main v$npm_package_version",
|
|
25
25
|
"release:major": "yarn check-main && yarn version --major && yarn build && yarn pub && yarn push",
|
|
@@ -45,15 +45,12 @@
|
|
|
45
45
|
"ts-jest": "^29.0.5",
|
|
46
46
|
"typescript": "^4.9.5"
|
|
47
47
|
},
|
|
48
|
-
"files": [
|
|
49
|
-
"dist/**/*"
|
|
50
|
-
],
|
|
51
48
|
"exports": {
|
|
52
|
-
".": "./
|
|
53
|
-
"./cms": "./
|
|
54
|
-
"./constants": "./
|
|
55
|
-
"./github": "./
|
|
56
|
-
"./path": "./
|
|
49
|
+
".": "./lib/index.js",
|
|
50
|
+
"./cms": "./lib/cms",
|
|
51
|
+
"./constants": "./constants",
|
|
52
|
+
"./github": "./lib/github.js",
|
|
53
|
+
"./path": "./lib/path.js"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
56
|
"axios": "^1.3.5",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DEFAULT_MODES } from '../constants/config';
|
|
2
|
+
import { ValueOf } from './Utils';
|
|
3
|
+
export type AuthType = 'personalaccesskey' | 'apikey' | 'oauth2';
|
|
4
|
+
export interface CLIAccount {
|
|
5
|
+
name?: string;
|
|
6
|
+
accountId: number;
|
|
7
|
+
defaultMode?: ValueOf<typeof DEFAULT_MODES>;
|
|
8
|
+
env?: string;
|
|
9
|
+
authType?: AuthType;
|
|
10
|
+
auth?: object;
|
|
11
|
+
sandboxAccountType?: string | null;
|
|
12
|
+
parentAccountId?: number | null;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
personalAccessKey?: string;
|
|
15
|
+
}
|
|
16
|
+
export type PersonalAccessKeyTokenInfo = {
|
|
17
|
+
accessToken: string;
|
|
18
|
+
expiresAt: string;
|
|
19
|
+
};
|
|
20
|
+
export type OauthTokenInfo = {
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
};
|
|
23
|
+
export interface PersonalAccessKeyAccount extends CLIAccount {
|
|
24
|
+
authType: 'personalaccesskey';
|
|
25
|
+
auth?: {
|
|
26
|
+
tokenInfo: PersonalAccessKeyTokenInfo;
|
|
27
|
+
};
|
|
28
|
+
personalAccessKey: string;
|
|
29
|
+
}
|
|
30
|
+
export interface OAuthAccount extends CLIAccount {
|
|
31
|
+
authType: 'oauth2';
|
|
32
|
+
auth?: {
|
|
33
|
+
clientId?: string;
|
|
34
|
+
clientSecret?: string;
|
|
35
|
+
scopes?: Array<string>;
|
|
36
|
+
tokenInfo?: OauthTokenInfo;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface APIKeyAccount extends CLIAccount {
|
|
40
|
+
authType: 'apikey';
|
|
41
|
+
apiKey: string;
|
|
42
|
+
}
|
|
43
|
+
export interface FlatAccountFields<T extends OauthTokenInfo | PersonalAccessKeyTokenInfo> extends CLIAccount {
|
|
44
|
+
tokenInfo?: T;
|
|
45
|
+
clientId?: string;
|
|
46
|
+
clientSecret?: string;
|
|
47
|
+
scopes?: Array<string>;
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
personalAccessKey?: string;
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CLIAccount } from './Accounts';
|
|
2
|
+
export interface CLIConfig {
|
|
3
|
+
accounts: Array<CLIAccount>;
|
|
4
|
+
allowUsageTracking?: boolean;
|
|
5
|
+
defaultAccount?: string | number;
|
|
6
|
+
defaultMode?: string;
|
|
7
|
+
httpTimeout?: number;
|
|
8
|
+
env?: string;
|
|
9
|
+
httpUseLocalhost?: boolean;
|
|
10
|
+
}
|
package/types/Config.js
ADDED
package/types/Error.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface BaseError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string;
|
|
4
|
+
errno?: number | null;
|
|
5
|
+
code?: string | null;
|
|
6
|
+
syscall?: string | null;
|
|
7
|
+
reason?: string;
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface StatusCodeError extends BaseError {
|
|
11
|
+
name: 'StatusCodeError';
|
|
12
|
+
statusCode: number;
|
|
13
|
+
message: string;
|
|
14
|
+
response: {
|
|
15
|
+
request: {
|
|
16
|
+
href: string;
|
|
17
|
+
method: string;
|
|
18
|
+
};
|
|
19
|
+
body: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
headers: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface GithubError extends BaseError {
|
|
28
|
+
error: {
|
|
29
|
+
message?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
package/types/Error.js
ADDED
package/types/Files.d.ts
ADDED
package/types/Files.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type GithubAuthor = {
|
|
2
|
+
login: string;
|
|
3
|
+
id: number;
|
|
4
|
+
node_id: string;
|
|
5
|
+
avatar_url: string;
|
|
6
|
+
gravatar_id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
html_url: string;
|
|
9
|
+
followers_url: string;
|
|
10
|
+
following_url: string;
|
|
11
|
+
gists_url: string;
|
|
12
|
+
starred_url: string;
|
|
13
|
+
subscriptions_url: string;
|
|
14
|
+
organizations_url: string;
|
|
15
|
+
repos_url: string;
|
|
16
|
+
events_url: string;
|
|
17
|
+
received_events_url: string;
|
|
18
|
+
type: string;
|
|
19
|
+
site_admin: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type GithubReleaseData = {
|
|
22
|
+
url: string;
|
|
23
|
+
assets_url: string;
|
|
24
|
+
upload_url: string;
|
|
25
|
+
html_url: string;
|
|
26
|
+
id: number;
|
|
27
|
+
author: GithubAuthor;
|
|
28
|
+
node_id: string;
|
|
29
|
+
tag_name: string;
|
|
30
|
+
target_commitish: string;
|
|
31
|
+
name: string;
|
|
32
|
+
draft: boolean;
|
|
33
|
+
prerelease: boolean;
|
|
34
|
+
created_at: string;
|
|
35
|
+
published_at: string;
|
|
36
|
+
assets: Array<object>;
|
|
37
|
+
tarball_url: string;
|
|
38
|
+
zipball_url: string;
|
|
39
|
+
body: string;
|
|
40
|
+
mentions_count: number;
|
|
41
|
+
};
|
|
42
|
+
export type GithubRepoFile = {
|
|
43
|
+
name: string;
|
|
44
|
+
path: string;
|
|
45
|
+
sha: string;
|
|
46
|
+
size: number;
|
|
47
|
+
url: string;
|
|
48
|
+
html_url: string;
|
|
49
|
+
git_url: string;
|
|
50
|
+
download_url: string;
|
|
51
|
+
type: string;
|
|
52
|
+
_links: {
|
|
53
|
+
self: string;
|
|
54
|
+
git: string;
|
|
55
|
+
html: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export {};
|
package/types/Github.js
ADDED
package/types/Modules.js
ADDED
package/types/Utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ValueOf<T> = T[keyof T];
|
package/types/Utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeRegExp(string: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeRegExp = void 0;
|
|
4
|
+
function escapeRegExp(string) {
|
|
5
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
6
|
+
}
|
|
7
|
+
exports.escapeRegExp = escapeRegExp;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldsArrayToJson = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Polyfill for `Array.flat(Infinity)` since the `flat` is only available for Node v11+
|
|
6
|
+
* https://stackoverflow.com/a/15030117
|
|
7
|
+
*/
|
|
8
|
+
function flattenArray(arr) {
|
|
9
|
+
return arr.reduce((flat, toFlatten) => {
|
|
10
|
+
return flat.concat(Array.isArray(toFlatten) ? flattenArray(toFlatten) : toFlatten);
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
//Transform fields array to JSON
|
|
14
|
+
function fieldsArrayToJson(fields) {
|
|
15
|
+
const flattened = flattenArray(fields);
|
|
16
|
+
return JSON.stringify(flattened, null, 2);
|
|
17
|
+
}
|
|
18
|
+
exports.fieldsArrayToJson = fieldsArrayToJson;
|
package/utils/git.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function makeComparisonDir(filepath: string | null): string | null;
|
|
2
|
+
export declare const getGitComparisonDir: () => string | null;
|
|
3
|
+
export declare function isConfigPathInGitRepo(configPath: string): boolean;
|
|
4
|
+
export declare function configFilenameIsIgnoredByGitignore(ignoreFiles: Array<string>, configPath: string): boolean;
|
package/utils/git.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = exports.getGitComparisonDir = exports.makeComparisonDir = void 0;
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
11
|
+
function makeComparisonDir(filepath) {
|
|
12
|
+
if (typeof filepath !== 'string')
|
|
13
|
+
return null;
|
|
14
|
+
// Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
|
|
15
|
+
return path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase() + path_1.default.sep;
|
|
16
|
+
}
|
|
17
|
+
exports.makeComparisonDir = makeComparisonDir;
|
|
18
|
+
const getGitComparisonDir = () => makeComparisonDir((0, findup_sync_1.default)('.git'));
|
|
19
|
+
exports.getGitComparisonDir = getGitComparisonDir;
|
|
20
|
+
function isConfigPathInGitRepo(configPath) {
|
|
21
|
+
const gitDir = (0, exports.getGitComparisonDir)();
|
|
22
|
+
if (!gitDir)
|
|
23
|
+
return false;
|
|
24
|
+
const configDir = makeComparisonDir(configPath);
|
|
25
|
+
if (!configDir)
|
|
26
|
+
return false;
|
|
27
|
+
return configDir.startsWith(gitDir);
|
|
28
|
+
}
|
|
29
|
+
exports.isConfigPathInGitRepo = isConfigPathInGitRepo;
|
|
30
|
+
function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
|
|
31
|
+
return ignoreFiles.some(gitignore => {
|
|
32
|
+
const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignore).toString();
|
|
33
|
+
const gitignoreConfig = (0, ignore_1.default)().add(gitignoreContents);
|
|
34
|
+
if (gitignoreConfig.ignores(path_1.default.relative(path_1.default.dirname(gitignore), configPath))) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.configFilenameIsIgnoredByGitignore = configFilenameIsIgnoredByGitignore;
|
package/utils/lang.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type InterpolationData = {
|
|
2
|
+
[identifier: string]: string | number;
|
|
3
|
+
};
|
|
4
|
+
export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
|
|
5
|
+
export declare function i18n(lookupDotNotation: string, options?: {
|
|
6
|
+
[identifier: string]: string | number;
|
|
7
|
+
}): string;
|
|
8
|
+
export {};
|