@gadgetinc/ggt 0.1.16 → 0.1.18
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/README.md +6 -6
- package/lib/commands/help.d.ts +2 -2
- package/lib/commands/help.js +2 -1
- package/lib/commands/help.js.map +1 -1
- package/lib/commands/list.d.ts +1 -0
- package/lib/commands/list.js +15 -6
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/sync.d.ts +88 -6
- package/lib/commands/sync.js +196 -122
- package/lib/commands/sync.js.map +1 -1
- package/lib/utils/base-command.d.ts +16 -10
- package/lib/utils/base-command.js +27 -14
- package/lib/utils/base-command.js.map +1 -1
- package/lib/utils/client.d.ts +6 -0
- package/lib/utils/client.js +6 -0
- package/lib/utils/client.js.map +1 -1
- package/lib/utils/context.d.ts +3 -2
- package/lib/utils/context.js +3 -2
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/fs-utils.d.ts +2 -2
- package/lib/utils/fs-utils.js +3 -3
- package/lib/utils/fs-utils.js.map +1 -1
- package/lib/utils/promise.d.ts +35 -0
- package/lib/utils/promise.js +114 -0
- package/lib/utils/promise.js.map +1 -0
- package/npm-shrinkwrap.json +17320 -11197
- package/oclif.manifest.json +1 -1
- package/package.json +23 -23
package/lib/utils/fs-utils.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ignoreEnoent = exports.isEmptyDir = exports.isEmptyDirSync = exports.walkDirSync = exports.walkDir = exports.
|
|
3
|
+
exports.ignoreEnoent = exports.isEmptyDir = exports.isEmptyDirSync = exports.walkDirSync = exports.walkDir = exports.FSIgnorer = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
7
7
|
const ignore_1 = tslib_1.__importDefault(require("ignore"));
|
|
8
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
9
|
const debug = (0, debug_1.default)("ggt:fs-utils");
|
|
10
|
-
class
|
|
10
|
+
class FSIgnorer {
|
|
11
11
|
constructor(_rootDir, _alwaysIgnore) {
|
|
12
12
|
Object.defineProperty(this, "_rootDir", {
|
|
13
13
|
enumerable: true,
|
|
@@ -53,7 +53,7 @@ class Ignorer {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
exports.
|
|
56
|
+
exports.FSIgnorer = FSIgnorer;
|
|
57
57
|
async function* walkDir(dir, options = {}) {
|
|
58
58
|
if (options.ignorer?.ignores(dir))
|
|
59
59
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-utils.js","sourceRoot":"/","sources":["utils/fs-utils.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,gEAA0B;AAE1B,4DAA4B;AAC5B,wDAAwB;AAExB,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,cAAc,CAAC,CAAC;AAEpC,MAAa,
|
|
1
|
+
{"version":3,"file":"fs-utils.js","sourceRoot":"/","sources":["utils/fs-utils.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,gEAA0B;AAE1B,4DAA4B;AAC5B,wDAAwB;AAExB,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,cAAc,CAAC,CAAC;AAEpC,MAAa,SAAS;IAKpB,YAA6B,QAAgB,EAAmB,aAAuB;QAA3E;;;;mBAAiB,QAAQ;WAAQ;QAAE;;;;mBAAiB,aAAa;WAAU;QAJ9E;;;;mBAAW,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC;WAAC;QAEhD;;;;;WAAkB;QAGxB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,QAAgB;QACtB,MAAM,QAAQ,GAAG,cAAI,CAAC,U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b;QACD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAXD,wCAWC;AAEM,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,IAAI,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE;IACzE,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;KAC3B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;SACb;QACD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAXD,gCAWC;AAED,SAAgB,YAAY,CAAC,KAAU;IACrC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC3B,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO;KACR;IACD,MAAM,KAAK,CAAC;AACd,CAAC;AAND,oCAMC","sourcesContent":["import Debug from \"debug\";\nimport fs from \"fs-extra\";\nimport type { Ignore } from \"ignore\";\nimport ignore from \"ignore\";\nimport path from \"path\";\n\nconst debug = Debug(\"ggt:fs-utils\");\n\nexport class FSIgnorer {\n readonly filepath = path.join(this._rootDir, \".ignore\");\n\n private _ignorer!: Ignore;\n\n constructor(private readonly _rootDir: string, private readonly _alwaysIgnore: string[]) {\n this.reload();\n }\n\n ignores(filepath: string): boolean {\n const relative = path.isAbsolute(filepath) ? path.relative(this._rootDir, filepath) : filepath;\n if (relative == \"\") return false;\n return this._ignorer.ignores(relative);\n }\n\n reload(): void {\n this._ignorer = ignore();\n this._ignorer.add(this._alwaysIgnore);\n\n try {\n this._ignorer.add(fs.readFileSync(this.filepath, \"utf-8\"));\n debug(\"reloaded ignore rules from %s\", this.filepath);\n } catch (error) {\n ignoreEnoent(error);\n }\n }\n}\n\nexport interface WalkDirOptions {\n ignorer?: FSIgnorer;\n}\n\nexport async function* walkDir(dir: string, options: WalkDirOptions = {}): AsyncGenerator<string> {\n if (options.ignorer?.ignores(dir)) return;\n\n if (await isEmptyDir(dir)) {\n yield `${dir}/`;\n return;\n }\n\n for await (const entry of await fs.opendir(dir)) {\n const filepath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkDir(filepath, options);\n } else if (entry.isFile() && !options.ignorer?.ignores(filepath)) {\n yield filepath;\n }\n }\n}\n\nexport function* walkDirSync(dir: string, options: WalkDirOptions = {}): Generator<string> {\n if (options.ignorer?.ignores(dir)) return;\n\n if (isEmptyDirSync(dir)) {\n yield `${dir}/`;\n return;\n }\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const filepath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkDirSync(filepath, options);\n } else if (entry.isFile() && !options.ignorer?.ignores(filepath)) {\n yield filepath;\n }\n }\n}\n\nexport function isEmptyDirSync(dir: string, opts = { ignoreEnoent: true }): boolean {\n try {\n const files = fs.readdirSync(dir);\n return files.length === 0;\n } catch (error) {\n if (opts.ignoreEnoent) {\n ignoreEnoent(error);\n return true;\n }\n throw error;\n }\n}\n\nexport async function isEmptyDir(dir: string, opts = { ignoreEnoent: true }): Promise<boolean> {\n try {\n const files = await fs.readdir(dir);\n return files.length === 0;\n } catch (error) {\n if (opts.ignoreEnoent) {\n ignoreEnoent(error);\n return true;\n }\n throw error;\n }\n}\n\nexport function ignoreEnoent(error: any): void {\n if (error.code === \"ENOENT\") {\n debug(\"ignoring ENOENT error %s\", error.path);\n return;\n }\n throw error;\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long lived references to Promises stress the garbage collector in JS. Instead of caching resolved Promises, we cache
|
|
3
|
+
* these little data objects instead which reference the resolution or rejection of the Promise, allowing the Promise
|
|
4
|
+
* object to be free'd.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PromiseWrapper<T> {
|
|
7
|
+
resolution?: T;
|
|
8
|
+
rejection?: any;
|
|
9
|
+
pendingPromise?: Promise<T>;
|
|
10
|
+
constructor(promise: Promise<T>);
|
|
11
|
+
unwrap(): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A promise that can be resolved or rejected from outside its callback.
|
|
15
|
+
*
|
|
16
|
+
* This is typically used when you want to await a promise that is resolved or rejected from outside the current scope,
|
|
17
|
+
* such as from an event handler.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const signal = new PromiseSignal();
|
|
21
|
+
* process.on("SIGINT", () => {
|
|
22
|
+
* signal.resolve();
|
|
23
|
+
* });
|
|
24
|
+
* await signal;
|
|
25
|
+
*/
|
|
26
|
+
export declare class PromiseSignal<T = void> implements Promise<T> {
|
|
27
|
+
readonly [Symbol.toStringTag]: string;
|
|
28
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
29
|
+
reject: (reason?: any) => void;
|
|
30
|
+
private _promise;
|
|
31
|
+
constructor();
|
|
32
|
+
then<R = T, E = never>(onfulfilled?: (value: T) => R | PromiseLike<R>, onrejected?: (reason: any) => E | PromiseLike<E>): Promise<R | E>;
|
|
33
|
+
catch<E = never>(onrejected?: (reason: any) => E | PromiseLike<E>): Promise<T | E>;
|
|
34
|
+
finally(onfinally?: () => void): Promise<T>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PromiseSignal = exports.PromiseWrapper = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Long lived references to Promises stress the garbage collector in JS. Instead of caching resolved Promises, we cache
|
|
7
|
+
* these little data objects instead which reference the resolution or rejection of the Promise, allowing the Promise
|
|
8
|
+
* object to be free'd.
|
|
9
|
+
*/
|
|
10
|
+
class PromiseWrapper {
|
|
11
|
+
constructor(promise) {
|
|
12
|
+
Object.defineProperty(this, "resolution", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "rejection", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "pendingPromise", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
this.pendingPromise = promise;
|
|
31
|
+
promise
|
|
32
|
+
.then((res) => {
|
|
33
|
+
this.resolution = res;
|
|
34
|
+
return res;
|
|
35
|
+
})
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
this.rejection = err;
|
|
38
|
+
})
|
|
39
|
+
.finally(() => {
|
|
40
|
+
delete this.pendingPromise;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async unwrap() {
|
|
44
|
+
if (this.resolution) {
|
|
45
|
+
return this.resolution;
|
|
46
|
+
}
|
|
47
|
+
else if (this.rejection) {
|
|
48
|
+
throw this.rejection;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
52
|
+
return await this.pendingPromise;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.PromiseWrapper = PromiseWrapper;
|
|
57
|
+
/**
|
|
58
|
+
* A promise that can be resolved or rejected from outside its callback.
|
|
59
|
+
*
|
|
60
|
+
* This is typically used when you want to await a promise that is resolved or rejected from outside the current scope,
|
|
61
|
+
* such as from an event handler.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const signal = new PromiseSignal();
|
|
65
|
+
* process.on("SIGINT", () => {
|
|
66
|
+
* signal.resolve();
|
|
67
|
+
* });
|
|
68
|
+
* await signal;
|
|
69
|
+
*/
|
|
70
|
+
class PromiseSignal {
|
|
71
|
+
constructor() {
|
|
72
|
+
Object.defineProperty(this, _a, {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "resolve", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "reject", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(this, "_promise", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
this._promise = new PromiseWrapper(new Promise((resolve, reject) => {
|
|
97
|
+
this.resolve = resolve;
|
|
98
|
+
this.reject = reject;
|
|
99
|
+
}));
|
|
100
|
+
this[Symbol.toStringTag] = String(this._promise.pendingPromise);
|
|
101
|
+
}
|
|
102
|
+
then(onfulfilled, onrejected) {
|
|
103
|
+
return this._promise.unwrap().then(onfulfilled, onrejected);
|
|
104
|
+
}
|
|
105
|
+
catch(onrejected) {
|
|
106
|
+
return this._promise.unwrap().catch(onrejected);
|
|
107
|
+
}
|
|
108
|
+
finally(onfinally) {
|
|
109
|
+
return this._promise.unwrap().finally(onfinally);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.PromiseSignal = PromiseSignal;
|
|
113
|
+
_a = Symbol.toStringTag;
|
|
114
|
+
//# sourceMappingURL=promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"/","sources":["utils/promise.ts"],"names":[],"mappings":";;;;AAAA;;;;GAIG;AACH,MAAa,cAA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QACrH,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAY,UAAgD;QAC/D,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,CAAC,SAAsB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACF;AA9BD,sCA8BC;KA7BW,MAAM,CAAC,WAAW","sourcesContent":["/**\n * Long lived references to Promises stress the garbage collector in JS. Instead of caching resolved Promises, we cache\n * these little data objects instead which reference the resolution or rejection of the Promise, allowing the Promise\n * object to be free'd.\n */\nexport class PromiseWrapper<T> {\n resolution?: T;\n rejection?: any;\n pendingPromise?: Promise<T>;\n\n constructor(promise: Promise<T>) {\n this.pendingPromise = promise;\n\n promise\n .then((res) => {\n this.resolution = res;\n return res;\n })\n .catch((err) => {\n this.rejection = err;\n })\n .finally(() => {\n delete this.pendingPromise;\n });\n }\n\n async unwrap(): Promise<T> {\n if (this.resolution) {\n return this.resolution;\n } else if (this.rejection) {\n throw this.rejection;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return await this.pendingPromise!;\n }\n }\n}\n\n/**\n * A promise that can be resolved or rejected from outside its callback.\n *\n * This is typically used when you want to await a promise that is resolved or rejected from outside the current scope,\n * such as from an event handler.\n *\n * @example\n * const signal = new PromiseSignal();\n * process.on(\"SIGINT\", () => {\n * signal.resolve();\n * });\n * await signal;\n */\nexport class PromiseSignal<T = void> implements Promise<T> {\n readonly [Symbol.toStringTag]!: string;\n\n resolve!: (value: T | PromiseLike<T>) => void;\n reject!: (reason?: any) => void;\n\n private _promise: PromiseWrapper<T>;\n\n constructor() {\n this._promise = new PromiseWrapper<T>(\n new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n })\n );\n\n this[Symbol.toStringTag] = String(this._promise.pendingPromise);\n }\n\n then<R = T, E = never>(onfulfilled?: (value: T) => R | PromiseLike<R>, onrejected?: (reason: any) => E | PromiseLike<E>): Promise<R | E> {\n return this._promise.unwrap().then(onfulfilled, onrejected);\n }\n\n catch<E = never>(onrejected?: (reason: any) => E | PromiseLike<E>): Promise<T | E> {\n return this._promise.unwrap().catch(onrejected);\n }\n\n finally(onfinally?: () => void): Promise<T> {\n return this._promise.unwrap().finally(onfinally);\n }\n}\n"]}
|