ztechno_core 0.0.100 → 0.0.102

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/index.d.ts CHANGED
@@ -7,5 +7,8 @@ import { ZUserService } from './user_service';
7
7
  export { middleware } from './express';
8
8
  export * from './typings';
9
9
  export * from './scripts/docker-update';
10
+ export * from './scripts/docker-build';
11
+ export * from './scripts/docker-push';
12
+ export * from './scripts/docker-publish';
10
13
  export * from './schema';
11
14
  export { ZEngineBase, ZCryptoService, ZMailService, ZSQLService, ZTranslateService, ZUserService };
package/lib/index.js CHANGED
@@ -89,5 +89,8 @@ Object.defineProperty(exports, 'middleware', {
89
89
  __exportStar(require('./typings'), exports);
90
90
  // Re-export specific scripts
91
91
  __exportStar(require('./scripts/docker-update'), exports);
92
+ __exportStar(require('./scripts/docker-build'), exports);
93
+ __exportStar(require('./scripts/docker-push'), exports);
94
+ __exportStar(require('./scripts/docker-publish'), exports);
92
95
  // Re-export all schema-related modules
93
96
  __exportStar(require('./schema'), exports);
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Build a Docker image tagged as <awsAccountId>/<packagename>:latest
4
+ * @param opt.packagename - Override the image name (defaults to package.json name)
5
+ * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
6
+ * @param opt.tag - Override the tag (defaults to "latest")
7
+ * @param opt.context - Docker build context path (defaults to ".")
8
+ */
9
+ export declare function dockerBuild(opt?: {
10
+ packagename?: string;
11
+ awsAccountId?: string;
12
+ tag?: string;
13
+ context?: string;
14
+ }): void;
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ var __importDefault =
4
+ (this && this.__importDefault) ||
5
+ function (mod) {
6
+ return mod && mod.__esModule ? mod : { default: mod };
7
+ };
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+ exports.dockerBuild = void 0;
10
+ const child_process_1 = require('child_process');
11
+ const path_1 = __importDefault(require('path'));
12
+ const fs_1 = __importDefault(require('fs'));
13
+ // ANSI color helpers
14
+ const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
15
+ const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
16
+ const cyan = (msg) => `\x1b[36m${msg}\x1b[0m`;
17
+ function loadPackageJson() {
18
+ const pkgPath = path_1.default.join(process.cwd(), 'package.json');
19
+ if (!fs_1.default.existsSync(pkgPath)) {
20
+ throw new Error(`No package.json found in ${process.cwd()}`);
21
+ }
22
+ return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
23
+ }
24
+ /**
25
+ * Build a Docker image tagged as <awsAccountId>/<packagename>:latest
26
+ * @param opt.packagename - Override the image name (defaults to package.json name)
27
+ * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
28
+ * @param opt.tag - Override the tag (defaults to "latest")
29
+ * @param opt.context - Docker build context path (defaults to ".")
30
+ */
31
+ function dockerBuild(opt) {
32
+ const pkg = loadPackageJson();
33
+ const packagename = opt?.packagename || pkg.name;
34
+ const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
35
+ const tag = opt?.tag || 'latest';
36
+ const context = opt?.context || '.';
37
+ if (!packagename) {
38
+ throw new Error('Missing package name. Set "name" in package.json or pass --name.');
39
+ }
40
+ if (!awsAccountId) {
41
+ throw new Error('Missing AWS Account ID. Set "config.awsAccountId" in package.json or AWS_ACCOUNT_ID env var.');
42
+ }
43
+ const image = `${awsAccountId}/${packagename}:${tag}`;
44
+ const cmd = `docker build -t ${image} ${context}`;
45
+ console.log(green(`[Docker Build]`));
46
+ console.log(cyan(`> ${cmd}`));
47
+ (0, child_process_1.execSync)(cmd, { stdio: 'inherit' });
48
+ console.log(green(`✓ Built ${image}`));
49
+ }
50
+ exports.dockerBuild = dockerBuild;
51
+ const USAGE = `
52
+ Usage:
53
+ ztechno-docker-build [options]
54
+
55
+ Options:
56
+ --name <name> Override image name (default: package.json "name")
57
+ --account <id> Override AWS Account ID (default: package.json "config.awsAccountId")
58
+ --tag <tag> Override tag (default: "latest")
59
+ --context <path> Docker build context (default: ".")
60
+ -h, --help Show this help
61
+
62
+ package.json format:
63
+ {
64
+ "name": "my-image",
65
+ "config": {
66
+ "awsAccountId": "00028463827"
67
+ }
68
+ }
69
+ `.trim();
70
+ if (require.main === module) {
71
+ try {
72
+ const args = process.argv.slice(2);
73
+ if (args.includes('--help') || args.includes('-h')) {
74
+ console.log(USAGE);
75
+ process.exit(0);
76
+ }
77
+ const getArg = (flag) => {
78
+ const idx = args.indexOf(flag);
79
+ return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
80
+ };
81
+ dockerBuild({
82
+ packagename: getArg('--name'),
83
+ awsAccountId: getArg('--account'),
84
+ tag: getArg('--tag'),
85
+ context: getArg('--context'),
86
+ });
87
+ } catch (err) {
88
+ console.error(red(`✗ Error: ${err.message}`));
89
+ process.exit(1);
90
+ }
91
+ }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run the full Docker publish pipeline: build → push → update
4
+ * All options are auto-detected from package.json and .env
5
+ * @param opt.packagename - Override the image name
6
+ * @param opt.awsAccountId - Override the AWS Account ID
7
+ * @param opt.tag - Override the tag (defaults to "latest")
8
+ * @param opt.context - Docker build context path (defaults to ".")
9
+ * @param opt.port - Override the port for remote update
10
+ * @param opt.volumes - Override volumes for remote update
11
+ */
12
+ export declare function dockerPublish(opt?: {
13
+ packagename?: string;
14
+ awsAccountId?: string;
15
+ tag?: string;
16
+ context?: string;
17
+ port?: string | number;
18
+ volumes?: string[];
19
+ }): Promise<void>;
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ var __importDefault =
4
+ (this && this.__importDefault) ||
5
+ function (mod) {
6
+ return mod && mod.__esModule ? mod : { default: mod };
7
+ };
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+ exports.dockerPublish = void 0;
10
+ const path_1 = __importDefault(require('path'));
11
+ const fs_1 = __importDefault(require('fs'));
12
+ const docker_build_1 = require('./docker-build');
13
+ const docker_push_1 = require('./docker-push');
14
+ const docker_update_1 = require('./docker-update');
15
+ // ANSI color helpers
16
+ const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
17
+ const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
18
+ const cyan = (msg) => `\x1b[36m${msg}\x1b[0m`;
19
+ function loadPackageJson() {
20
+ const pkgPath = path_1.default.join(process.cwd(), 'package.json');
21
+ if (!fs_1.default.existsSync(pkgPath)) {
22
+ throw new Error(`No package.json found in ${process.cwd()}`);
23
+ }
24
+ return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
25
+ }
26
+ /**
27
+ * Run the full Docker publish pipeline: build → push → update
28
+ * All options are auto-detected from package.json and .env
29
+ * @param opt.packagename - Override the image name
30
+ * @param opt.awsAccountId - Override the AWS Account ID
31
+ * @param opt.tag - Override the tag (defaults to "latest")
32
+ * @param opt.context - Docker build context path (defaults to ".")
33
+ * @param opt.port - Override the port for remote update
34
+ * @param opt.volumes - Override volumes for remote update
35
+ */
36
+ async function dockerPublish(opt) {
37
+ const pkg = loadPackageJson();
38
+ const packagename = opt?.packagename || pkg.name;
39
+ const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
40
+ const tag = opt?.tag || 'latest';
41
+ console.log(cyan(`\n[Docker Publish Pipeline]`));
42
+ console.log(cyan(` Image: ${awsAccountId}/${packagename}:${tag}\n`));
43
+ // Step 1: Build
44
+ console.log(cyan(`── Step 1/3: Build ──`));
45
+ (0, docker_build_1.dockerBuild)({ packagename, awsAccountId, tag, context: opt?.context });
46
+ // Step 2: Push
47
+ console.log(cyan(`\n── Step 2/3: Push ──`));
48
+ (0, docker_push_1.dockerPush)({ packagename, awsAccountId, tag });
49
+ // Step 3: Update remote
50
+ console.log(cyan(`\n── Step 3/3: Update Remote ──`));
51
+ const port = opt?.port || pkg.config?.port;
52
+ let volumes = opt?.volumes;
53
+ if (!volumes && pkg.config?.volumes) {
54
+ volumes = Array.isArray(pkg.config.volumes) ? pkg.config.volumes : pkg.config.volumes.split(',').filter(Boolean);
55
+ }
56
+ if (!port) {
57
+ console.log(green(`✓ Build & push complete. Skipping remote update (no port configured).`));
58
+ return;
59
+ }
60
+ await (0, docker_update_1.updateDocker)({
61
+ packagename: packagename,
62
+ port,
63
+ volumes,
64
+ c: console,
65
+ });
66
+ console.log(green(`\n✓ Publish pipeline complete!`));
67
+ }
68
+ exports.dockerPublish = dockerPublish;
69
+ const USAGE = `
70
+ Usage:
71
+ ztechno-docker-publish [options]
72
+
73
+ Runs: docker build → docker push → remote update
74
+
75
+ Options:
76
+ --name <name> Override image name (default: package.json "name")
77
+ --account <id> Override AWS Account ID (default: package.json "config.awsAccountId")
78
+ --tag <tag> Override tag (default: "latest")
79
+ --context <path> Docker build context (default: ".")
80
+ -h, --help Show this help
81
+
82
+ package.json format:
83
+ {
84
+ "name": "my-image",
85
+ "config": {
86
+ "awsAccountId": "00028463827",
87
+ "port": 3000,
88
+ "volumes": ["/data:/app/data"]
89
+ }
90
+ }
91
+ `.trim();
92
+ if (require.main === module) {
93
+ const args = process.argv.slice(2);
94
+ if (args.includes('--help') || args.includes('-h')) {
95
+ console.log(USAGE);
96
+ process.exit(0);
97
+ }
98
+ const getArg = (flag) => {
99
+ const idx = args.indexOf(flag);
100
+ return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
101
+ };
102
+ dockerPublish({
103
+ packagename: getArg('--name'),
104
+ awsAccountId: getArg('--account'),
105
+ tag: getArg('--tag'),
106
+ context: getArg('--context'),
107
+ }).catch((err) => {
108
+ console.error(red(`✗ Error: ${err.message}`));
109
+ process.exit(1);
110
+ });
111
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Push a Docker image tagged as <awsAccountId>/<packagename>:latest
4
+ * @param opt.packagename - Override the image name (defaults to package.json name)
5
+ * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
6
+ * @param opt.tag - Override the tag (defaults to "latest")
7
+ */
8
+ export declare function dockerPush(opt?: { packagename?: string; awsAccountId?: string; tag?: string }): void;
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ var __importDefault =
4
+ (this && this.__importDefault) ||
5
+ function (mod) {
6
+ return mod && mod.__esModule ? mod : { default: mod };
7
+ };
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+ exports.dockerPush = void 0;
10
+ const child_process_1 = require('child_process');
11
+ const path_1 = __importDefault(require('path'));
12
+ const fs_1 = __importDefault(require('fs'));
13
+ // ANSI color helpers
14
+ const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
15
+ const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
16
+ const cyan = (msg) => `\x1b[36m${msg}\x1b[0m`;
17
+ function loadPackageJson() {
18
+ const pkgPath = path_1.default.join(process.cwd(), 'package.json');
19
+ if (!fs_1.default.existsSync(pkgPath)) {
20
+ throw new Error(`No package.json found in ${process.cwd()}`);
21
+ }
22
+ return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
23
+ }
24
+ /**
25
+ * Push a Docker image tagged as <awsAccountId>/<packagename>:latest
26
+ * @param opt.packagename - Override the image name (defaults to package.json name)
27
+ * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
28
+ * @param opt.tag - Override the tag (defaults to "latest")
29
+ */
30
+ function dockerPush(opt) {
31
+ const pkg = loadPackageJson();
32
+ const packagename = opt?.packagename || pkg.name;
33
+ const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
34
+ const tag = opt?.tag || 'latest';
35
+ if (!packagename) {
36
+ throw new Error('Missing package name. Set "name" in package.json or pass --name.');
37
+ }
38
+ if (!awsAccountId) {
39
+ throw new Error('Missing AWS Account ID. Set "config.awsAccountId" in package.json or AWS_ACCOUNT_ID env var.');
40
+ }
41
+ const image = `${awsAccountId}/${packagename}:${tag}`;
42
+ const cmd = `docker push ${image}`;
43
+ console.log(green(`[Docker Push]`));
44
+ console.log(cyan(`> ${cmd}`));
45
+ (0, child_process_1.execSync)(cmd, { stdio: 'inherit' });
46
+ console.log(green(`✓ Pushed ${image}`));
47
+ }
48
+ exports.dockerPush = dockerPush;
49
+ const USAGE = `
50
+ Usage:
51
+ ztechno-docker-push [options]
52
+
53
+ Options:
54
+ --name <name> Override image name (default: package.json "name")
55
+ --account <id> Override AWS Account ID (default: package.json "config.awsAccountId")
56
+ --tag <tag> Override tag (default: "latest")
57
+ -h, --help Show this help
58
+
59
+ package.json format:
60
+ {
61
+ "name": "my-image",
62
+ "config": {
63
+ "awsAccountId": "00028463827"
64
+ }
65
+ }
66
+ `.trim();
67
+ if (require.main === module) {
68
+ try {
69
+ const args = process.argv.slice(2);
70
+ if (args.includes('--help') || args.includes('-h')) {
71
+ console.log(USAGE);
72
+ process.exit(0);
73
+ }
74
+ const getArg = (flag) => {
75
+ const idx = args.indexOf(flag);
76
+ return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
77
+ };
78
+ dockerPush({
79
+ packagename: getArg('--name'),
80
+ awsAccountId: getArg('--account'),
81
+ tag: getArg('--tag'),
82
+ });
83
+ } catch (err) {
84
+ console.error(red(`✗ Error: ${err.message}`));
85
+ process.exit(1);
86
+ }
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_core",
3
- "version": "0.0.100",
3
+ "version": "0.0.102",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -21,7 +21,10 @@
21
21
  "update": "npm run build && npm version patch && npm publish"
22
22
  },
23
23
  "bin": {
24
- "ztechno-docker-update": "lib/scripts/docker-update.js"
24
+ "ztechno-docker-update": "lib/scripts/docker-update.js",
25
+ "ztechno-docker-build": "lib/scripts/docker-build.js",
26
+ "ztechno-docker-push": "lib/scripts/docker-push.js",
27
+ "ztechno-docker-publish": "lib/scripts/docker-publish.js"
25
28
  },
26
29
  "keywords": [
27
30
  "ztechno",