@sw-tsdk/core 0.1.1-next.23

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.
Files changed (50) hide show
  1. package/LICENSE +8 -0
  2. package/lib/base.d.ts +11 -0
  3. package/lib/base.js +39 -0
  4. package/lib/base.js.map +1 -0
  5. package/lib/config-service.d.ts +7 -0
  6. package/lib/config-service.js +41 -0
  7. package/lib/config-service.js.map +1 -0
  8. package/lib/index.d.ts +4 -0
  9. package/lib/index.js +8 -0
  10. package/lib/index.js.map +1 -0
  11. package/lib/models/cipher.d.ts +5 -0
  12. package/lib/models/cipher.js +3 -0
  13. package/lib/models/cipher.js.map +1 -0
  14. package/lib/models/config.d.ts +9 -0
  15. package/lib/models/config.js +7 -0
  16. package/lib/models/config.js.map +1 -0
  17. package/lib/models/index.d.ts +3 -0
  18. package/lib/models/index.js +7 -0
  19. package/lib/models/index.js.map +1 -0
  20. package/lib/models/netrc-entry.d.ts +5 -0
  21. package/lib/models/netrc-entry.js +3 -0
  22. package/lib/models/netrc-entry.js.map +1 -0
  23. package/lib/utils/credential-helper.d.ts +9 -0
  24. package/lib/utils/credential-helper.js +48 -0
  25. package/lib/utils/credential-helper.js.map +1 -0
  26. package/lib/utils/fs-utils.d.ts +3 -0
  27. package/lib/utils/fs-utils.js +41 -0
  28. package/lib/utils/fs-utils.js.map +1 -0
  29. package/lib/utils/git-credential.d.ts +14 -0
  30. package/lib/utils/git-credential.js +60 -0
  31. package/lib/utils/git-credential.js.map +1 -0
  32. package/lib/utils/git.d.ts +8 -0
  33. package/lib/utils/git.js +31 -0
  34. package/lib/utils/git.js.map +1 -0
  35. package/lib/utils/index.d.ts +7 -0
  36. package/lib/utils/index.js +11 -0
  37. package/lib/utils/index.js.map +1 -0
  38. package/lib/utils/netrc.d.ts +4 -0
  39. package/lib/utils/netrc.js +48 -0
  40. package/lib/utils/netrc.js.map +1 -0
  41. package/lib/utils/protector.d.ts +9 -0
  42. package/lib/utils/protector.js +52 -0
  43. package/lib/utils/protector.js.map +1 -0
  44. package/lib/utils/streams.d.ts +16 -0
  45. package/lib/utils/streams.js +37 -0
  46. package/lib/utils/streams.js.map +1 -0
  47. package/lib/utils/strings.d.ts +1 -0
  48. package/lib/utils/strings.js +15 -0
  49. package/lib/utils/strings.js.map +1 -0
  50. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The ISC License (ISC)
2
+
3
+ Copyright © SWIMLANE 2021
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8
+ {"mode":"full","isActive":false}
package/lib/base.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ import type { ConfigType } from './models';
3
+ export declare abstract class Base extends Command {
4
+ sdkConfig: ConfigType;
5
+ environment: string | null;
6
+ static BaseFlags: {
7
+ 'log-level': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
+ };
9
+ init(): Promise<void>;
10
+ protected saveConfig(key: string, value: string | Date): Promise<void>;
11
+ }
package/lib/base.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const config_service_1 = require("./config-service");
6
+ const core_2 = require("@oclif/core");
7
+ // noinspection JSUnusedGlobalSymbols
8
+ class Base extends core_1.Command {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.sdkConfig = { gitProtocol: 'https', owner: 'swimlane', lastRepoCheck: new Date(1977, 1, 8) };
12
+ this.environment = null;
13
+ }
14
+ async init() {
15
+ const entry = this.config.configDir;
16
+ const { flags } = (await this.parse(this.constructor));
17
+ if (flags['log-level'] === 'debug') {
18
+ core_2.CliUx.ux.config.outputLevel = 'debug';
19
+ }
20
+ const configService = new config_service_1.ConfigService(entry);
21
+ const config = (await configService.loadConfig()) || { gitProtocol: 'https', owner: 'swimlane', lastRepoCheck: new Date(1977, 1, 8) };
22
+ this.sdkConfig = config;
23
+ }
24
+ async saveConfig(key, value) {
25
+ const entry = this.config.configDir;
26
+ const configService = new config_service_1.ConfigService(entry);
27
+ const loadedConfig = await configService.loadConfig();
28
+ if (!loadedConfig) {
29
+ return;
30
+ }
31
+ loadedConfig[key] = value;
32
+ await configService.saveConfig(loadedConfig);
33
+ }
34
+ }
35
+ exports.Base = Base;
36
+ Base.BaseFlags = {
37
+ 'log-level': core_1.Flags.string({ options: ['debug'], hidden: true }),
38
+ };
39
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":";;;AAAA,sCAA0C;AAE1C,qDAA8C;AAC9C,sCAAiC;AAEjC,qCAAqC;AACrC,MAAsB,IAAK,SAAQ,cAAO;IAA1C;;QACE,cAAS,GAAe,EAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAC,CAAA;QAEtG,gBAAW,GAAkB,IAAI,CAAA;IAiCnC,CAAC;IA3BC,KAAK,CAAC,IAAI;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAA;QACnC,MAAM,EAAC,KAAK,EAAC,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAA6B,CAAC,CAAQ,CAAA;QAE7E,IAAI,KAAK,CAAC,WAAW,CAAC,KAAK,OAAO,EAAE;YAClC,YAAK,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,GAAG,OAAO,CAAA;SACtC;QAED,MAAM,aAAa,GAAG,IAAI,8BAAa,CAAC,KAAK,CAAC,CAAA;QAE9C,MAAM,MAAM,GAAG,CAAC,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,IAAI,EAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAC,CAAA;QACnI,IAAI,CAAC,SAAS,GAAG,MAAa,CAAA;IAChC,CAAC;IAES,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,KAAoB;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAA;QACnC,MAAM,aAAa,GAAG,IAAI,8BAAa,CAAC,KAAK,CAAC,CAAA;QAC9C,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,CAAA;QAErD,IAAI,CAAC,YAAY,EAAE;YACjB,OAAM;SACP;QAED,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAEzB,MAAM,aAAa,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;IAC9C,CAAC;;AAnCH,oBAoCC;AA/BQ,cAAS,GAAG;IACjB,WAAW,EAAE,YAAK,CAAC,MAAM,CAAC,EAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC;CAC9D,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { ConfigType } from './models';
2
+ export declare class ConfigService {
3
+ private _basePath;
4
+ constructor(_basePath: string);
5
+ loadConfig(): Promise<ConfigType | null>;
6
+ saveConfig({ owner, gitProtocol, lastRepoCheck }: ConfigType): Promise<void>;
7
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigService = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const node_path_1 = require("node:path");
6
+ const utils_1 = require("./utils");
7
+ class ConfigService {
8
+ // eslint-disable-next-line no-useless-constructor
9
+ constructor(_basePath) {
10
+ this._basePath = _basePath;
11
+ }
12
+ async loadConfig() {
13
+ const configPath = (0, node_path_1.join)(this._basePath, '.sw-tsdkrc.json');
14
+ if (!await (0, utils_1.fileExists)(configPath)) {
15
+ return null;
16
+ }
17
+ const result = await (0, fs_extra_1.readJson)(configPath);
18
+ if (!result) {
19
+ return null;
20
+ }
21
+ return result;
22
+ }
23
+ async saveConfig({ owner, gitProtocol, lastRepoCheck }) {
24
+ const configPath = (0, node_path_1.join)(this._basePath, '.sw-tsdkrc.json');
25
+ let configValues = {
26
+ owner: 'swimlane',
27
+ gitProtocol: 'https',
28
+ };
29
+ if (await (0, utils_1.fileExists)(configPath)) {
30
+ configValues = Object.assign(configValues, (await (0, fs_extra_1.readJson)(configPath)));
31
+ }
32
+ Object.assign(configValues, {
33
+ owner,
34
+ gitProtocol,
35
+ lastRepoCheck,
36
+ });
37
+ await (0, fs_extra_1.writeJson)(configPath, configValues, { spaces: 2, EOL: '\n' });
38
+ }
39
+ }
40
+ exports.ConfigService = ConfigService;
41
+ //# sourceMappingURL=config-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-service.js","sourceRoot":"","sources":["../src/config-service.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,yCAA8B;AAC9B,mCAAkC;AAElC,MAAa,aAAa;IACxB,kDAAkD;IAClD,YAAoB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAElC,KAAK,CAAC,UAAU;QACrB,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;QAE1D,IAAI,CAAC,MAAM,IAAA,kBAAU,EAAC,UAAU,CAAC,EAAE;YACjC,OAAO,IAAI,CAAA;SACZ;QAED,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAQ,EAAC,UAAU,CAAC,CAAA;QAEzC,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,EAAC,KAAK,EAAE,WAAW,EAAE,aAAa,EAAa;QACrE,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;QAC1D,IAAI,YAAY,GAAG;YACjB,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,OAAO;SACrB,CAAA;QACD,IAAI,MAAM,IAAA,kBAAU,EAAC,UAAU,CAAC,EAAE;YAChC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,MAAM,IAAA,mBAAQ,EAAC,UAAU,CAAC,CAAC,CAAC,CAAA;SACzE;QAED,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;YAC1B,KAAK;YACL,WAAW;YACX,aAAa;SACd,CAAC,CAAA;QAEF,MAAM,IAAA,oBAAS,EAAC,UAAU,EAAE,YAAY,EAAE,EAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAC,CAAC,CAAA;IACnE,CAAC;CACF;AAtCD,sCAsCC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './base';
2
+ export * from './models';
3
+ export * from './utils';
4
+ export * from './config-service';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./base"), exports);
5
+ tslib_1.__exportStar(require("./models"), exports);
6
+ tslib_1.__exportStar(require("./utils"), exports);
7
+ tslib_1.__exportStar(require("./config-service"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAsB;AACtB,mDAAwB;AACxB,kDAAuB;AACvB,2DAAgC"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ export declare type Cipher = {
3
+ cipherKey: Buffer;
4
+ hashingSalt: Buffer;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=cipher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cipher.js","sourceRoot":"","sources":["../../src/models/cipher.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export declare type ConfigType = {
2
+ [key: string]: string | Date | undefined;
3
+ gitProtocol: string;
4
+ owner?: string;
5
+ lastRepoCheck?: Date;
6
+ };
7
+ export declare const ConfigTypeDefault: {
8
+ gitProtocol: string;
9
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigTypeDefault = void 0;
4
+ exports.ConfigTypeDefault = {
5
+ gitProtocol: 'https',
6
+ };
7
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/models/config.ts"],"names":[],"mappings":";;;AAOa,QAAA,iBAAiB,GAAG;IAC/B,WAAW,EAAE,OAAO;CACrB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './cipher';
3
+ export * from './netrc-entry';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./config"), exports);
5
+ tslib_1.__exportStar(require("./cipher"), exports);
6
+ tslib_1.__exportStar(require("./netrc-entry"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,mDAAwB;AACxB,wDAA6B"}
@@ -0,0 +1,5 @@
1
+ export interface NetrcEntry {
2
+ host: string;
3
+ login: string;
4
+ password: string;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=netrc-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netrc-entry.js","sourceRoot":"","sources":["../../src/models/netrc-entry.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ interface GitCredentialSetupParams {
2
+ hostname: string;
3
+ username: string;
4
+ password: string;
5
+ }
6
+ export declare function shouldPromptForSetup(hostname: string): Promise<boolean>;
7
+ export declare function gitCredentialSetup({ hostname, username, password }: GitCredentialSetupParams): Promise<void>;
8
+ export declare function isOurCredentialHelper(cmd: string): boolean;
9
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOurCredentialHelper = exports.gitCredentialSetup = exports.shouldPromptForSetup = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const git_credential_1 = require("./git-credential");
6
+ const simple_git_1 = tslib_1.__importStar(require("simple-git"));
7
+ // noinspection JSUnusedGlobalSymbols
8
+ async function shouldPromptForSetup(hostname) {
9
+ const helper = await getCredentialHelper(hostname);
10
+ return helper === '' || !isOurCredentialHelper(helper);
11
+ }
12
+ exports.shouldPromptForSetup = shouldPromptForSetup;
13
+ // noinspection JSUnusedGlobalSymbols
14
+ async function gitCredentialSetup({ hostname, username, password }) {
15
+ const git = (0, simple_git_1.default)();
16
+ // first use a blank value to indicate to git we want to sever the chain of credential helpers
17
+ const helper = await getCredentialHelper(hostname);
18
+ if (helper === '') {
19
+ const configKey = gitCredentialHelperKey(hostname);
20
+ await git.addConfig(configKey, '', true, simple_git_1.GitConfigScope.global);
21
+ const executable = process.argv[1] || 'sw-tsdk';
22
+ await git.addConfig(configKey, `!${executable} auth:git-credential`, true, simple_git_1.GitConfigScope.global);
23
+ }
24
+ await (0, git_credential_1.reject)(hostname);
25
+ await (0, git_credential_1.approve)({ username, url: hostname, password: password });
26
+ }
27
+ exports.gitCredentialSetup = gitCredentialSetup;
28
+ function isOurCredentialHelper(cmd) {
29
+ if (!cmd.startsWith('!')) {
30
+ return false;
31
+ }
32
+ return cmd.includes('sw-tsdk');
33
+ }
34
+ exports.isOurCredentialHelper = isOurCredentialHelper;
35
+ async function getCredentialHelper(hostname) {
36
+ const git = (0, simple_git_1.default)();
37
+ const configKey = gitCredentialHelperKey(hostname);
38
+ let config = await git.getConfig(configKey);
39
+ if (config && config.value) {
40
+ return config.value;
41
+ }
42
+ config = await git.getConfig('credential.helper');
43
+ return (config === null || config === void 0 ? void 0 : config.value) || '';
44
+ }
45
+ function gitCredentialHelperKey(hostname) {
46
+ return `credential.${hostname}.helper`;
47
+ }
48
+ //# sourceMappingURL=credential-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-helper.js","sourceRoot":"","sources":["../../src/utils/credential-helper.ts"],"names":[],"mappings":";;;;AAAA,qDAAgD;AAChD,iEAAoD;AAQpD,qCAAqC;AAC9B,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAClD,OAAO,MAAM,KAAK,EAAE,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;AACxD,CAAC;AAHD,oDAGC;AAED,qCAAqC;AAC9B,KAAK,UAAU,kBAAkB,CAAC,EAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAA2B;IAC/F,MAAM,GAAG,GAAG,IAAA,oBAAS,GAAE,CAAA;I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AmB,CAAC,CAAA;IAEjD,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,KAAI,EAAE,CAAA;AAC5B,CAAC;AAED,SAAS,sBAAsB,CAAC,QAAgB;IAC9C,OAAO,cAAc,QAAQ,SAAS,CAAA;AACxC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function directoryExists(path: string): Promise<boolean>;
2
+ export declare function fileExists(path: string): Promise<boolean>;
3
+ export declare function hasGit(path: string): Promise<boolean>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasGit = exports.fileExists = exports.directoryExists = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ async function directoryExists(path) {
6
+ return node_fs_1.promises.stat(path)
7
+ .then(stat => {
8
+ return stat.isDirectory();
9
+ })
10
+ .catch(error => {
11
+ if (error.code === 'ENOENT') {
12
+ return false;
13
+ }
14
+ throw error;
15
+ });
16
+ }
17
+ exports.directoryExists = directoryExists;
18
+ async function fileExists(path) {
19
+ return node_fs_1.promises.stat(path)
20
+ .then(stat => {
21
+ return stat.isFile();
22
+ })
23
+ .catch(error => {
24
+ if (error.code === 'ENOENT') {
25
+ return false;
26
+ }
27
+ throw error;
28
+ });
29
+ }
30
+ exports.fileExists = fileExists;
31
+ async function hasGit(path) {
32
+ const exists = await directoryExists(path);
33
+ if (!exists) {
34
+ return false;
35
+ }
36
+ const results = await node_fs_1.promises.readdir(path, { withFileTypes: true });
37
+ const directories = results.filter(d => d.isDirectory());
38
+ return directories.some(d => d.name === '.git');
39
+ }
40
+ exports.hasGit = hasGit;
41
+ //# sourceMappingURL=fs-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-utils.js","sourceRoot":"","sources":["../../src/utils/fs-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAEzB,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,OAAO,kBAAQ,CAAC,IAAI,CAAC,IAA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+ }
6
+ interface FillResult {
7
+ username: string;
8
+ password: string;
9
+ }
10
+ export declare function fill(url: string): Promise<FillResult | null>;
11
+ export declare function reject(url: string): Promise<void>;
12
+ export declare function approve(options: ApproveOptions): Promise<void>;
13
+ export declare function hostPrefix(hostname: string): string;
14
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hostPrefix = exports.approve = exports.reject = exports.fill = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const execa_1 = tslib_1.__importDefault(require("execa"));
6
+ const credentialRE = /username=([^\n]+)\npassword=([^\n]+)\n/;
7
+ function parse(result) {
8
+ const match = result.match(credentialRE);
9
+ if (!match) {
10
+ return null;
11
+ }
12
+ const username = match[1];
13
+ const password = match[2];
14
+ if (username.startsWith('Username for ')) {
15
+ return null;
16
+ }
17
+ return { username, password };
18
+ }
19
+ const fillOpts = (url) => ({
20
+ stripEof: false,
21
+ reject: false,
22
+ encoding: 'utf8',
23
+ input: url ? `url=${url}\n\n` : '\n',
24
+ env: Object.assign({ GIT_TERMINAL_PROMPT: '0' }, process.env),
25
+ });
26
+ const rejectOpts = (url) => ({
27
+ stripEof: false,
28
+ encoding: 'utf8',
29
+ input: url ? `url=${url}\n\n` : '\n',
30
+ });
31
+ const approveOpts = ({ username, password, url }) => ({
32
+ stripEof: false,
33
+ encoding: 'utf8',
34
+ input: (url ? `url=${url}\n` : '') +
35
+ `username=${username}\npassword=${password}\n\n`,
36
+ });
37
+ async function fill(url) {
38
+ const result = await (0, execa_1.default)('git', ['credential', 'fill'], fillOpts(url));
39
+ if (result.exitCode !== 0) {
40
+ return null;
41
+ }
42
+ return parse(result.stdout);
43
+ }
44
+ exports.fill = fill;
45
+ async function reject(url) {
46
+ await (0, execa_1.default)('git', ['credential', 'reject'], rejectOpts(url));
47
+ }
48
+ exports.reject = reject;
49
+ async function approve(options) {
50
+ await (0, execa_1.default)('git', ['credential', 'approve'], approveOpts(options));
51
+ }
52
+ exports.approve = approve;
53
+ function hostPrefix(hostname) {
54
+ if (hostname.toLocaleLowerCase() === 'localhost') {
55
+ return 'http://localhost/';
56
+ }
57
+ return `https://${hostname}/`;
58
+ }
59
+ exports.hostPrefix = hostPrefix;
60
+ //# sourceMappingURL=git-credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-credential.js","sourceRoot":"","sources":["../../src/utils/git-credential.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AAEzB,MAAM,YAAY,GAAG,wCAAwC,CAAA;AAa7D,SAAS,KAAK,CAAC,MAAc;IAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IAEzB,IAAI,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACxC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,CAAA;AAC7B,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC;IACjC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI;IACpC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAC,mBAAmB,EAAE,GAAG,EAAC,EAAE,OAAO,CAAC,GAAG,CAAC;CAC5D,CAAC,CAAA;AAEF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC;IACnC,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,GAAG,CAAC,CAAC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CAMC"}
@@ -0,0 +1,8 @@
1
+ import { SimpleGit } from 'simple-git';
2
+ export declare function getRepoUrl(directory: string): Promise<string>;
3
+ interface GitRunnerParams {
4
+ gitProtocol: string;
5
+ directory: string;
6
+ }
7
+ export declare function gitRunner({ directory, gitProtocol, }: GitRunnerParams): Promise<SimpleGit>;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitRunner = exports.getRepoUrl = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const simple_git_1 = tslib_1.__importDefault(require("simple-git"));
6
+ const npmlog_1 = require("npmlog");
7
+ const GIT_SSH_COMMAND = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no';
8
+ // noinspection JSUnusedGlobalSymbols
9
+ async function getRepoUrl(directory) {
10
+ return (0, simple_git_1.default)()
11
+ .cwd(directory)
12
+ .listRemote(['--get-url']);
13
+ }
14
+ exports.getRepoUrl = getRepoUrl;
15
+ async function gitRunner({ directory = process.cwd(), gitProtocol = 'https', }) {
16
+ const git = (0, simple_git_1.default)({
17
+ baseDir: directory,
18
+ })
19
+ .outputHandler((command, stdout, stderr, args) => {
20
+ (0, npmlog_1.log)('silly', 'git', `${command} ${args.join(' ')}`);
21
+ stdout.on('data', chunk => {
22
+ (0, npmlog_1.log)('info', 'git', chunk === null || chunk === void 0 ? void 0 : chunk.toString());
23
+ });
24
+ });
25
+ if (gitProtocol === 'ssh') {
26
+ return git.env(Object.assign(Object.assign({}, process.env), { GIT_SSH_COMMAND }));
27
+ }
28
+ return git;
29
+ }
30
+ exports.gitRunner = gitRunner;
31
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":";;;;AAAA,oEAA+C;AAC/C,mCAA0B;AAE1B,MAAM,eAAe,GAAG,iEAAiE,CAAA;AAEzF,qCAAqC;AAC9B,KAAK,UAAU,UAAU,CAAC,SAAiB;IAChD,OAAO,IAAA,oBAAS,GAAE;SACjB,GAAG,CAAC,SAAS,CAAC;SACd,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;AAC5B,CAAC;AAJD,gCAIC;AAOM,KAAK,UAAU,SAAS,CAAC,EAC9B,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,EACzB,WAAW,GAAG,OAAO,GACL;IAChB,MAAM,GAAG,GAAG,IAAA,oBAAS,EAAC;QACpB,OAAO,EAAE,SAAS;KACnB,CAAC;SACD,aAAa,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC/C,IAAA,YAAG,EAAC,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACnD,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YACxB,IAAA,YAAG,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,IAAI,WAAW,KAAK,KAAK,EAAE;QACzB,OAAO,GAAG,CAAC,GAAG,iCAAK,OAAO,CAAC,GAAG,KAAE,eAAe,IAAE,CAAA;KAClD;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAnBD,8BAmBC"}
@@ -0,0 +1,7 @@
1
+ export * from './fs-utils';
2
+ export * from './netrc';
3
+ export * from './git';
4
+ export * from './strings';
5
+ export * from './streams';
6
+ export * from './git-credential';
7
+ export * from './credential-helper';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./fs-utils"), exports);
5
+ tslib_1.__exportStar(require("./netrc"), exports);
6
+ tslib_1.__exportStar(require("./git"), exports);
7
+ tslib_1.__exportStar(require("./strings"), exports);
8
+ tslib_1.__exportStar(require("./streams"), exports);
9
+ tslib_1.__exportStar(require("./git-credential"), exports);
10
+ tslib_1.__exportStar(require("./credential-helper"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,kDAAuB;AACvB,gDAAqB;AACrB,oDAAyB;AACzB,oDAAyB;AACzB,2DAAgC;AAChC,8DAAmC"}
@@ -0,0 +1,4 @@
1
+ import type { NetrcEntry } from '../models';
2
+ export declare function saveToken(entry: NetrcEntry): Promise<void>;
3
+ export declare function getToken(host: string): Promise<NetrcEntry | null>;
4
+ export declare function deleteToken(host: string): Promise<void>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteToken = exports.getToken = exports.saveToken = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const netrc_parser_1 = tslib_1.__importDefault(require("netrc-parser"));
6
+ const protector_1 = require("./protector");
7
+ async function saveToken(entry) {
8
+ const host = entry.host;
9
+ await netrc_parser_1.default.load();
10
+ if (!netrc_parser_1.default.machines[host])
11
+ netrc_parser_1.default.machines[host] = {};
12
+ netrc_parser_1.default.machines[host].login = entry.login;
13
+ netrc_parser_1.default.machines[host].password = new protector_1.Protector().encrypt(entry.password);
14
+ delete netrc_parser_1.default.machines[host].method;
15
+ delete netrc_parser_1.default.machines[host].org;
16
+ if (netrc_parser_1.default.machines._tokens) {
17
+ for (const token of netrc_parser_1.default.machines._tokens) {
18
+ if (host === token.host) {
19
+ token.internalWhitespace = '\n ';
20
+ }
21
+ }
22
+ }
23
+ await netrc_parser_1.default.save();
24
+ }
25
+ exports.saveToken = saveToken;
26
+ async function getToken(host) {
27
+ await netrc_parser_1.default.load();
28
+ if (!netrc_parser_1.default.machines[host]) {
29
+ return null;
30
+ }
31
+ let pwd = netrc_parser_1.default.machines[host].password;
32
+ if (pwd) {
33
+ pwd = new protector_1.Protector().decrypt(pwd);
34
+ }
35
+ return {
36
+ host: host,
37
+ login: netrc_parser_1.default.machines[host].login || '',
38
+ password: pwd || '',
39
+ };
40
+ }
41
+ exports.getToken = getToken;
42
+ async function deleteToken(host) {
43
+ await netrc_parser_1.default.load();
44
+ delete netrc_parser_1.default.machines[host];
45
+ await netrc_parser_1.default.save();
46
+ }
47
+ exports.deleteToken = deleteToken;
48
+ //# sourceMappingURL=netrc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"netrc.js","sourceRoot":"","sources":["../../src/utils/netrc.ts"],"names":[],"mappings":";;;;AACA,wEAAgC;AAChC,2CAAqC;AAE9B,KAAK,UAAU,SAAS,CAAC,KAAiB;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACvB,MAAM,sBAAK,CAAC,IAAI,EAAE,CAAA;IAClB,IAAI,CAAC,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACpD,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;IACxC,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI,qBAAS,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACvE,OAAO,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;IAClC,OAAO,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAA;IAE/B,IAAI,sBAAK,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC1B,KAAK,MAAM,KAAK,IAAK,sBAAK,CAAC,QAAQ,CAAC,OAAe,EAAE;YACnD,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE;gBACvB,KAAK,CAAC,kBAAkB,GAAG,MAAM,CAAA;aAClC;SACF;KACF;IAED,MAAM,sBAAK,CAAC,IAAI,EAAE,CAAA;AACpB,CAAC;AAlBD,8BAkBC;AAEM,KAAK,UAAU,QAAQ,CAAC,IAAY;IACzC,MAAM,sBAAK,CAAC,IAAI,EAAE,CAAA;IAClB,IAAI,CAAC,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IAED,IAAI,GAAG,GAAG,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAA;IACvC,IAAI,GAAG,EAAE;QACP,GAAG,GAAG,IAAI,qBAAS,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;KACnC;IAED,OAAO;QACL,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;QACvC,QAAQ,EAAE,GAAG,IAAI,EAAE;KACpB,CAAA;AACH,CAAC;AAhBD,4BAgBC;AAEM,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,MAAM,sBAAK,CAAC,IAAI,EAAE,CAAA;IAClB,OAAO,sBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3B,MAAM,sBAAK,CAAC,IAAI,EAAE,CAAA;AACpB,CAAC;AAJD,kCAIC"}
@@ -0,0 +1,9 @@
1
+ export declare class Protector {
2
+ private key;
3
+ constructor();
4
+ private static stretchString;
5
+ private static keyFromPassword;
6
+ encrypt(sourceData: string): string;
7
+ decrypt(encryptedData: string): string;
8
+ hash(sourceData: string): number;
9
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Protector = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const node_os_1 = require("node:os");
6
+ class Protector {
7
+ constructor() {
8
+ const info = (0, node_os_1.userInfo)();
9
+ const uid = info.username;
10
+ this.key = Protector.keyFromPassword(uid);
11
+ }
12
+ // Uses the PBKDF2 algorithm to stretch the string 's' to an arbitrary size,
13
+ // in a way that is completely deterministic yet impossible to guess without
14
+ // knowing the original string
15
+ static stretchString(s, salt, outputLength) {
16
+ return (0, node_crypto_1.pbkdf2Sync)(s, salt, 100000, outputLength, 'sha512');
17
+ }
18
+ // Stretches the password in order to generate a key (for encrypting)
19
+ // and a large salt (for hashing)
20
+ static keyFromPassword(password) {
21
+ // We need 24 bytes for the key, and another 48 bytes for the salt
22
+ const keyPlusHashingSalt = Protector.stretchString(password, 'salt', 24 + 48);
23
+ return {
24
+ cipherKey: keyPlusHashingSalt.slice(0, 24),
25
+ hashingSalt: keyPlusHashingSalt.slice(24),
26
+ };
27
+ }
28
+ // Encrypts data using the key generated using the 'keyFromPassword' function
29
+ encrypt(sourceData) {
30
+ const iv = Buffer.alloc(16, 0); // Initialization vector
31
+ const cipher = (0, node_crypto_1.createCipheriv)('aes-192-cbc', this.key.cipherKey, iv);
32
+ let encrypted = cipher.update(sourceData, 'ascii', 'base64');
33
+ encrypted += cipher.final('base64');
34
+ return encrypted;
35
+ }
36
+ // Decrypts data using the key generated using the 'keyFromPassword' function
37
+ decrypt(encryptedData) {
38
+ const iv = Buffer.alloc(16, 0); // Initialization vector
39
+ const decipher = (0, node_crypto_1.createDecipheriv)('aes-192-cbc', this.key.cipherKey, iv);
40
+ let decrypted = decipher.update(encryptedData, 'base64', 'ascii');
41
+ decrypted += decipher.final('ascii');
42
+ return decrypted;
43
+ }
44
+ // Computes a unique (integer) hash from the given data, using the salt
45
+ // we generated from the password (using 'keyFromPassword')
46
+ hash(sourceData) {
47
+ const hashBuffer = Protector.stretchString(sourceData, this.key.hashingSalt, 6);
48
+ return hashBuffer.readUIntLE(0, 6);
49
+ }
50
+ }
51
+ exports.Protector = Protector;
52
+ //# sourceMappingURL=protector.js.map
@@ -0,0 +1 @@
1
+ {"version":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KAAK,CAAC,QAAQ,CAAC,CAAA;QACnC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,6EAA6E;IAC7E,OAAO,CAAC,aAAqB;QAC3B,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA,CAAC,wBAAwB;QACvD,MAAM,QAAQ,GAAG,IAAA,8BAAgB,EAAC,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QACxE,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;QACjE,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACpC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,uEAAuE;IACvE,2DAA2D;IAC3D,IAAI,CAAC,UAAkB;QACrB,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAC/E,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACpC,CAAC;CACF;AAnDD,8BAmDC"}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { ReadableOptions as ReadableNodeStreamOptions, WritableOptions as WritableNodeStreamOptions } from 'node:stream';
4
+ export interface ReadableStreamOptions extends Omit<ReadableNodeStreamOptions, 'read'> {
5
+ /**
6
+ The amount of data to stream in bytes.
7
+
8
+ Set it to `Infinity` to make it produce data until you manually destroy the stream.
9
+
10
+ @default 0
11
+ */
12
+ readonly size?: number;
13
+ }
14
+ export declare type WritableStreamOptions = Omit<WritableNodeStreamOptions, 'write'>;
15
+ export declare function readableNoopStream({ size, ...options }: ReadableStreamOptions): NodeJS.ReadableStream;
16
+ export declare function writableNoopStream(options?: WritableStreamOptions): NodeJS.WritableStream;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writableNoopStream = exports.readableNoopStream = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_stream_1 = require("node:stream");
6
+ const node_buffer_1 = require("node:buffer");
7
+ // noinspection JSUnusedGlobalSymbols
8
+ function readableNoopStream(_a) {
9
+ var { size = 0 } = _a, options = tslib_1.__rest(_a, ["size"]);
10
+ let producedSize = 0;
11
+ return new node_stream_1.Readable(Object.assign(Object.assign({}, options), { read(readSize) {
12
+ let shouldEnd = false;
13
+ if ((producedSize + readSize) >= size) {
14
+ readSize = size - producedSize;
15
+ shouldEnd = true;
16
+ }
17
+ setImmediate(() => {
18
+ if (size === 0) {
19
+ this.push(null);
20
+ }
21
+ producedSize += readSize;
22
+ this.push(node_buffer_1.Buffer.alloc(readSize));
23
+ if (shouldEnd) {
24
+ this.push(null);
25
+ }
26
+ });
27
+ } }));
28
+ }
29
+ exports.readableNoopStream = readableNoopStream;
30
+ // noinspection JSUnusedGlobalSymbols
31
+ function writableNoopStream(options) {
32
+ return new node_stream_1.Writable(Object.assign(Object.assign({}, options), { write(chunk, encding, callback) {
33
+ setImmediate(callback);
34
+ } }));
35
+ }
36
+ exports.writableNoopStream = writableNoopStream;
37
+ //# sourceMappingURL=streams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.js","sourceRoot":"","sources":["../../src/utils/streams.ts"],"names":[],"mappings":";;;;AAAA,6CAGoB;AACpB,6CAAkC;AAoBlC,qCAAqC;AACrC,SAAgB,kBAAkB,CAAC,EAA6C;QAA7C,EAAC,IAAI,GAAG,CAAC,OAAoC,EAA/B,OAAO,sBAArB,QAAsB,CAAD;IACtD,IAAI,YAAY,GAAG,CAAC,CAAA;IAEpB,OAAO,IAAI,sBAAc,iCACpB,OAAO,KACV,IAAI,CAAC,QAAQ;YACX,IAAI,SAAS,GAAG,KAAK,CAAA;YAErB,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE;gBACrC,QAAQ,GAAG,IAAI,GAAG,YAAY,CAAA;gBAC9B,SAAS,GAAG,IAAI,CAAA;aACjB;YAED,YAAY,CAAC,GAAG,EAAE;gBAChB,IAAI,IAAI,KAAK,CAAC,EAAE;oBACd,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;iBAChB;gBAED,YAAY,IAAI,QAAQ,CAAA;gBACxB,IAAI,CAAC,IAAI,CAAC,oBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;gBAEjC,IAAI,SAAS,EAAE;oBACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;iBAChB;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,IACD,CAAA;AACJ,CAAC;AA3BD,gDA2BC;AAED,qCAAqC;AACrC,SAAgB,kBAAkB,CAAC,OAA+B;IAChE,OAAO,IAAI,sBAAc,iCACpB,OAAO,KACV,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ;YAC5B,YAAY,CAAC,QAAQ,CAAC,CAAA;QACxB,CAAC,IACD,CAAA;AACJ,CAAC;AAPD,gDAOC"}
@@ -0,0 +1 @@
1
+ export declare function trimSuffix(toTrim: string, trim: string): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trimSuffix = void 0;
4
+ function trimSuffix(toTrim, trim) {
5
+ if (!toTrim || !trim) {
6
+ return toTrim;
7
+ }
8
+ const index = toTrim.lastIndexOf(trim);
9
+ if (index === -1 || (index + trim.length) !== toTrim.length) {
10
+ return toTrim;
11
+ }
12
+ return toTrim.slice(0, Math.max(0, index));
13
+ }
14
+ exports.trimSuffix = trimSuffix;
15
+ //# sourceMappingURL=strings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,MAAc,EAAE,IAAY;IACrD,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE;QACpB,OAAO,MAAM,CAAA;KACd;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACtC,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE;QAC3D,OAAO,MAAM,CAAA;KACd;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;AAC5C,CAAC;AAXD,gCAWC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "author": "Swimlane",
3
+ "bugs": {
4
+ "url": "https://github.com/swimlane/turbine-sdk/issues"
5
+ },
6
+ "dependencies": {
7
+ "@oclif/core": "1.16.4",
8
+ "execa": "5.1.1",
9
+ "fs-extra": "10.0.1",
10
+ "git-credential-node": "1.1.0",
11
+ "netrc-parser": "3.1.6",
12
+ "npmlog": "6.0.1",
13
+ "simple-git": "3.5.0"
14
+ },
15
+ "description": "Core library for sw-tsdk",
16
+ "directories": {
17
+ "lib": "lib"
18
+ },
19
+ "engines": {
20
+ "node": ">=16.0.0"
21
+ },
22
+ "files": [
23
+ "lib",
24
+ "/yarn.lock"
25
+ ],
26
+ "homepage": "https://github.com/swimlane/turbine-sdk#readme",
27
+ "license": "ISC",
28
+ "main": "lib/index.js",
29
+ "name": "@sw-tsdk/core",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/swimlane/turbine-sdk.git"
36
+ },
37
+ "scripts": {
38
+ "build": "rm -rf lib && tsc",
39
+ "lint": "eslint . --ext .ts --config .eslintrc",
40
+ "test": "echo \"Error: run tests from root\" && exit 1"
41
+ },
42
+ "types": "lib/index.d.ts",
43
+ "version": "0.1.1-next.23+038e7a6",
44
+ "gitHead": "038e7a68d45b2d93f39c7f7b2edce9798019007e"
45
+ }