ztechno_core 0.0.99 → 0.0.101
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 +2 -0
- package/lib/index.js +2 -0
- package/lib/scripts/docker-build.d.ts +14 -0
- package/lib/scripts/docker-build.js +91 -0
- package/lib/scripts/docker-push.d.ts +8 -0
- package/lib/scripts/docker-push.js +87 -0
- package/lib/scripts/docker-update.js +62 -13
- package/package.json +4 -2
package/lib/index.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ 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';
|
|
10
12
|
export * from './schema';
|
|
11
13
|
export { ZEngineBase, ZCryptoService, ZMailService, ZSQLService, ZTranslateService, ZUserService };
|
package/lib/index.js
CHANGED
|
@@ -89,5 +89,7 @@ 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);
|
|
92
94
|
// Re-export all schema-related modules
|
|
93
95
|
__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,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
|
+
}
|
|
@@ -9,6 +9,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
9
9
|
exports.updateDocker = void 0;
|
|
10
10
|
const http_1 = __importDefault(require('http'));
|
|
11
11
|
const crypto_1 = __importDefault(require('crypto'));
|
|
12
|
+
const path_1 = __importDefault(require('path'));
|
|
13
|
+
const fs_1 = __importDefault(require('fs'));
|
|
12
14
|
const dotenv_1 = require('dotenv');
|
|
13
15
|
const crypto_service_1 = require('../crypto_service');
|
|
14
16
|
// ANSI color helpers
|
|
@@ -94,35 +96,82 @@ function updateDocker(opt) {
|
|
|
94
96
|
}
|
|
95
97
|
exports.updateDocker = updateDocker;
|
|
96
98
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
99
|
+
* Read the consumer's package.json from the current working directory.
|
|
100
|
+
* Returns null if not found or unreadable.
|
|
101
|
+
*/
|
|
102
|
+
function loadPackageJson() {
|
|
103
|
+
try {
|
|
104
|
+
const pkgPath = path_1.default.join(process.cwd(), 'package.json');
|
|
105
|
+
if (!fs_1.default.existsSync(pkgPath)) return null;
|
|
106
|
+
return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Auto-detect options from .env and/or package.json in the current working directory.
|
|
113
|
+
*
|
|
114
|
+
* Resolution order for each field:
|
|
115
|
+
* 1. .env / environment variable
|
|
116
|
+
* 2. package.json (name → packagename, config.port → port, config.volumes → volumes)
|
|
117
|
+
*
|
|
118
|
+
* Required: packagename, port, ZTECHNO_API_SECRET (env only)
|
|
119
|
+
* Optional: volumes (comma-separated)
|
|
100
120
|
*/
|
|
101
121
|
function loadOptionsFromEnv() {
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
// Load .env file
|
|
123
|
+
const envPath = path_1.default.join(process.cwd(), '.env');
|
|
104
124
|
const cfg = (0, dotenv_1.config)({ path: envPath });
|
|
105
|
-
if (cfg.error) {
|
|
125
|
+
if (cfg.error && cfg.error.message && !cfg.error.message.includes('ENOENT')) {
|
|
106
126
|
throw cfg.error;
|
|
107
127
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
128
|
+
// Load package.json as fallback
|
|
129
|
+
const pkg = loadPackageJson();
|
|
130
|
+
const packagename = cfg.parsed?.packagename || process.env.packagename || pkg?.name;
|
|
131
|
+
const port =
|
|
132
|
+
cfg.parsed?.port || process.env.port || (pkg?.config?.port != null ? String(pkg.config.port) : undefined);
|
|
133
|
+
const volumesRaw = cfg.parsed?.volumes || process.env.volumes || pkg?.config?.volumes;
|
|
134
|
+
if (pkg) {
|
|
135
|
+
console.log(`Detected package.json: ${pkg.name || '(unnamed)'}`);
|
|
136
|
+
}
|
|
137
|
+
if (!packagename) {
|
|
138
|
+
throw new Error('Missing packagename. Set it in .env, environment, or package.json "name".');
|
|
139
|
+
}
|
|
140
|
+
if (!port) {
|
|
141
|
+
throw new Error('Missing port. Set it in .env, environment, or package.json "config.port".');
|
|
113
142
|
}
|
|
114
|
-
|
|
143
|
+
// Normalize volumes: accept string[] from package.json or comma-separated string from .env
|
|
144
|
+
let volumes;
|
|
145
|
+
if (Array.isArray(volumesRaw)) {
|
|
146
|
+
volumes = volumesRaw.filter(Boolean);
|
|
147
|
+
} else if (typeof volumesRaw === 'string') {
|
|
148
|
+
volumes = volumesRaw.split(',').filter(Boolean);
|
|
149
|
+
}
|
|
150
|
+
return { packagename, port, volumes };
|
|
115
151
|
}
|
|
116
152
|
const USAGE = `
|
|
117
153
|
Usage:
|
|
118
154
|
ztechno-docker-update <packagename>:<port>
|
|
119
|
-
ztechno-docker-update (
|
|
155
|
+
ztechno-docker-update (auto-detect from .env / package.json)
|
|
156
|
+
|
|
157
|
+
Auto-detection priority:
|
|
158
|
+
1. .env file → packagename, port, volumes, ZTECHNO_API_SECRET
|
|
159
|
+
2. package.json → "name" as packagename, "config.port", "config.volumes"
|
|
120
160
|
|
|
121
161
|
.env file format:
|
|
122
162
|
ZTECHNO_API_SECRET=your_secret
|
|
123
163
|
packagename=my-image
|
|
124
164
|
port=3000
|
|
125
165
|
volumes=/host/path:/container/path (optional, comma-separated)
|
|
166
|
+
|
|
167
|
+
package.json format:
|
|
168
|
+
{
|
|
169
|
+
"name": "my-image",
|
|
170
|
+
"config": {
|
|
171
|
+
"port": 3000,
|
|
172
|
+
"volumes": ["/host/path:/container/path", "/logs:/app/logs"]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
126
175
|
`.trim();
|
|
127
176
|
// Run if executed directly (node docker-update.js or npx ztechno-docker-update)
|
|
128
177
|
if (require.main === module) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ztechno_core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"description": "Core files for ztechno framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -21,7 +21,9 @@
|
|
|
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"
|
|
25
27
|
},
|
|
26
28
|
"keywords": [
|
|
27
29
|
"ztechno",
|