From ab5723a75bbaf83b9fcd3656fd09701fe8b4d473 Mon Sep 17 00:00:00 2001 From: Nameer Haider Date: Sat, 17 Feb 2024 20:13:32 +0300 Subject: [PATCH] adding basic commands --- .env2 | 3 +- package-lock.json | 669 +++++++++++++++++- package.backup | 6 +- package.json | 3 + src/commanders/commander.ts | 12 +- src/commanders/commands/package.command.ts | 12 + src/commanders/index.ts | 11 + .../subcommands/backup.subcommand.ts | 11 + .../subcommands/refactor.subcommand.ts | 24 + .../subcommands/restore.subcommand.ts | 10 + src/common/utils/load-env.ts | 10 - .../dto => commons/dtos}/config.dto.ts | 0 src/{common/dto => commons/dtos}/index.ts | 0 .../package-utils/backup.ts | 4 +- .../package-utils/blacklist-properties.ts | 0 .../package-utils/filter-package-json.ts | 0 .../package-utils/get-package-json.ts | 6 +- .../package-utils/index.ts | 0 .../package-utils/read-json.d.ts | 0 .../package-utils/restore.ts | 4 +- .../utils/get-config-object.ts | 2 +- src/{common => commons}/utils/index.ts | 0 src/commons/utils/load-env.ts | 15 + src/commons/utils/logger.ts | 74 ++ .../operationRunner.ts} | 10 +- .../{ => operations}/basic.operations.ts | 2 +- .../{ => operations}/env.operations.ts | 0 src/main.ts | 69 +- 28 files changed, 842 insertions(+), 115 deletions(-) create mode 100644 src/commanders/commands/package.command.ts create mode 100644 src/commanders/index.ts create mode 100644 src/commanders/subcommands/backup.subcommand.ts create mode 100644 src/commanders/subcommands/refactor.subcommand.ts create mode 100644 src/commanders/subcommands/restore.subcommand.ts delete mode 100644 src/common/utils/load-env.ts rename src/{common/dto => commons/dtos}/config.dto.ts (100%) rename src/{common/dto => commons/dtos}/index.ts (100%) rename src/{common => commons}/package-utils/backup.ts (77%) rename src/{common => commons}/package-utils/blacklist-properties.ts (100%) rename src/{common => commons}/package-utils/filter-package-json.ts (100%) rename src/{common => commons}/package-utils/get-package-json.ts (72%) rename src/{common => commons}/package-utils/index.ts (100%) rename src/{common => commons}/package-utils/read-json.d.ts (100%) rename src/{common => commons}/package-utils/restore.ts (76%) rename src/{common => commons}/utils/get-config-object.ts (94%) rename src/{common => commons}/utils/index.ts (100%) create mode 100644 src/commons/utils/load-env.ts create mode 100644 src/commons/utils/logger.ts rename src/{operationsRunner.ts => features/operationRunner.ts} (78%) rename src/features/{ => operations}/basic.operations.ts (94%) rename src/features/{ => operations}/env.operations.ts (100%) diff --git a/.env2 b/.env2 index ae4bf0c..9bb92b0 100644 --- a/.env2 +++ b/.env2 @@ -1,2 +1 @@ -test3=3 -test4=test4 \ No newline at end of file +test4=test4 diff --git a/package-lock.json b/package-lock.json index 512f4df..417cdf1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,9 @@ "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" }, + "bin": { + "repack": "lib/main.js" + }, "devDependencies": { "@types/jest": "^29.5.2", "@types/node": "^20.3.1", @@ -1074,6 +1077,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jest/console/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@jest/core": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/core/-/core-29.7.0.tgz", @@ -1121,6 +1140,22 @@ } } }, + "node_modules/@jest/core/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@jest/environment": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", @@ -1236,6 +1271,22 @@ } } }, + "node_modules/@jest/reporters/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -1318,6 +1369,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jest/transform/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@jest/types": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", @@ -1335,6 +1402,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jest/types/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", @@ -2238,6 +2321,22 @@ "@babel/core": "^7.8.0" } }, + "node_modules/babel-jest/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/babel-plugin-istanbul": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", @@ -2474,22 +2573,6 @@ } ] }, - "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, "node_modules/char-regex": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", @@ -2643,6 +2726,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/create-jest/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -3040,6 +3139,22 @@ "concat-map": "0.0.1" } }, + "node_modules/eslint/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/eslint/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3991,6 +4106,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-circus/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-cli": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.7.0.tgz", @@ -4024,6 +4155,22 @@ } } }, + "node_modules/jest-cli/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-config": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-29.7.0.tgz", @@ -4069,6 +4216,22 @@ } } }, + "node_modules/jest-config/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-diff": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", @@ -4084,6 +4247,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-diff/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-docblock": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-29.7.0.tgz", @@ -4112,6 +4291,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-each/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-environment-node": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.7.0.tgz", @@ -4191,6 +4386,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-matcher-utils/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-message-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", @@ -4211,6 +4422,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-message-util/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-mock": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", @@ -4284,6 +4511,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-resolve/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-runner": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-29.7.0.tgz", @@ -4312,8 +4555,24 @@ "p-limit": "^3.1.0", "source-map-support": "0.5.13" }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/jest-runner/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, "node_modules/jest-runner/node_modules/source-map-support": { @@ -4359,6 +4618,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-runtime/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-snapshot": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.7.0.tgz", @@ -4390,6 +4665,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-snapshot/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", @@ -4407,6 +4698,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-util/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-validate": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", @@ -4436,6 +4743,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/jest-validate/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-watcher": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-29.7.0.tgz", @@ -4455,6 +4778,22 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-watcher/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/jest-worker": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", @@ -6085,6 +6424,22 @@ "webpack": "^5.0.0" } }, + "node_modules/ts-loader/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/ts-loader/node_modules/source-map": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", @@ -7308,6 +7663,18 @@ "jest-message-util": "^29.7.0", "jest-util": "^29.7.0", "slash": "^3.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@jest/core": { @@ -7344,6 +7711,18 @@ "pretty-format": "^29.7.0", "slash": "^3.0.0", "strip-ansi": "^6.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@jest/environment": { @@ -7433,6 +7812,18 @@ "string-length": "^4.0.1", "strip-ansi": "^6.0.0", "v8-to-istanbul": "^9.0.1" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@jest/schemas": { @@ -7500,6 +7891,18 @@ "pirates": "^4.0.4", "slash": "^3.0.0", "write-file-atomic": "^4.0.2" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@jest/types": { @@ -7514,6 +7917,18 @@ "@types/node": "*", "@types/yargs": "^17.0.8", "chalk": "^4.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "@jridgewell/gen-mapping": { @@ -8251,6 +8666,18 @@ "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "slash": "^3.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "babel-plugin-istanbul": { @@ -8418,16 +8845,6 @@ "integrity": "sha512-HMFNotUmLXn71BQxg8cijvqxnIAofforZOwGsxyXJ0qugTdspUF4sPSJ2vhgprHCB996tIDzEq1ubumPDV8ULA==", "dev": true }, - "chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, "char-regex": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", @@ -8542,6 +8959,18 @@ "jest-config": "^29.7.0", "jest-util": "^29.7.0", "prompts": "^2.0.1" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "create-require": { @@ -8787,6 +9216,16 @@ "concat-map": "0.0.1" } }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -9515,6 +9954,18 @@ "pure-rand": "^6.0.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-cli": { @@ -9534,6 +9985,18 @@ "jest-util": "^29.7.0", "jest-validate": "^29.7.0", "yargs": "^17.3.1" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-config": { @@ -9564,6 +10027,18 @@ "pretty-format": "^29.7.0", "slash": "^3.0.0", "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-diff": { @@ -9576,6 +10051,18 @@ "diff-sequences": "^29.6.3", "jest-get-type": "^29.6.3", "pretty-format": "^29.7.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-docblock": { @@ -9598,6 +10085,18 @@ "jest-get-type": "^29.6.3", "jest-util": "^29.7.0", "pretty-format": "^29.7.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-environment-node": { @@ -9660,6 +10159,18 @@ "jest-diff": "^29.7.0", "jest-get-type": "^29.6.3", "pretty-format": "^29.7.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-message-util": { @@ -9677,6 +10188,18 @@ "pretty-format": "^29.7.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-mock": { @@ -9718,6 +10241,18 @@ "resolve": "^1.20.0", "resolve.exports": "^2.0.0", "slash": "^3.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-resolve-dependencies": { @@ -9759,6 +10294,16 @@ "source-map-support": "0.5.13" }, "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, "source-map-support": { "version": "0.5.13", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz", @@ -9799,6 +10344,18 @@ "jest-util": "^29.7.0", "slash": "^3.0.0", "strip-bom": "^4.0.0" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-snapshot": { @@ -9827,6 +10384,18 @@ "natural-compare": "^1.4.0", "pretty-format": "^29.7.0", "semver": "^7.5.3" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-util": { @@ -9841,6 +10410,18 @@ "ci-info": "^3.2.0", "graceful-fs": "^4.2.9", "picomatch": "^2.2.3" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-validate": { @@ -9862,6 +10443,16 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } } } }, @@ -9879,6 +10470,18 @@ "emittery": "^0.13.1", "jest-util": "^29.7.0", "string-length": "^4.0.1" + }, + "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "jest-worker": { @@ -11034,6 +11637,16 @@ "source-map": "^0.7.4" }, "dependencies": { + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, "source-map": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", diff --git a/package.backup b/package.backup index 6c6b8fc..c4f77bf 100644 --- a/package.backup +++ b/package.backup @@ -5,11 +5,14 @@ "author": "", "private": true, "license": "UNLICENSED", + "bin": { + "repack": "lib/main.js" + }, "repackify": { "remove": [ "test" ], - "operations": { + "add": { "test": "test2" } }, @@ -21,6 +24,7 @@ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix" }, "dependencies": { + "dotenv": "^16.4.4", "read-package-json": "^7.0.0", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" diff --git a/package.json b/package.json index 156d511..c9ea76e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "author": "", "private": true, "license": "UNLICENSED", + "bin": { + "repack": "lib/main.js" + }, "repackify": { "remove": [ "test" diff --git a/src/commanders/commander.ts b/src/commanders/commander.ts index db74a6b..4bd0dbd 100644 --- a/src/commanders/commander.ts +++ b/src/commanders/commander.ts @@ -8,7 +8,7 @@ interface CommanderProps { command: string; commandOptions?: CommandOptions[]; subCommands?: Commander[]; - script: (options: Record) => void; + script: (options: Record) => Promise; } export class Commander { @@ -22,9 +22,9 @@ export class Commander { private readonly command: string; private readonly commandOptions: CommandOptions[]; private readonly subCommands: Commander[]; - private readonly script: (options: Record) => void; + private readonly script: (options: Record) => Promise; - run(args: string[]): boolean { + async run(args: string[]): Promise { if (this.extractCommand(args, this.command)) { if (!this.checkSubCommands(this.subCommands, args)) { throw new Error(`Command ${args[0]} not found`); @@ -32,7 +32,7 @@ export class Commander { for (const subCommand of this.subCommands) { if (subCommand && subCommand.command) { - const subcommand = subCommand.run(args); + const subcommand = await subCommand.run(args); if (subcommand) { return true; } @@ -45,7 +45,7 @@ export class Commander { this.checkForRequiredOptions(this.commandOptions, options); } - this.script(options); + await this.script(options); return true; } @@ -79,7 +79,7 @@ export class Commander { const finalOptions: Record = {}; for (const option of options) { if (option.option === args[0] || option.shortOption === args[0]) { - const key = this.removeCommandOptionPrefix(args[0]); + const key = this.removeCommandOptionPrefix(option.option); finalOptions[key] = args[1]; args.splice(0, 2); } diff --git a/src/commanders/commands/package.command.ts b/src/commanders/commands/package.command.ts new file mode 100644 index 0000000..80d46a0 --- /dev/null +++ b/src/commanders/commands/package.command.ts @@ -0,0 +1,12 @@ +import { Commander } from '../commander'; +import { backupSubcommand } from '../subcommands/backup.subcommand'; +import { restoreSubcommand } from '../subcommands/restore.subcommand'; +import { refactorSubcommand } from '../subcommands/refactor.subcommand'; + +export const packageCommand = new Commander({ + command: 'package', + script: async () => { + console.log('Repacking'); + }, + subCommands: [backupSubcommand, restoreSubcommand, refactorSubcommand], +}); diff --git a/src/commanders/index.ts b/src/commanders/index.ts new file mode 100644 index 0000000..88fe541 --- /dev/null +++ b/src/commanders/index.ts @@ -0,0 +1,11 @@ +/** + * Export Commands: + */ +export * from './commands/package.command'; + +/** + * Export SubCommands: + */ +export * from './subcommands/restore.subcommand'; +export * from './subcommands/refactor.subcommand'; +export * from './subcommands/backup.subcommand'; diff --git a/src/commanders/subcommands/backup.subcommand.ts b/src/commanders/subcommands/backup.subcommand.ts new file mode 100644 index 0000000..035499a --- /dev/null +++ b/src/commanders/subcommands/backup.subcommand.ts @@ -0,0 +1,11 @@ +import { Commander } from '../commander'; +import { backup, getPackageJson } from '../../commons/package-utils'; + +export const backupSubcommand = new Commander({ + command: 'backup', + script: async () => { + const packageJson = await getPackageJson(global.configs.packageDir); + await backup(packageJson, global.configs.backupDir); + global._logger.success(`Backup complete.`); + }, +}); diff --git a/src/commanders/subcommands/refactor.subcommand.ts b/src/commanders/subcommands/refactor.subcommand.ts new file mode 100644 index 0000000..4ac00de --- /dev/null +++ b/src/commanders/subcommands/refactor.subcommand.ts @@ -0,0 +1,24 @@ +import { Commander } from '../commander'; +import { operationRunner } from '../../features/operationRunner'; +import { backup, getPackageJson, restore } from '../../commons/package-utils'; +import { getConfig, loadEnv } from '../../commons/utils'; + +export const refactorSubcommand = new Commander({ + command: 'refactor', + commandOptions: [ + { option: '--env', shortOption: '-e' }, + { option: '--extra_env', shortOption: '-ee' }, + ], + script: async (options) => { + const baseEnv = options['env'] ?? '.env'; + const extraEnvs = (options['extra_env'] ?? '').split(',') ?? []; + + const packageJson = await getPackageJson(global.configs.packageDir); + await backup(packageJson, global.configs.backupDir); + const refactorConfig = getConfig(packageJson); + const env = loadEnv(baseEnv, extraEnvs); + const refactoredPackage = operationRunner(packageJson, refactorConfig, env); + await restore(refactoredPackage, global.configs.packageDir); + global._logger.success(`Refactor complete.`); + }, +}); diff --git a/src/commanders/subcommands/restore.subcommand.ts b/src/commanders/subcommands/restore.subcommand.ts new file mode 100644 index 0000000..9b6ee6f --- /dev/null +++ b/src/commanders/subcommands/restore.subcommand.ts @@ -0,0 +1,10 @@ +import { Commander } from '../commander'; +import { getPackageJson, restore } from '../../commons/package-utils'; + +export const restoreSubcommand = new Commander({ + command: 'restore', + script: async () => { + const backupPackage = await getPackageJson(global.configs.backupDir); + await restore(backupPackage, global.configs.packageDir); + }, +}); diff --git a/src/common/utils/load-env.ts b/src/common/utils/load-env.ts deleted file mode 100644 index 6921da9..0000000 --- a/src/common/utils/load-env.ts +++ /dev/null @@ -1,10 +0,0 @@ -import dotenv from 'dotenv'; - -export const loadEnv = (env: string, extraEnvs: string[]): void => { - if (env) { - dotenv.config({ path: env }); - } - if (extraEnvs) { - dotenv.config({ path: extraEnvs }); - } -}; diff --git a/src/common/dto/config.dto.ts b/src/commons/dtos/config.dto.ts similarity index 100% rename from src/common/dto/config.dto.ts rename to src/commons/dtos/config.dto.ts diff --git a/src/common/dto/index.ts b/src/commons/dtos/index.ts similarity index 100% rename from src/common/dto/index.ts rename to src/commons/dtos/index.ts diff --git a/src/common/package-utils/backup.ts b/src/commons/package-utils/backup.ts similarity index 77% rename from src/common/package-utils/backup.ts rename to src/commons/package-utils/backup.ts index 063aa46..b526805 100644 --- a/src/common/package-utils/backup.ts +++ b/src/commons/package-utils/backup.ts @@ -6,11 +6,11 @@ const writeFile = promisify(fs.writeFile); export const backup = async ( record: Record, - backupName = 'package.backup', + backupPath: string, ) => { record = filterPackageJson(record); const data = JSON.stringify(record, null, 2); - await writeFile(`${global._projectDir}/${backupName}`, data); + await writeFile(backupPath, data); return record; }; diff --git a/src/common/package-utils/blacklist-properties.ts b/src/commons/package-utils/blacklist-properties.ts similarity index 100% rename from src/common/package-utils/blacklist-properties.ts rename to src/commons/package-utils/blacklist-properties.ts diff --git a/src/common/package-utils/filter-package-json.ts b/src/commons/package-utils/filter-package-json.ts similarity index 100% rename from src/common/package-utils/filter-package-json.ts rename to src/commons/package-utils/filter-package-json.ts diff --git a/src/common/package-utils/get-package-json.ts b/src/commons/package-utils/get-package-json.ts similarity index 72% rename from src/common/package-utils/get-package-json.ts rename to src/commons/package-utils/get-package-json.ts index e29fff8..278d018 100644 --- a/src/common/package-utils/get-package-json.ts +++ b/src/commons/package-utils/get-package-json.ts @@ -1,12 +1,10 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires const readJson = require('read-package-json'); -export const getPackageJson = (packageName = 'package.json') => { +export const getPackageJson = (packagePath: string) => { return new Promise>((resolve, reject) => { - const packageJsonPath = `${global._projectDir}/${packageName}`; - readJson( - packageJsonPath, + packagePath, console.error, false, (er: NodeJS.ErrnoException, data: Record) => { diff --git a/src/common/package-utils/index.ts b/src/commons/package-utils/index.ts similarity index 100% rename from src/common/package-utils/index.ts rename to src/commons/package-utils/index.ts diff --git a/src/common/package-utils/read-json.d.ts b/src/commons/package-utils/read-json.d.ts similarity index 100% rename from src/common/package-utils/read-json.d.ts rename to src/commons/package-utils/read-json.d.ts diff --git a/src/common/package-utils/restore.ts b/src/commons/package-utils/restore.ts similarity index 76% rename from src/common/package-utils/restore.ts rename to src/commons/package-utils/restore.ts index 2f2edb8..93f27a4 100644 --- a/src/common/package-utils/restore.ts +++ b/src/commons/package-utils/restore.ts @@ -6,9 +6,9 @@ const writeFile = promisify(fs.writeFile); export const restore = async ( record: Record, - packageName = 'package.json', + packagePath: string, ) => { record = filterPackageJson(record); const data = JSON.stringify(record, null, 2); - await writeFile(`${global._projectDir}/${packageName}`, data); + await writeFile(packagePath, data); }; diff --git a/src/common/utils/get-config-object.ts b/src/commons/utils/get-config-object.ts similarity index 94% rename from src/common/utils/get-config-object.ts rename to src/commons/utils/get-config-object.ts index efe2323..b32a10b 100644 --- a/src/common/utils/get-config-object.ts +++ b/src/commons/utils/get-config-object.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import { ConfigDto } from '../dto'; +import { ConfigDto } from '../dtos'; export const getConfigFromJSFile = (): ConfigDto | null => { const filePath = path.join(global._projectDir, 'repackify.js'); diff --git a/src/common/utils/index.ts b/src/commons/utils/index.ts similarity index 100% rename from src/common/utils/index.ts rename to src/commons/utils/index.ts diff --git a/src/commons/utils/load-env.ts b/src/commons/utils/load-env.ts new file mode 100644 index 0000000..c157de9 --- /dev/null +++ b/src/commons/utils/load-env.ts @@ -0,0 +1,15 @@ +import * as dotenv from 'dotenv'; + +export const loadEnv = ( + env: string, + extraEnvs: string[], +): NodeJS.ProcessEnv => { + if (env) { + dotenv.config({ path: env }); + } + if (extraEnvs) { + dotenv.config({ path: extraEnvs }); + } + + return process.env; +}; diff --git a/src/commons/utils/logger.ts b/src/commons/utils/logger.ts new file mode 100644 index 0000000..8032f02 --- /dev/null +++ b/src/commons/utils/logger.ts @@ -0,0 +1,74 @@ +export class Logger { + constructor(private readonly serviceName: string) {} + + _color = (code: number, ended = false, ...messages: any[]) => + `\x1b[${code}m${messages.join(' ')}${ended ? '\x1b[0m' : ''}`; + + coloredText = { + black: this._color.bind(null, 30, false), + red: this._color.bind(null, 31, false), + green: this._color.bind(null, 32, false), + yellow: this._color.bind(this, 33, false), + blue: this._color.bind(this, 34, false), + magenta: this._color.bind(this, 35, false), + cyan: this._color.bind(this, 36, false), + white: this._color.bind(this, 37, false), + bgBlack: this._color.bind(this, 40, true), + bgRed: this._color.bind(this, 41, true), + bgGreen: this._color.bind(this, 42, true), + bgYellow: this._color.bind(this, 43, true), + bgBlue: this._color.bind(this, 44, true), + bgMagenta: this._color.bind(this, 45, true), + bgCyan: this._color.bind(this, 46, true), + bgWhite: this._color.bind(this, 47, true), + }; + + private getFormattedDatetime(): string { + const date = new Date(); + const formatter = new Intl.DateTimeFormat('en', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + }); + return formatter.format(date); + } + + success(message: string) { + const formattedDate = this.getFormattedDatetime(); + + console.log( + this.coloredText.white(formattedDate) + + ' ' + + this.coloredText.yellow(`[${this.serviceName}]`) + + ' ' + + this.coloredText.green(message), + ); + } + + info(message: string) { + const formattedDate = this.getFormattedDatetime(); + + console.log( + this.coloredText.white(formattedDate) + + ' ' + + this.coloredText.yellow(`[${this.serviceName}]`) + + ' ' + + this.coloredText.yellow(message), + ); + } + + error(message: string) { + const formattedDate = this.getFormattedDatetime(); + + console.log( + this.coloredText.white(formattedDate) + + ' ' + + this.coloredText.yellow(`[${this.serviceName}]`) + + ' ' + + this.coloredText.red(message), + ); + } +} diff --git a/src/operationsRunner.ts b/src/features/operationRunner.ts similarity index 78% rename from src/operationsRunner.ts rename to src/features/operationRunner.ts index 2a64fc0..ba70e0b 100644 --- a/src/operationsRunner.ts +++ b/src/features/operationRunner.ts @@ -1,9 +1,9 @@ -import { ConfigDto } from './common/dto'; -import * as operations from './features/basic.operations'; -import { filterPackageJson } from './common/package-utils'; -import { replaceEnvPlaceholders } from './features/env.operations'; +import { ConfigDto } from '../commons/dtos'; +import * as operations from './operations/basic.operations'; +import { filterPackageJson } from '../commons/package-utils'; +import { replaceEnvPlaceholders } from './operations/env.operations'; -export const operationsRunner = ( +export const operationRunner = ( packProps: Record, config: ConfigDto, env: Record, diff --git a/src/features/basic.operations.ts b/src/features/operations/basic.operations.ts similarity index 94% rename from src/features/basic.operations.ts rename to src/features/operations/basic.operations.ts index fa84221..183b687 100644 --- a/src/features/basic.operations.ts +++ b/src/features/operations/basic.operations.ts @@ -1,4 +1,4 @@ -import { filterPackageJson } from '../common/package-utils'; +import { filterPackageJson } from '../../commons/package-utils'; export const add = ( packProps: Record, diff --git a/src/features/env.operations.ts b/src/features/operations/env.operations.ts similarity index 100% rename from src/features/env.operations.ts rename to src/features/operations/env.operations.ts diff --git a/src/main.ts b/src/main.ts index e084608..1c27a0d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,16 +1,25 @@ import { dirname } from 'path'; -import { backup, getPackageJson, restore } from './common/package-utils'; -import { getConfig } from './common/utils'; -import { Commander } from './commander'; +import { backup, getPackageJson, restore } from './commons/package-utils'; +import { getConfig } from './commons/utils'; +import { packageCommand } from './commanders'; +import { Logger } from './commons/utils/logger'; // setting global variable to the parent directory. global._projectDir = dirname(__dirname); +// setting global logger. +global._logger = new Logger('Repackify'); + +global.configs = { + packageDir: `${global._projectDir}/package.json`, + backupDir: `${global._projectDir}/package.backup`, +}; + async function main() { - const packageJson = await getPackageJson(); - const backupPackage = await backup(packageJson); + const packageJson = await getPackageJson(global.configs.packageDir); + const backupPackage = await backup(packageJson, global.configs.backupDir); console.log('Backup complete'); - await restore(backupPackage); + await restore(backupPackage, global.configs.packageDir); console.log('Restore complete'); const config = getConfig(packageJson); @@ -19,50 +28,4 @@ async function main() { // main(); -// console.log(process.argv.slice(2)); - -new Commander({ - command: 'test', - commandOptions: [ - { - option: '--option', - shortOption: '-o', - required: true, - }, - { - option: '--t', - shortOption: '-t', - }, - ], - script: (options) => { - console.log(options); - }, - subCommands: [ - new Commander({ - command: 'sub', - commandOptions: [ - { - option: '--sub', - shortOption: '-s', - required: true, - }, - ], - script: (options) => { - console.log(options); - }, - }), - new Commander({ - command: 'sub2', - commandOptions: [ - { - option: '--sub2', - shortOption: '-s2', - required: true, - }, - ], - script: (options) => { - console.log(options); - }, - }), - ], -}).run(['test', 'sub', '-s', 'value']); +packageCommand.run(process.argv.slice(2));