@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.
Files changed (2) hide show
  1. package/index.js +53 -8
  2. 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('--url <url>', 'Backend URL', 'https://preproduccio.componentssiscat.hes.catsalut.intranet.gencat.cat/api/plugins/version')
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 filePath = path.resolve(process.cwd(), "dist", "index.js");
41
+ const config = getConfig();
17
42
  const packageJsonPath = path.resolve(process.cwd(), "package.json");
18
43
 
19
- if (!fs.existsSync(filePath)) {
20
- console.error(`File not found: ${filePath}`);
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
- if (!fs.existsSync(packageJsonPath)) {
25
- console.error(`package.json not found in: ${process.cwd()}`);
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
- const response = await axios.post(opts.url, formData);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/harmonix-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "bin": {
5
5
  "harmonix": "index.js"
6
6
  },