@uxland/harmonix-cli 0.0.1 → 0.0.3
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/index.js +53 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8,32 +8,77 @@ const FormData = require('form-data');
|
|
|
8
8
|
|
|
9
9
|
console.log("reached index");
|
|
10
10
|
|
|
11
|
+
function getConfig() {
|
|
12
|
+
const configPath = path.resolve(process.cwd(), ".harmonixrc");
|
|
13
|
+
const config = {};
|
|
14
|
+
|
|
15
|
+
if (fs.existsSync(configPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const content = fs.readFileSync(configPath, 'utf8');
|
|
18
|
+
content.split('\n').forEach(line => {
|
|
19
|
+
if (line.trim()) {
|
|
20
|
+
const [key, value] = line.split('=');
|
|
21
|
+
if (key && value) {
|
|
22
|
+
config[key.trim()] = value.trim();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
console.log(config)
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.warn("⚠️ Warning: Error reading .harmonixrc:", err.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
|
|
11
35
|
program
|
|
12
36
|
.command('publish')
|
|
13
|
-
.option('--
|
|
37
|
+
.option('--registry <registry>', 'Backend URL (overrides .harmonixrc)')
|
|
38
|
+
.option('--api-key <apiKey>', 'API Key (overrides .harmonixrc)')
|
|
14
39
|
.action(async (opts) => {
|
|
15
40
|
try {
|
|
16
|
-
const
|
|
41
|
+
const config = getConfig();
|
|
17
42
|
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
18
43
|
|
|
19
|
-
if (!fs.existsSync(
|
|
20
|
-
console.error(`
|
|
44
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
45
|
+
console.error(`package.json not found in: ${process.cwd()}`);
|
|
21
46
|
process.exit(1);
|
|
22
47
|
}
|
|
23
48
|
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
const packageJson = require(packageJsonPath);
|
|
50
|
+
const { name: pluginId, version: versionNumber, module } = packageJson;
|
|
51
|
+
|
|
52
|
+
if (!module) {
|
|
53
|
+
console.error("❌ 'module' field not found in package.json");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const filePath = path.resolve(process.cwd(), module);
|
|
58
|
+
if (!fs.existsSync(filePath)) {
|
|
59
|
+
console.error(`Compiled bundle file not found: ${filePath}`);
|
|
26
60
|
process.exit(1);
|
|
27
61
|
}
|
|
28
62
|
|
|
29
|
-
const { name: pluginId, version: versionNumber } = require(packageJsonPath);
|
|
30
63
|
const formData = new FormData();
|
|
31
64
|
formData.append("versionNumber", versionNumber);
|
|
32
65
|
formData.append("pluginId", pluginId);
|
|
33
66
|
formData.append('file', fs.createReadStream(filePath));
|
|
34
67
|
|
|
68
|
+
const registry = opts.registry || config.registry;
|
|
69
|
+
const apiKey = opts.apiKey || config.apiKey;
|
|
35
70
|
|
|
36
|
-
|
|
71
|
+
if(!registry){
|
|
72
|
+
throw new Error("No registry configured")
|
|
73
|
+
}
|
|
74
|
+
if(!apiKey){
|
|
75
|
+
throw new Error("No api key configured")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const headers = {
|
|
79
|
+
'x-api-key': apiKey
|
|
80
|
+
};
|
|
81
|
+
const response = await axios.post(registry, formData, { headers });
|
|
37
82
|
|
|
38
83
|
console.log('✅ Plugin published:', response.data);
|
|
39
84
|
} catch (err) {
|