ztechno_core 0.0.99 → 0.0.100

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.
@@ -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
- * Parse options from a .env file in the current working directory.
98
- * Required keys: packagename, port, ZTECHNO_API_SECRET
99
- * Optional key: volumes (comma-separated)
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
- const envPath = process.cwd() + '/.env';
103
- console.log(`Loading env from: ${envPath}`);
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
- const packagename = cfg.parsed?.packagename || process.env.packagename;
109
- const port = cfg.parsed?.port || process.env.port;
110
- const volumes = cfg.parsed?.volumes || process.env.volumes;
111
- if (!packagename || !port) {
112
- throw new Error('Missing required .env variables: packagename and port');
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
- return { packagename, port, volumes: volumes?.split(',').filter(Boolean) };
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 (reads from .env file)
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.99",
3
+ "version": "0.0.100",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",