zcatalyst-cli 1.25.3 → 1.26.1
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/lib/api-timer.d.ts +0 -1
- package/lib/apig-utils.d.ts +1 -1
- package/lib/apig-utils.js +1 -1
- package/lib/appsail-utils.js +6 -7
- package/lib/archiver.d.ts +0 -4
- package/lib/archiver.js +21 -11
- package/lib/authentication/constants/auth.js +1 -1
- package/lib/authentication/credential.js +3 -3
- package/lib/authentication/index.js +25 -14
- package/lib/authentication/login.d.ts +0 -2
- package/lib/authentication/login.js +23 -10
- package/lib/bin/catalyst.js +17 -7
- package/lib/client-utils.d.ts +3 -3
- package/lib/client-utils.js +2 -2
- package/lib/client.js +19 -9
- package/lib/code-deck.d.ts +0 -2
- package/lib/code-deck.js +4 -4
- package/lib/command_needs/config.js +1 -1
- package/lib/command_needs/rc.js +5 -2
- package/lib/commands/appsail/add.js +17 -7
- package/lib/commands/client/setup.js +17 -7
- package/lib/commands/config/set.js +5 -3
- package/lib/commands/deploy/appsail.js +37 -14
- package/lib/commands/deploy/index.js +88 -66
- package/lib/commands/deploy/slate.js +37 -14
- package/lib/commands/event/generate/integ.js +18 -9
- package/lib/commands/functions/add.js +17 -7
- package/lib/commands/functions/execute.js +17 -7
- package/lib/commands/functions/setup.js +17 -7
- package/lib/commands/functions/shell.js +17 -7
- package/lib/commands/iac/import.js +18 -8
- package/lib/commands/iac/pack.js +17 -7
- package/lib/commands/iac/status.js +17 -7
- package/lib/commands/index.js +20 -12
- package/lib/commands/init.js +17 -7
- package/lib/commands/login.js +17 -7
- package/lib/commands/logout.js +17 -7
- package/lib/commands/project/list.js +17 -7
- package/lib/commands/project/use.js +1 -0
- package/lib/commands/pull.js +17 -7
- package/lib/commands/run.js +17 -7
- package/lib/commands/serve.js +17 -7
- package/lib/commands/signals/generate/index.js +1 -1
- package/lib/commands/slate/create.js +17 -7
- package/lib/commands/slate/link.js +17 -7
- package/lib/commands/token/generate.js +17 -7
- package/lib/commands/token/list.js +17 -7
- package/lib/commands/token/revoke.js +17 -7
- package/lib/commands/zest/generate/index.js +21 -11
- package/lib/deploy/features/appsail/index.js +2 -3
- package/lib/deploy/features/appsail/pack.d.ts +0 -1
- package/lib/deploy/features/appsail/pack.js +2 -3
- package/lib/deploy/features/appsail/utils.js +7 -8
- package/lib/deploy/features/functions/languages/index.js +3 -4
- package/lib/deploy/features/index.js +17 -7
- package/lib/deploy/features/slate.js +11 -8
- package/lib/deploy/index.js +2 -2
- package/lib/deploy/util.d.ts +2 -0
- package/lib/deploy/util.js +3 -1
- package/lib/docs/commands/signals/generate/generate.toml +19 -0
- package/lib/docs/commands/slate/unlink.toml +9 -0
- package/lib/docs/fn-utils/lib/node.toml +4 -0
- package/lib/docs/init/dependencies/python/ensure-python.toml +4 -0
- package/lib/docs/serve/server/lib/slate/index.toml +20 -0
- package/lib/docs/slate-utils.toml +9 -0
- package/lib/endpoints/index.d.ts +2 -1
- package/lib/endpoints/index.js +88 -79
- package/lib/endpoints/lib/apig.d.ts +0 -1
- package/lib/endpoints/lib/apig.js +2 -2
- package/lib/endpoints/lib/applogic.d.ts +0 -1
- package/lib/endpoints/lib/applogic.js +2 -2
- package/lib/endpoints/lib/appsail.d.ts +1 -4
- package/lib/endpoints/lib/appsail.js +7 -7
- package/lib/endpoints/lib/client.d.ts +0 -1
- package/lib/endpoints/lib/code-deck.js +1 -1
- package/lib/endpoints/lib/common.d.ts +0 -2
- package/lib/endpoints/lib/ds-bulk.js +2 -2
- package/lib/endpoints/lib/env.js +2 -2
- package/lib/endpoints/lib/filestore.d.ts +0 -1
- package/lib/endpoints/lib/functions.d.ts +0 -1
- package/lib/endpoints/lib/functions.js +2 -2
- package/lib/endpoints/lib/git-hub.d.ts +0 -2
- package/lib/endpoints/lib/iac.d.ts +0 -3
- package/lib/endpoints/lib/iac.js +2 -2
- package/lib/endpoints/lib/project.d.ts +0 -1
- package/lib/endpoints/lib/project.js +2 -2
- package/lib/endpoints/lib/sdk.d.ts +0 -2
- package/lib/endpoints/lib/sdk.js +1 -1
- package/lib/endpoints/lib/slate.d.ts +0 -1
- package/lib/endpoints/lib/stratus.d.ts +0 -1
- package/lib/endpoints/lib/user.d.ts +0 -2
- package/lib/endpoints/lib/user.js +2 -1
- package/lib/error/context-help.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/event_generate/cache.js +4 -4
- package/lib/event_generate/custom.js +1 -2
- package/lib/event_generate/datastore.js +4 -4
- package/lib/event_generate/filestore.js +4 -4
- package/lib/event_generate/github.js +2 -2
- package/lib/event_generate/index.js +19 -11
- package/lib/event_generate/stratus.js +2 -2
- package/lib/event_generate/user.js +2 -2
- package/lib/event_generate/webapp.js +2 -2
- package/lib/execute/caller.d.ts +0 -1
- package/lib/execute/caller.js +20 -7
- package/lib/execute/index.js +27 -4
- package/lib/execute-script.js +22 -13
- package/lib/express_middlewares/auth-checker.js +2 -3
- package/lib/express_middlewares/project.d.ts +1 -1
- package/lib/fn-utils/index.js +17 -7
- package/lib/fn-utils/lib/browserLogic.js +4 -5
- package/lib/fn-utils/lib/common.d.ts +0 -1
- package/lib/fn-utils/lib/common.js +25 -26
- package/lib/fn-utils/lib/integ.js +2 -3
- package/lib/fn-utils/lib/java/classpath.js +2 -3
- package/lib/fn-utils/lib/java/compile.js +4 -4
- package/lib/fn-utils/lib/java/ensure-java-userconfig.d.ts +10 -0
- package/lib/fn-utils/lib/java/ensure-java-userconfig.js +45 -23
- package/lib/fn-utils/lib/java/index.d.ts +0 -1
- package/lib/fn-utils/lib/java/index.js +11 -11
- package/lib/fn-utils/lib/java/keywords.js +2 -2
- package/lib/fn-utils/lib/node.d.ts +1 -1
- package/lib/fn-utils/lib/node.js +67 -15
- package/lib/fn-utils/lib/python.js +29 -19
- package/lib/iac/status/util/index.d.ts +1 -1
- package/lib/init/dependencies/npm-install.js +2 -2
- package/lib/init/dependencies/python/ensure-python.d.ts +2 -2
- package/lib/init/dependencies/python/ensure-python.js +65 -58
- package/lib/init/dependencies/python/pip-install.d.ts +3 -5
- package/lib/init/dependencies/python/pip-install.js +14 -53
- package/lib/init/features/appsail/utils.js +21 -12
- package/lib/init/features/client/index.js +18 -9
- package/lib/init/features/client/initializers/angular.js +17 -7
- package/lib/init/features/client/initializers/basic.js +17 -7
- package/lib/init/features/client/initializers/lyte.js +17 -7
- package/lib/init/features/client/initializers/react.js +17 -7
- package/lib/init/features/index.js +29 -20
- package/lib/init/features/project.js +5 -5
- package/lib/init/features/slate/index.js +23 -11
- package/lib/init/util/client.js +23 -13
- package/lib/init/util/common.js +5 -6
- package/lib/init/util/project.js +1 -1
- package/lib/internal/api.d.ts +0 -3
- package/lib/internal/api.js +19 -9
- package/lib/internal/command.js +18 -9
- package/lib/migration/global/1.25.0.d.ts +2 -0
- package/lib/migration/global/1.25.0.js +28 -0
- package/lib/migration/index.js +20 -12
- package/lib/option-filter.js +19 -10
- package/lib/optional-import.js +19 -10
- package/lib/plugin-loader.d.ts +0 -2
- package/lib/plugin-loader.js +18 -8
- package/lib/port-resolver.js +10 -10
- package/lib/prompt/index.d.ts +3 -3
- package/lib/prompt/index.js +17 -7
- package/lib/prompt/types/file-path.d.ts +0 -1
- package/lib/prompt/types/search-box.d.ts +0 -1
- package/lib/prompt/types/tree.d.ts +1 -2
- package/lib/prompt/types/tree.js +10 -10
- package/lib/prompt/types/with-description.d.ts +0 -1
- package/lib/pull/features/functions/index.js +71 -52
- package/lib/pull/features/functions/languages.js +3 -4
- package/lib/pull/features/index.js +17 -7
- package/lib/repl-server.d.ts +0 -1
- package/lib/repl-server.js +9 -1
- package/lib/serve/features/apig.js +7 -1
- package/lib/serve/features/appsail.d.ts +1 -0
- package/lib/serve/features/appsail.js +51 -7
- package/lib/serve/features/index.js +22 -13
- package/lib/serve/index.js +17 -7
- package/lib/serve/server/index.d.ts +0 -2
- package/lib/serve/server/index.js +26 -12
- package/lib/serve/server/lib/appsail/index.js +27 -34
- package/lib/serve/server/lib/appsail/util.d.ts +11 -0
- package/lib/serve/server/lib/appsail/util.js +69 -0
- package/lib/serve/server/lib/java/index.js +18 -7
- package/lib/serve/server/lib/master/appsail.js +3 -4
- package/lib/serve/server/lib/master/functions.js +1 -2
- package/lib/serve/server/lib/master/index.d.ts +0 -1
- package/lib/serve/server/lib/master/index.js +5 -5
- package/lib/serve/server/lib/master/slate.js +1 -2
- package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
- package/lib/serve/server/lib/master/utils.d.ts +4 -8
- package/lib/serve/server/lib/master/utils.js +4 -6
- package/lib/serve/server/lib/master/web-client.js +1 -2
- package/lib/serve/server/lib/node/index.js +22 -11
- package/lib/serve/server/lib/node/server/browserlogic/utils/playwright-handler.js +1 -1
- package/lib/serve/server/lib/node/server/browserlogic/utils/puppeteer-handler.js +1 -1
- package/lib/serve/server/lib/node/server/browserlogic/utils/selenium-handler.js +2 -0
- package/lib/serve/server/lib/python/index.js +23 -14
- package/lib/serve/server/lib/slate/index.js +7 -0
- package/lib/serve/server/lib/slate/static-server.d.ts +0 -1
- package/lib/serve/server/lib/slate/static-server.js +5 -4
- package/lib/serve/server/lib/web_client/server.d.ts +0 -1
- package/lib/serve/server/lib/web_client/server.js +5 -4
- package/lib/shell/dependencies/http-functions.d.ts +0 -2
- package/lib/shell/dependencies/http-functions.js +7 -7
- package/lib/shell/dependencies/non-http-function/fn-execution-handler.d.ts +0 -2
- package/lib/shell/dependencies/non-http-function/fn-execution-handler.js +55 -24
- package/lib/shell/dependencies/non-http-function/fn-handler.d.ts +3 -3
- package/lib/shell/dependencies/non-http-function/fn-handler.js +54 -20
- package/lib/shell/dependencies/non-http-function/node.js +4 -4
- package/lib/shell/dependencies/non-http-function/python.d.ts +1 -1
- package/lib/shell/dependencies/non-http-function/python.js +11 -13
- package/lib/shell/dependencies/non-http-function/slave-manager.d.ts +0 -2
- package/lib/shell/dependencies/non-http-function/slave-manager.js +11 -7
- package/lib/shell/dependencies/tunnel-server.js +4 -4
- package/lib/shell/index.js +50 -3
- package/lib/shell/prepare/index.js +4 -3
- package/lib/shell/prepare/languages/index.js +18 -9
- package/lib/shell/prepare/languages/node.js +29 -19
- package/lib/shell/prepare/languages/python.js +6 -12
- package/lib/signals/index.js +19 -11
- package/lib/slate-utils.js +25 -16
- package/lib/throbber/index.d.ts +1 -2
- package/lib/throbber/index.js +5 -2
- package/lib/throbber/utils.d.ts +0 -1
- package/lib/throbber/utils.js +4 -5
- package/lib/userConfig.d.ts +14 -0
- package/lib/userConfig.js +15 -1
- package/lib/util_modules/config/index.js +17 -7
- package/lib/util_modules/config/lib/apig.d.ts +1 -0
- package/lib/util_modules/config/lib/apig.js +10 -5
- package/lib/util_modules/config/lib/appsail.js +7 -7
- package/lib/util_modules/config/lib/client.js +5 -6
- package/lib/util_modules/config/lib/functions.js +5 -6
- package/lib/util_modules/config/lib/slate.d.ts +2 -1
- package/lib/util_modules/config/lib/slate.js +27 -13
- package/lib/util_modules/config-store.d.ts +1 -1
- package/lib/util_modules/config-store.js +30 -13
- package/lib/util_modules/constants/lib/apig-rules.d.ts +1 -1
- package/lib/util_modules/constants/lib/dc-type.js +3 -3
- package/lib/util_modules/constants/lib/placeholders.d.ts +1 -1
- package/lib/util_modules/constants/lib/placeholders.js +1 -1
- package/lib/util_modules/constants/lib/urls.js +2 -9
- package/lib/util_modules/container.js +23 -14
- package/lib/util_modules/dc.js +3 -4
- package/lib/util_modules/env.d.ts +3 -0
- package/lib/util_modules/env.js +64 -4
- package/lib/util_modules/event-emitter.d.ts +9 -0
- package/lib/util_modules/event-emitter.js +68 -0
- package/lib/util_modules/fs/index.js +17 -7
- package/lib/util_modules/fs/lib/async.d.ts +0 -4
- package/lib/util_modules/fs/lib/async.js +46 -46
- package/lib/util_modules/fs/lib/sync.d.ts +1 -3
- package/lib/util_modules/fs/lib/sync.js +40 -30
- package/lib/util_modules/logger/index.js +12 -12
- package/lib/util_modules/logger/utils.d.ts +0 -4
- package/lib/util_modules/logger/utils.js +1 -1
- package/lib/util_modules/logger/winston.js +2 -2
- package/lib/util_modules/option.js +5 -6
- package/lib/util_modules/project.js +22 -23
- package/lib/util_modules/runtime-store.d.ts +2 -2
- package/lib/util_modules/server.d.ts +1 -2
- package/lib/util_modules/server.js +54 -15
- package/lib/util_modules/shell.d.ts +0 -3
- package/lib/util_modules/shell.js +5 -6
- package/lib/util_modules/toml.js +2 -3
- package/package.json +13 -13
- package/templates/init/functions/java/event/sample.java +5 -2
- package/templates/web-socket.txt +1 -1
- /package/lib/docs/{commands/event/generate → event_generate}/index.toml +0 -0
- /package/templates/init/functions/java/integ/convokraft/{Sample.java → sample.java} +0 -0
package/lib/util_modules/env.js
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
36
|
+
exports.getLocalAccessDomain = exports.isExtension = exports.isZCode = exports.isVsCode = exports.isWindows = exports.isMac = exports.isCI = void 0;
|
|
37
|
+
exports.isPrimaryShell = isPrimaryShell;
|
|
38
|
+
exports.envOverride = envOverride;
|
|
39
|
+
exports.getEnvVariable = getEnvVariable;
|
|
4
40
|
exports.isCI = process &&
|
|
5
41
|
!!(process.env.CI ||
|
|
6
42
|
process.env.CONTINUOUS_INTEGRATION ||
|
|
@@ -13,6 +49,8 @@ exports.isWindows = process &&
|
|
|
13
49
|
(process.platform === 'win32' ||
|
|
14
50
|
(process.env.OSTYPE !== undefined && /^(msys|cygwin)$/.test(process.env.OSTYPE)));
|
|
15
51
|
exports.isVsCode = process.env.ZCATALYST_VSCODE === 'true';
|
|
52
|
+
exports.isZCode = process.env.ZCODE === 'true';
|
|
53
|
+
exports.isExtension = exports.isVsCode || exports.isZCode;
|
|
16
54
|
function isPrimaryShell() {
|
|
17
55
|
if (!process || process.env.CATALYST_SUB_PROCESS) {
|
|
18
56
|
return false;
|
|
@@ -22,7 +60,6 @@ function isPrimaryShell() {
|
|
|
22
60
|
}
|
|
23
61
|
return true;
|
|
24
62
|
}
|
|
25
|
-
exports.isPrimaryShell = isPrimaryShell;
|
|
26
63
|
function envOverride(envname, value) {
|
|
27
64
|
var _a;
|
|
28
65
|
if (process.env[envname] !== undefined && ((_a = process.env[envname]) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
@@ -30,8 +67,31 @@ function envOverride(envname, value) {
|
|
|
30
67
|
}
|
|
31
68
|
return value;
|
|
32
69
|
}
|
|
33
|
-
exports.envOverride = envOverride;
|
|
34
70
|
function getEnvVariable(variable, fallback) {
|
|
35
71
|
return process.env[variable] || fallback;
|
|
36
72
|
}
|
|
37
|
-
|
|
73
|
+
let zcode;
|
|
74
|
+
if (exports.isZCode) {
|
|
75
|
+
const moduleName = 'zcode';
|
|
76
|
+
Promise.resolve(`${moduleName}`).then(s => __importStar(require(s))).then((_code) => {
|
|
77
|
+
zcode = _code;
|
|
78
|
+
})
|
|
79
|
+
.catch((er) => {
|
|
80
|
+
console.error('Unable to import ZCode: ', er);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const getLocalAccessDomain = (port, protocol = 'http') => {
|
|
84
|
+
var _a;
|
|
85
|
+
if (zcode) {
|
|
86
|
+
try {
|
|
87
|
+
const previewUrl = (_a = zcode.workspace) === null || _a === void 0 ? void 0 : _a.previewURL(port);
|
|
88
|
+
if (previewUrl)
|
|
89
|
+
return protocol === 'http' ? previewUrl : previewUrl.replace(/^http/, 'ws');
|
|
90
|
+
}
|
|
91
|
+
catch (er) {
|
|
92
|
+
console.error('Error getting previewURL from ZCode: ', er);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return protocol === 'http' ? `http://localhost:${port}` : `ws://localhost:${port}`;
|
|
96
|
+
};
|
|
97
|
+
exports.getLocalAccessDomain = getLocalAccessDomain;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
export declare class CatalystEventEmitter extends EventEmitter {
|
|
3
|
+
private listenerMap;
|
|
4
|
+
on(event: string, listener: Parameters<EventEmitter['on']>[1]): this;
|
|
5
|
+
once(event: string, listener: Parameters<EventEmitter['once']>[1]): this;
|
|
6
|
+
removeListener(event: string, listener: Parameters<EventEmitter['on']>[1]): this;
|
|
7
|
+
off(event: string, listener: Parameters<EventEmitter['off']>[1]): this;
|
|
8
|
+
emit(...args: Parameters<EventEmitter['emit']>): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.CatalystEventEmitter = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const error_1 = __importDefault(require("../error"));
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
class CatalystEventEmitter extends events_1.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.listenerMap = new WeakMap();
|
|
14
|
+
}
|
|
15
|
+
on(event, listener) {
|
|
16
|
+
const wrappedListener = (...args) => {
|
|
17
|
+
try {
|
|
18
|
+
listener(...args);
|
|
19
|
+
}
|
|
20
|
+
catch (er) {
|
|
21
|
+
throw error_1.default.getErrorInstance(er, {
|
|
22
|
+
message: 'Error when processing the <on> listener of ServerEvent: ' + event,
|
|
23
|
+
skipHelp: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
this.listenerMap.set(listener, wrappedListener);
|
|
28
|
+
super.on(event, wrappedListener);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
once(event, listener) {
|
|
32
|
+
const wrappedListener = (...args) => {
|
|
33
|
+
try {
|
|
34
|
+
listener(...args);
|
|
35
|
+
}
|
|
36
|
+
catch (er) {
|
|
37
|
+
throw error_1.default.getErrorInstance(er, {
|
|
38
|
+
message: 'Error when processing the <once> listener of ServerEvent: ' + event,
|
|
39
|
+
skipHelp: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
this.listenerMap.delete(listener);
|
|
43
|
+
};
|
|
44
|
+
this.listenerMap.set(listener, wrappedListener);
|
|
45
|
+
super.once(event, wrappedListener);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
removeListener(event, listener) {
|
|
49
|
+
const wrappedListener = this.listenerMap.get(listener);
|
|
50
|
+
if (wrappedListener) {
|
|
51
|
+
super.removeListener(event, wrappedListener);
|
|
52
|
+
this.listenerMap.delete(listener);
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
off(event, listener) {
|
|
57
|
+
return this.removeListener(event, listener);
|
|
58
|
+
}
|
|
59
|
+
emit(...args) {
|
|
60
|
+
const [event] = args;
|
|
61
|
+
if (event === 'error' && this.listenerCount('error') === 0) {
|
|
62
|
+
(0, logger_1.debug)('Unable to emit "error" event as no listeners are attached');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return super.emit(...args);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.CatalystEventEmitter = CatalystEventEmitter;
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.ASYNC = exports.SYNC = void 0;
|
|
27
37
|
const ASYNC = __importStar(require("./lib/async"));
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
1
|
import fs, { CopyFilterAsync, Stats } from 'fs-extra';
|
|
6
2
|
type OutputType = 'buffer' | 'utf8' | undefined;
|
|
7
3
|
type OutputByType<T> = T extends 'buffer' ? Buffer : string;
|
|
@@ -12,7 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.findAndReplace = void 0;
|
|
16
|
+
exports.isPathExists = isPathExists;
|
|
17
|
+
exports.dirExists = dirExists;
|
|
18
|
+
exports.fileExists = fileExists;
|
|
19
|
+
exports.getFileDetails = getFileDetails;
|
|
20
|
+
exports.readFile = readFile;
|
|
21
|
+
exports.tempFile = tempFile;
|
|
22
|
+
exports.writeFile = writeFile;
|
|
23
|
+
exports.dirList = dirList;
|
|
24
|
+
exports.walk = walk;
|
|
25
|
+
exports.ensureFile = ensureFile;
|
|
26
|
+
exports.ensureDir = ensureDir;
|
|
27
|
+
exports.deleteFile = deleteFile;
|
|
28
|
+
exports.deleteDir = deleteDir;
|
|
29
|
+
exports.copyFile = copyFile;
|
|
30
|
+
exports.copyFiles = copyFiles;
|
|
31
|
+
exports.copyDir = copyDir;
|
|
32
|
+
exports.rename = rename;
|
|
33
|
+
exports.emptyDir = emptyDir;
|
|
34
|
+
exports.readJSONFile = readJSONFile;
|
|
35
|
+
exports.writeJSONFile = writeJSONFile;
|
|
36
|
+
exports.chmod = chmod;
|
|
37
|
+
exports.readStreamAsJSON = readStreamAsJSON;
|
|
38
|
+
exports.isDirEmpty = isDirEmpty;
|
|
16
39
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
17
40
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
18
41
|
const os_1 = __importDefault(require("os"));
|
|
@@ -25,27 +48,23 @@ function isPathExists(path) {
|
|
|
25
48
|
return stats && true;
|
|
26
49
|
});
|
|
27
50
|
}
|
|
28
|
-
exports.isPathExists = isPathExists;
|
|
29
51
|
function dirExists(pth) {
|
|
30
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
53
|
const stats = yield fs_extra_1.default.stat((0, utils_js_1.untildify)(pth)).catch(() => false);
|
|
32
54
|
return stats && stats.isDirectory();
|
|
33
55
|
});
|
|
34
56
|
}
|
|
35
|
-
exports.dirExists = dirExists;
|
|
36
57
|
function fileExists(pth) {
|
|
37
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
59
|
const stats = yield fs_extra_1.default.stat((0, utils_js_1.untildify)(pth)).catch(() => false);
|
|
39
60
|
return stats && stats.isFile();
|
|
40
61
|
});
|
|
41
62
|
}
|
|
42
|
-
exports.fileExists = fileExists;
|
|
43
63
|
function getFileDetails(pth) {
|
|
44
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
65
|
return fs_extra_1.default.stat((0, utils_js_1.untildify)(pth));
|
|
46
66
|
});
|
|
47
67
|
}
|
|
48
|
-
exports.getFileDetails = getFileDetails;
|
|
49
68
|
function readFile(pth, type) {
|
|
50
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
70
|
if (!(yield fileExists(pth))) {
|
|
@@ -58,22 +77,19 @@ function readFile(pth, type) {
|
|
|
58
77
|
: fs_extra_1.default.readFile(pth, 'utf8'));
|
|
59
78
|
});
|
|
60
79
|
}
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
function tempFile() {
|
|
81
|
+
return __awaiter(this, arguments, void 0, function* (name = Date.now().toString(), content) {
|
|
64
82
|
const tempDir = path_1.default.join(os_1.default.tmpdir(), '.catalyst');
|
|
65
83
|
const tempFilePth = path_1.default.join(tempDir, name);
|
|
66
84
|
content === undefined ? yield ensureFile(tempFilePth) : yield writeFile(tempFilePth, content);
|
|
67
85
|
return tempFilePth;
|
|
68
86
|
});
|
|
69
87
|
}
|
|
70
|
-
|
|
71
|
-
function
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
function writeFile(pth_1, content_1) {
|
|
89
|
+
return __awaiter(this, arguments, void 0, function* (pth, content, encoding = 'utf8') {
|
|
73
90
|
return fs_extra_1.default.writeFile(pth, content, { encoding });
|
|
74
91
|
});
|
|
75
92
|
}
|
|
76
|
-
exports.writeFile = writeFile;
|
|
77
93
|
function dirList(dir) {
|
|
78
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
95
|
const files = yield fs_extra_1.default.readdir(dir);
|
|
@@ -88,13 +104,12 @@ function dirList(dir) {
|
|
|
88
104
|
return entries.filter((entry) => entry !== undefined);
|
|
89
105
|
});
|
|
90
106
|
}
|
|
91
|
-
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}, depth = -1, includeDirPaths = false } = {}) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
function walk(dir_1) {
|
|
108
|
+
return __awaiter(this, arguments, void 0, function* (dir, { filter = {
|
|
109
|
+
exclude: [],
|
|
110
|
+
excludeDir: true,
|
|
111
|
+
ignoreFiles: false
|
|
112
|
+
}, depth = -1, includeDirPaths = false } = {}) {
|
|
98
113
|
const stats = yield fs_extra_1.default.lstat(dir);
|
|
99
114
|
if (depth === 0) {
|
|
100
115
|
return includeDirPaths ? [{ path: dir, stats }] : [];
|
|
@@ -130,9 +145,8 @@ function walk(dir, { filter = {
|
|
|
130
145
|
return folderContents.reduce((all, folderContent) => all.concat(folderContent), includeDirPaths ? [{ path: dir, stats }] : []);
|
|
131
146
|
});
|
|
132
147
|
}
|
|
133
|
-
|
|
134
|
-
function
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
function ensureFile(filePath_1) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* (filePath, cleanFile = false) {
|
|
136
150
|
const isFile = yield fileExists(filePath);
|
|
137
151
|
if (!isFile) {
|
|
138
152
|
return fs_extra_1.default.ensureFile(filePath);
|
|
@@ -143,27 +157,23 @@ function ensureFile(filePath, cleanFile = false) {
|
|
|
143
157
|
return;
|
|
144
158
|
});
|
|
145
159
|
}
|
|
146
|
-
exports.ensureFile = ensureFile;
|
|
147
160
|
function ensureDir(pth) {
|
|
148
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
162
|
return fs_extra_1.default.ensureDir(pth);
|
|
150
163
|
});
|
|
151
164
|
}
|
|
152
|
-
exports.ensureDir = ensureDir;
|
|
153
165
|
function deleteFile(filePath) {
|
|
154
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
167
|
return fs_extra_1.default.remove(filePath);
|
|
156
168
|
});
|
|
157
169
|
}
|
|
158
|
-
exports.deleteFile = deleteFile;
|
|
159
170
|
function deleteDir(dir) {
|
|
160
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
172
|
return fs_extra_1.default.remove(dir);
|
|
162
173
|
});
|
|
163
174
|
}
|
|
164
|
-
|
|
165
|
-
function
|
|
166
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
function copyFile(src_1, dest_1) {
|
|
176
|
+
return __awaiter(this, arguments, void 0, function* (src, dest, overwrite = true) {
|
|
167
177
|
yield ensureDir(path_1.default.dirname(dest));
|
|
168
178
|
return fs_extra_1.default.copy(src, dest, {
|
|
169
179
|
dereference: true,
|
|
@@ -173,7 +183,6 @@ function copyFile(src, dest, overwrite = true) {
|
|
|
173
183
|
});
|
|
174
184
|
});
|
|
175
185
|
}
|
|
176
|
-
exports.copyFile = copyFile;
|
|
177
186
|
function copyFiles(src, dest) {
|
|
178
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
188
|
return Promise.all(src.map((filePath) => {
|
|
@@ -182,15 +191,13 @@ function copyFiles(src, dest) {
|
|
|
182
191
|
}));
|
|
183
192
|
});
|
|
184
193
|
}
|
|
185
|
-
|
|
186
|
-
function
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
function copyDir(srcDir_1, destDir_1) {
|
|
195
|
+
return __awaiter(this, arguments, void 0, function* (srcDir, destDir, { filter = () => __awaiter(this, void 0, void 0, function* () { return true; }) } = {}) {
|
|
188
196
|
return fs_extra_1.default.copy(srcDir, destDir, { filter });
|
|
189
197
|
});
|
|
190
198
|
}
|
|
191
|
-
|
|
192
|
-
function
|
|
193
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
function rename(pth_1) {
|
|
200
|
+
return __awaiter(this, arguments, void 0, function* (pth, modifier = (baseName) => baseName) {
|
|
194
201
|
if (Array.isArray(pth)) {
|
|
195
202
|
yield Promise.all(pth.map((el) => rename(el, modifier)));
|
|
196
203
|
return;
|
|
@@ -200,7 +207,6 @@ function rename(pth, modifier = (baseName) => baseName) {
|
|
|
200
207
|
return fs_extra_1.default.rename(pth, modifiedName);
|
|
201
208
|
});
|
|
202
209
|
}
|
|
203
|
-
exports.rename = rename;
|
|
204
210
|
const findAndReplace = (pth) => (templates, finalWords) => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
211
|
if (Array.isArray(pth)) {
|
|
206
212
|
yield Promise.all(pth.map((el) => (0, exports.findAndReplace)(el)(templates, finalWords)));
|
|
@@ -229,7 +235,6 @@ function emptyDir(dir) {
|
|
|
229
235
|
return fs_extra_1.default.emptyDir(dir);
|
|
230
236
|
});
|
|
231
237
|
}
|
|
232
|
-
exports.emptyDir = emptyDir;
|
|
233
238
|
function readJSONFile(pth, opts) {
|
|
234
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
235
240
|
if (opts && opts.checkpath && !(yield fileExists(pth))) {
|
|
@@ -238,16 +243,14 @@ function readJSONFile(pth, opts) {
|
|
|
238
243
|
return fs_extra_1.default.readJson(pth, opts);
|
|
239
244
|
});
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
function
|
|
243
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
function writeJSONFile(pth_1, object_1) {
|
|
247
|
+
return __awaiter(this, arguments, void 0, function* (pth, object, opts = { spaces: '\t' }) {
|
|
244
248
|
yield ensureFile(pth, true);
|
|
245
249
|
return fs_extra_1.default.writeJson(pth, object, opts);
|
|
246
250
|
});
|
|
247
251
|
}
|
|
248
|
-
|
|
249
|
-
function
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
function chmod(path_2, mode_1) {
|
|
253
|
+
return __awaiter(this, arguments, void 0, function* (path, mode, { checkPath = true, recursive = false } = {}) {
|
|
251
254
|
if (checkPath && !(yield isPathExists(path))) {
|
|
252
255
|
return Promise.reject('Path does not exists');
|
|
253
256
|
}
|
|
@@ -259,7 +262,6 @@ function chmod(path, mode, { checkPath = true, recursive = false } = {}) {
|
|
|
259
262
|
return fs_extra_1.default.chmod(path, mode);
|
|
260
263
|
});
|
|
261
264
|
}
|
|
262
|
-
exports.chmod = chmod;
|
|
263
265
|
function readStreamAsJSON(stream) {
|
|
264
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
267
|
return new Promise((resolve, reject) => {
|
|
@@ -281,11 +283,9 @@ function readStreamAsJSON(stream) {
|
|
|
281
283
|
});
|
|
282
284
|
});
|
|
283
285
|
}
|
|
284
|
-
exports.readStreamAsJSON = readStreamAsJSON;
|
|
285
286
|
function isDirEmpty(pth) {
|
|
286
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
288
|
const files = yield fs_extra_1.default.readdir(pth);
|
|
288
289
|
return files.length === 0;
|
|
289
290
|
});
|
|
290
291
|
}
|
|
291
|
-
exports.isDirEmpty = isDirEmpty;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import fs, { CopyFilterSync } from 'fs-extra';
|
|
5
2
|
export declare function getWriteStream(pth: string, mode?: number): fs.WriteStream;
|
|
6
3
|
export declare function getReadStream(pth: string): fs.ReadStream;
|
|
@@ -18,6 +15,7 @@ export declare function writeFile(pth: string, data: Buffer | Uint8Array | strin
|
|
|
18
15
|
export declare function appendFile(pth: string, data: Buffer | Uint8Array | string, encoding?: BufferEncoding): void;
|
|
19
16
|
export declare function modifyFileName(pth: string | Array<string>, modifier: (fullPth: string, extension: string) => string): Array<string>;
|
|
20
17
|
export declare function renameFile(pth: string | Array<string>, modifier: (fullPth: string, extension: string) => string): Array<void>;
|
|
18
|
+
export declare function renameDir(from: string, to: string): boolean;
|
|
21
19
|
export declare function isPathOutside(from: string, to: string): boolean;
|
|
22
20
|
export declare function isPathInside(from: string, to: string): boolean;
|
|
23
21
|
export declare function deleteDir(dir: string): void;
|
|
@@ -3,7 +3,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getWriteStream = getWriteStream;
|
|
7
|
+
exports.getReadStream = getReadStream;
|
|
8
|
+
exports.readSymLink = readSymLink;
|
|
9
|
+
exports.fileExists = fileExists;
|
|
10
|
+
exports.pathExists = pathExists;
|
|
11
|
+
exports.dirExists = dirExists;
|
|
12
|
+
exports.getAllDirs = getAllDirs;
|
|
13
|
+
exports.getAllFiles = getAllFiles;
|
|
14
|
+
exports.deleteFile = deleteFile;
|
|
15
|
+
exports.readFile = readFile;
|
|
16
|
+
exports.ensureDir = ensureDir;
|
|
17
|
+
exports.ensureFile = ensureFile;
|
|
18
|
+
exports.writeFile = writeFile;
|
|
19
|
+
exports.appendFile = appendFile;
|
|
20
|
+
exports.modifyFileName = modifyFileName;
|
|
21
|
+
exports.renameFile = renameFile;
|
|
22
|
+
exports.renameDir = renameDir;
|
|
23
|
+
exports.isPathOutside = isPathOutside;
|
|
24
|
+
exports.isPathInside = isPathInside;
|
|
25
|
+
exports.deleteDir = deleteDir;
|
|
26
|
+
exports.tempFile = tempFile;
|
|
27
|
+
exports.deleteTempDir = deleteTempDir;
|
|
28
|
+
exports.copyFile = copyFile;
|
|
29
|
+
exports.copyFiles = copyFiles;
|
|
30
|
+
exports.copyDir = copyDir;
|
|
31
|
+
exports.emptyDir = emptyDir;
|
|
32
|
+
exports.readJSONFile = readJSONFile;
|
|
33
|
+
exports.writeJSONFile = writeJSONFile;
|
|
34
|
+
exports.readPackageJson = readPackageJson;
|
|
35
|
+
exports.isDirEmpty = isDirEmpty;
|
|
7
36
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
37
|
const os_1 = __importDefault(require("os"));
|
|
9
38
|
const path_1 = require("path");
|
|
@@ -11,15 +40,12 @@ const utils_1 = require("../utils");
|
|
|
11
40
|
function getWriteStream(pth, mode) {
|
|
12
41
|
return fs_extra_1.default.createWriteStream(pth, { mode });
|
|
13
42
|
}
|
|
14
|
-
exports.getWriteStream = getWriteStream;
|
|
15
43
|
function getReadStream(pth) {
|
|
16
44
|
return fs_extra_1.default.createReadStream(pth);
|
|
17
45
|
}
|
|
18
|
-
exports.getReadStream = getReadStream;
|
|
19
46
|
function readSymLink(pth) {
|
|
20
47
|
return fs_extra_1.default.readlinkSync(pth);
|
|
21
48
|
}
|
|
22
|
-
exports.readSymLink = readSymLink;
|
|
23
49
|
function fileExists(pth) {
|
|
24
50
|
try {
|
|
25
51
|
const stats = fs_extra_1.default.statSync(pth);
|
|
@@ -29,7 +55,6 @@ function fileExists(pth) {
|
|
|
29
55
|
return false;
|
|
30
56
|
}
|
|
31
57
|
}
|
|
32
|
-
exports.fileExists = fileExists;
|
|
33
58
|
function pathExists(pth) {
|
|
34
59
|
try {
|
|
35
60
|
const stats = fs_extra_1.default.statSync((0, utils_1.untildify)(pth));
|
|
@@ -39,7 +64,6 @@ function pathExists(pth) {
|
|
|
39
64
|
return false;
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
|
-
exports.pathExists = pathExists;
|
|
43
67
|
function dirExists(pth) {
|
|
44
68
|
try {
|
|
45
69
|
const stats = fs_extra_1.default.statSync(pth);
|
|
@@ -49,7 +73,6 @@ function dirExists(pth) {
|
|
|
49
73
|
return false;
|
|
50
74
|
}
|
|
51
75
|
}
|
|
52
|
-
exports.dirExists = dirExists;
|
|
53
76
|
function getAllDirs(srcPath) {
|
|
54
77
|
const directories = fs_extra_1.default
|
|
55
78
|
.readdirSync(srcPath)
|
|
@@ -61,7 +84,6 @@ function getAllDirs(srcPath) {
|
|
|
61
84
|
});
|
|
62
85
|
return directories;
|
|
63
86
|
}
|
|
64
|
-
exports.getAllDirs = getAllDirs;
|
|
65
87
|
function getAllFiles(srcPath) {
|
|
66
88
|
const files = fs_extra_1.default
|
|
67
89
|
.readdirSync(srcPath)
|
|
@@ -73,22 +95,18 @@ function getAllFiles(srcPath) {
|
|
|
73
95
|
});
|
|
74
96
|
return files;
|
|
75
97
|
}
|
|
76
|
-
exports.getAllFiles = getAllFiles;
|
|
77
98
|
function deleteFile(pth) {
|
|
78
99
|
return fs_extra_1.default.removeSync(pth);
|
|
79
100
|
}
|
|
80
|
-
exports.deleteFile = deleteFile;
|
|
81
101
|
function readFile(pth, encoding = 'utf8') {
|
|
82
102
|
if (fileExists(pth)) {
|
|
83
103
|
return fs_extra_1.default.readFileSync(pth, encoding);
|
|
84
104
|
}
|
|
85
105
|
return undefined;
|
|
86
106
|
}
|
|
87
|
-
exports.readFile = readFile;
|
|
88
107
|
function ensureDir(dir) {
|
|
89
108
|
return fs_extra_1.default.ensureDirSync(dir);
|
|
90
109
|
}
|
|
91
|
-
exports.ensureDir = ensureDir;
|
|
92
110
|
function ensureFile(filePath, cleanFile = false) {
|
|
93
111
|
const isFile = fileExists(filePath);
|
|
94
112
|
if (!isFile) {
|
|
@@ -99,15 +117,12 @@ function ensureFile(filePath, cleanFile = false) {
|
|
|
99
117
|
}
|
|
100
118
|
return;
|
|
101
119
|
}
|
|
102
|
-
exports.ensureFile = ensureFile;
|
|
103
120
|
function writeFile(pth, data, encoding = 'utf8') {
|
|
104
121
|
return fs_extra_1.default.writeFileSync(pth, data, { encoding });
|
|
105
122
|
}
|
|
106
|
-
exports.writeFile = writeFile;
|
|
107
123
|
function appendFile(pth, data, encoding = 'utf8') {
|
|
108
124
|
return fs_extra_1.default.appendFileSync(pth, data, { encoding });
|
|
109
125
|
}
|
|
110
|
-
exports.appendFile = appendFile;
|
|
111
126
|
function modifyFileName(pth, modifier) {
|
|
112
127
|
pth = Array.isArray(pth) ? pth : [pth];
|
|
113
128
|
return pth.map((el) => {
|
|
@@ -115,71 +130,68 @@ function modifyFileName(pth, modifier) {
|
|
|
115
130
|
return (0, path_1.join)((0, path_1.dirname)(el), modifier((0, path_1.basename)(el, ext), ext));
|
|
116
131
|
});
|
|
117
132
|
}
|
|
118
|
-
exports.modifyFileName = modifyFileName;
|
|
119
133
|
function renameFile(pth, modifier) {
|
|
120
134
|
pth = Array.isArray(pth) ? pth : [pth];
|
|
121
135
|
return pth.map((el) => fs_extra_1.default.renameSync(el, modifyFileName(el, modifier)[0]));
|
|
122
136
|
}
|
|
123
|
-
|
|
137
|
+
function renameDir(from, to) {
|
|
138
|
+
if (isDirEmpty(from)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if ((0, path_1.resolve)(from) === (0, path_1.resolve)(to)) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
fs_extra_1.default.renameSync(from, to);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
124
147
|
function isPathOutside(from, to) {
|
|
125
148
|
return !isPathInside(from, to);
|
|
126
149
|
}
|
|
127
|
-
exports.isPathOutside = isPathOutside;
|
|
128
150
|
function isPathInside(from, to) {
|
|
129
151
|
const relativePth = (0, path_1.relative)(from, to);
|
|
130
152
|
return !!((from === to || relativePth) &&
|
|
131
153
|
!relativePth.startsWith('..') &&
|
|
132
154
|
!(0, path_1.isAbsolute)(relativePth));
|
|
133
155
|
}
|
|
134
|
-
exports.isPathInside = isPathInside;
|
|
135
156
|
function deleteDir(dir) {
|
|
136
157
|
return fs_extra_1.default.removeSync(dir);
|
|
137
158
|
}
|
|
138
|
-
exports.deleteDir = deleteDir;
|
|
139
159
|
function tempFile(name = Date.now().toString()) {
|
|
140
160
|
const tempDir = (0, path_1.join)(os_1.default.tmpdir(), '.catalyst');
|
|
141
161
|
const tempFilePth = (0, path_1.join)(tempDir, name);
|
|
142
162
|
fs_extra_1.default.ensureFileSync(tempFilePth);
|
|
143
163
|
return tempFilePth;
|
|
144
164
|
}
|
|
145
|
-
exports.tempFile = tempFile;
|
|
146
165
|
function deleteTempDir() {
|
|
147
166
|
const dir = (0, path_1.join)(os_1.default.tmpdir(), '.catalyst');
|
|
148
167
|
return deleteDir(dir);
|
|
149
168
|
}
|
|
150
|
-
exports.deleteTempDir = deleteTempDir;
|
|
151
169
|
function copyFile(src, dest) {
|
|
152
170
|
ensureDir((0, path_1.dirname)(dest));
|
|
153
171
|
return fs_extra_1.default.copyFileSync(src, dest);
|
|
154
172
|
}
|
|
155
|
-
exports.copyFile = copyFile;
|
|
156
173
|
function copyFiles(src, dest) {
|
|
157
174
|
src.forEach((srcPath) => {
|
|
158
175
|
const file = (0, path_1.basename)(srcPath);
|
|
159
176
|
copyFile(srcPath, (0, path_1.join)(dest, file));
|
|
160
177
|
});
|
|
161
178
|
}
|
|
162
|
-
exports.copyFiles = copyFiles;
|
|
163
179
|
function copyDir(srcDir, destDir, { filter = () => true, overwrite = true, errorOnExist = false } = {}) {
|
|
164
180
|
return fs_extra_1.default.copySync(srcDir, destDir, { filter, overwrite, errorOnExist });
|
|
165
181
|
}
|
|
166
|
-
exports.copyDir = copyDir;
|
|
167
182
|
function emptyDir(dir) {
|
|
168
183
|
return fs_extra_1.default.emptyDirSync(dir);
|
|
169
184
|
}
|
|
170
|
-
exports.emptyDir = emptyDir;
|
|
171
185
|
function readJSONFile(pth, opts) {
|
|
172
186
|
if (opts && opts.checkpath && !fileExists(pth)) {
|
|
173
187
|
return undefined;
|
|
174
188
|
}
|
|
175
189
|
return fs_extra_1.default.readJsonSync(pth, opts);
|
|
176
190
|
}
|
|
177
|
-
exports.readJSONFile = readJSONFile;
|
|
178
191
|
function writeJSONFile(pth, object, opts) {
|
|
179
192
|
ensureFile(pth, true);
|
|
180
193
|
return fs_extra_1.default.writeJsonSync(pth, object, opts);
|
|
181
194
|
}
|
|
182
|
-
exports.writeJSONFile = writeJSONFile;
|
|
183
195
|
function readPackageJson() {
|
|
184
196
|
const pkg = readJSONFile((0, path_1.join)(__dirname, '../../../../package.json'), {
|
|
185
197
|
checkpath: true,
|
|
@@ -187,9 +199,7 @@ function readPackageJson() {
|
|
|
187
199
|
});
|
|
188
200
|
return pkg;
|
|
189
201
|
}
|
|
190
|
-
exports.readPackageJson = readPackageJson;
|
|
191
202
|
function isDirEmpty(pth) {
|
|
192
203
|
const files = fs_extra_1.default.readdirSync(pth);
|
|
193
204
|
return files.length === 0;
|
|
194
205
|
}
|
|
195
|
-
exports.isDirEmpty = isDirEmpty;
|