ztechno_cli 0.0.5 → 0.0.7

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.
@@ -0,0 +1,21 @@
1
+ interface Task {
2
+ name: string;
3
+ command: string;
4
+ dirProject: string;
5
+ }
6
+ export declare class Runner {
7
+ private tasks;
8
+ private exiting;
9
+ private readonly colors;
10
+ /**
11
+ * Create a new runner.
12
+ * @param tasks - List of tasks to run in parallel.
13
+ * @param useColors - Whether to colorize the task name prefix (default: true).
14
+ */
15
+ constructor(tasks: Task[], useColors?: boolean);
16
+ /** Terminates all running processes. */
17
+ exit(): void;
18
+ /** Adds a prefix to each non-empty line of text. */
19
+ addPrefix(text: string, prefix: string): string;
20
+ }
21
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Runner = void 0;
4
+ const child_process_1 = require("child_process");
5
+ class Runner {
6
+ /**
7
+ * Create a new runner.
8
+ * @param tasks - List of tasks to run in parallel.
9
+ * @param useColors - Whether to colorize the task name prefix (default: true).
10
+ */
11
+ constructor(tasks, useColors = true) {
12
+ this.tasks = [];
13
+ this.exiting = false;
14
+ this.colors = [
15
+ '\x1b[33m', // yellow
16
+ '\x1b[34m', // blue
17
+ '\x1b[35m', // magenta
18
+ '\x1b[36m', // cyan
19
+ ];
20
+ tasks.forEach((task, index) => {
21
+ // Split the command into command and arguments
22
+ const args = task.command.split(' ');
23
+ const command = args.shift();
24
+ // Color the process prefix for output
25
+ const color = this.colors[index % this.colors.length];
26
+ const reset = '\x1b[0m';
27
+ const name = useColors ? `${color}${task.name}:${reset}` : `${task.name}:`;
28
+ // Spawn the child process
29
+ const childProcess = (0, child_process_1.spawn)(command, args, {
30
+ env: process.env,
31
+ cwd: task.dirProject,
32
+ shell: true,
33
+ });
34
+ // Prefix the output and write to stdout
35
+ childProcess.stdout.on('data', (data) => {
36
+ process.stdout.write(this.addPrefix(data.toString(), name));
37
+ });
38
+ // Prefix the error output and write to stderr
39
+ childProcess.stderr.on('data', (data) => {
40
+ process.stderr.write(this.addPrefix(data.toString(), name));
41
+ });
42
+ // When any process closes, start termination of all processes
43
+ childProcess.on('close', (code, signal) => {
44
+ if (code !== null) {
45
+ console.log(`${name} exited with code ${code}`);
46
+ }
47
+ else if (signal) {
48
+ console.log(`${name} was killed with signal ${signal}`);
49
+ }
50
+ this.exit();
51
+ });
52
+ // If any process fails to start, terminate all processes
53
+ childProcess.on('error', (error) => {
54
+ console.error(`${name} failed to start: ${error.message}`);
55
+ this.exit();
56
+ });
57
+ this.tasks.push({ name, childProcess });
58
+ });
59
+ }
60
+ /** Terminates all running processes. */
61
+ exit() {
62
+ if (!this.exiting) {
63
+ this.exiting = true;
64
+ this.tasks.forEach((task) => {
65
+ if (!task.childProcess.killed) {
66
+ task.childProcess.kill();
67
+ }
68
+ });
69
+ }
70
+ }
71
+ /** Adds a prefix to each non-empty line of text. */
72
+ addPrefix(text, prefix) {
73
+ return text
74
+ .split('\n')
75
+ .map((line) => (line ? `${prefix} ${line}` : ''))
76
+ .join('\n');
77
+ }
78
+ }
79
+ exports.Runner = Runner;
package/lib/index.d.ts CHANGED
@@ -0,0 +1 @@
1
+ export * from './helpers/Runner';
package/lib/index.js CHANGED
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./helpers/Runner"), exports);
@@ -8,6 +8,7 @@ exports.dockerBuild = dockerBuild;
8
8
  const child_process_1 = require("child_process");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
+ const dotenv_1 = require("dotenv");
11
12
  // ANSI color helpers
12
13
  const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
13
14
  const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
@@ -27,6 +28,7 @@ function loadPackageJson() {
27
28
  * @param opt.context - Docker build context path (defaults to ".")
28
29
  */
29
30
  function dockerBuild(opt) {
31
+ (0, dotenv_1.config)({ path: path_1.default.join(process.cwd(), '.env'), quiet: true });
30
32
  const pkg = loadPackageJson();
31
33
  const packagename = opt?.packagename || pkg.name;
32
34
  const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
@@ -8,6 +8,7 @@ exports.dockerPush = dockerPush;
8
8
  const child_process_1 = require("child_process");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
+ const dotenv_1 = require("dotenv");
11
12
  // ANSI color helpers
12
13
  const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
13
14
  const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
@@ -26,6 +27,7 @@ function loadPackageJson() {
26
27
  * @param opt.tag - Override the tag (defaults to "latest")
27
28
  */
28
29
  function dockerPush(opt) {
30
+ (0, dotenv_1.config)({ path: path_1.default.join(process.cwd(), '.env'), quiet: true });
29
31
  const pkg = loadPackageJson();
30
32
  const packagename = opt?.packagename || pkg.name;
31
33
  const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const Runner_1 = require("../helpers/Runner");
11
+ // Root directory: the folder this CLI is invoked from
12
+ const lib = process.cwd();
13
+ // npm binary based on OS
14
+ const prefixCmd = os_1.default.platform().startsWith('win') ? 'npm.cmd' : 'npm';
15
+ const tasks = fs_1.default.readdirSync(lib)
16
+ .map((dir) => {
17
+ const dirProject = path_1.default.join(lib, dir);
18
+ const pathPackage = path_1.default.join(dirProject, 'package.json');
19
+ if (!fs_1.default.existsSync(pathPackage)) {
20
+ return undefined;
21
+ }
22
+ console.log('dir', dir, dirProject);
23
+ return {
24
+ name: `Dev ${dir}`,
25
+ command: `${prefixCmd} run dev`,
26
+ dirProject,
27
+ };
28
+ })
29
+ .filter((it) => it !== undefined);
30
+ new Runner_1.Runner(tasks);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,7 +24,8 @@
24
24
  "ztechno-cli-build": "lib/scripts/docker-build.js",
25
25
  "ztechno-cli-push": "lib/scripts/docker-push.js",
26
26
  "ztechno-cli-update": "lib/scripts/docker-update.js",
27
- "ztechno-cli-publish": "lib/scripts/docker-publish.js"
27
+ "ztechno-cli-publish": "lib/scripts/docker-publish.js",
28
+ "ztechno-cli-run-dev-mode": "lib/scripts/run-dev-mode.js"
28
29
  },
29
30
  "keywords": [
30
31
  "ztechno",