@uxland/harmonix-cli 0.0.1 → 0.0.2

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 +50 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -8,32 +8,74 @@ 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
+ } catch (err) {
27
+ console.warn("⚠️ Warning: Error reading .harmonixrc:", err.message);
28
+ }
29
+ }
30
+
31
+ return config;
32
+ }
33
+
11
34
  program
12
35
  .command('publish')
13
- .option('--url <url>', 'Backend URL', 'https://preproduccio.componentssiscat.hes.catsalut.intranet.gencat.cat/api/plugins/version')
36
+ .option('--repository <repository>', 'Backend URL (overrides .harmonixrc)', 'https://preproduccio.componentssiscat.hes.catsalut.intranet.gencat.cat/api/plugins/version')
37
+ .option('--api-key <apiKey>', 'API Key (overrides .harmonixrc)')
14
38
  .action(async (opts) => {
15
39
  try {
16
- const filePath = path.resolve(process.cwd(), "dist", "index.js");
40
+ const config = getConfig();
17
41
  const packageJsonPath = path.resolve(process.cwd(), "package.json");
18
42
 
19
- if (!fs.existsSync(filePath)) {
20
- console.error(`File not found: ${filePath}`);
43
+ if (!fs.existsSync(packageJsonPath)) {
44
+ console.error(`package.json not found in: ${process.cwd()}`);
21
45
  process.exit(1);
22
46
  }
23
47
 
24
- if (!fs.existsSync(packageJsonPath)) {
25
- console.error(`package.json not found in: ${process.cwd()}`);
48
+ const packageJson = require(packageJsonPath);
49
+ const { name: pluginId, version: versionNumber, module } = packageJson;
50
+
51
+ if (!module) {
52
+ console.error("❌ 'module' field not found in package.json");
53
+ process.exit(1);
54
+ }
55
+
56
+ const filePath = path.resolve(process.cwd(), module);
57
+ if (!fs.existsSync(filePath)) {
58
+ console.error(`Compiled bundle file not found: ${filePath}`);
26
59
  process.exit(1);
27
60
  }
28
61
 
29
- const { name: pluginId, version: versionNumber } = require(packageJsonPath);
30
62
  const formData = new FormData();
31
63
  formData.append("versionNumber", versionNumber);
32
64
  formData.append("pluginId", pluginId);
33
65
  formData.append('file', fs.createReadStream(filePath));
34
66
 
67
+ const repository = opts.repository || config.repository;
68
+ const apiKey = opts.apiKey || config.apiKey;
69
+
70
+ if(!apiKey){
71
+ throw new Error("No api key configured")
72
+ }
73
+
74
+ const headers = {
75
+ 'x-api-key': apiKey
76
+ };
35
77
 
36
- const response = await axios.post(opts.url, formData);
78
+ const response = await axios.post(repository, formData, { headers });
37
79
 
38
80
  console.log('✅ Plugin published:', response.data);
39
81
  } 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.2",
4
4
  "bin": {
5
5
  "harmonix": "index.js"
6
6
  },