@onexapis/cli 1.0.2 → 1.0.4

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/README.md CHANGED
@@ -213,10 +213,25 @@ onex clone simple -v 1.0.0 -o ./my-clone --no-install
213
213
 
214
214
  ## S3 Configuration
215
215
 
216
- The `upload`, `download`, and `clone` commands use S3 for storage. The CLI **automatically loads `.env.local` and `.env`** from the project root, so you only need to configure once:
216
+ The `upload`, `download`, and `clone` commands use S3 for storage. The CLI automatically loads env files in this order (first found wins):
217
+
218
+ 1. **Project-level**: `.env.local` and `.env` at the project root
219
+ 2. **Global**: `~/.onex/.env` (works from any directory)
220
+
221
+ ### Project config (recommended for teams)
222
+
223
+ ```bash
224
+ # .env.local (at project root — shared with the team via .env.example)
225
+ BUCKET_NAME=my-bucket
226
+ AWS_REGION=ap-southeast-1
227
+ AWS_ACCESS_KEY_ID=your-access-key
228
+ AWS_SECRET_ACCESS_KEY=your-secret-key
229
+ ```
230
+
231
+ ### Global config (for personal use / running outside a project)
217
232
 
218
233
  ```bash
219
- # .env.local (at project root)
234
+ # ~/.onex/.env
220
235
  BUCKET_NAME=my-bucket
221
236
  AWS_REGION=ap-southeast-1
222
237
  AWS_ACCESS_KEY_ID=your-access-key
@@ -226,8 +241,8 @@ AWS_SECRET_ACCESS_KEY=your-secret-key
226
241
  Then all S3 commands just work without extra flags:
227
242
 
228
243
  ```bash
229
- onex upload --theme simple # picks up bucket + credentials from .env.local
230
- onex clone simple # same
244
+ onex upload --theme simple # picks up config automatically
245
+ onex clone simple # works from any directory
231
246
  onex download -t simple # same
232
247
  ```
233
248
 
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  var path = require('path');
5
+ var os = require('os');
5
6
  var dotenv = require('dotenv');
6
7
  var fs = require('fs-extra');
7
8
  var ejs = require('ejs');
@@ -15,12 +16,12 @@ var archiver = require('archiver');
15
16
  var FormData = require('form-data');
16
17
  var fetch = require('node-fetch');
17
18
  var clientS3 = require('@aws-sdk/client-s3');
18
- var os = require('os');
19
19
  var AdmZip = require('adm-zip');
20
20
 
21
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
22
22
 
23
23
  var path__default = /*#__PURE__*/_interopDefault(path);
24
+ var os__default = /*#__PURE__*/_interopDefault(os);
24
25
  var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);
25
26
  var fs__default = /*#__PURE__*/_interopDefault(fs);
26
27
  var ejs__default = /*#__PURE__*/_interopDefault(ejs);
@@ -31,7 +32,6 @@ var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
31
32
  var archiver__default = /*#__PURE__*/_interopDefault(archiver);
32
33
  var FormData__default = /*#__PURE__*/_interopDefault(FormData);
33
34
  var fetch__default = /*#__PURE__*/_interopDefault(fetch);
34
- var os__default = /*#__PURE__*/_interopDefault(os);
35
35
  var AdmZip__default = /*#__PURE__*/_interopDefault(AdmZip);
36
36
 
37
37
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
@@ -174,18 +174,16 @@ function getProjectRoot() {
174
174
  }
175
175
  function getThemesDir() {
176
176
  const root = getProjectRoot();
177
- const themesDir = path__default.default.join(root, "themes");
178
- if (fs__default.default.existsSync(themesDir)) {
179
- return themesDir;
180
- }
181
- return path__default.default.join(root, "src/themes");
177
+ if (fs__default.default.existsSync(path__default.default.join(root, "themes"))) return path__default.default.join(root, "themes");
178
+ if (fs__default.default.existsSync(path__default.default.join(root, "src/themes"))) return path__default.default.join(root, "src/themes");
179
+ return path__default.default.dirname(root);
182
180
  }
183
181
  function getFeaturesDir() {
184
182
  return path__default.default.join(getProjectRoot(), "src/features");
185
183
  }
186
184
  function isOneXProject() {
187
185
  const root = getProjectRoot();
188
- return fs__default.default.existsSync(path__default.default.join(root, "themes")) || fs__default.default.existsSync(path__default.default.join(root, "src/themes"));
186
+ return fs__default.default.existsSync(path__default.default.join(root, "themes")) || fs__default.default.existsSync(path__default.default.join(root, "src/themes")) || fs__default.default.existsSync(path__default.default.join(root, "theme.config.ts")) || fs__default.default.existsSync(path__default.default.join(root, "bundle-entry.ts"));
189
187
  }
190
188
  function ensureOneXProject() {
191
189
  if (!isOneXProject()) {
@@ -679,6 +677,14 @@ export const homePageConfig: PageConfig = {
679
677
  async function createSectionCommand(name, options) {
680
678
  logger.header("Create New Section");
681
679
  ensureOneXProject();
680
+ if (!options.theme) {
681
+ const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
682
+ (f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f))
683
+ );
684
+ if (isStandaloneTheme) {
685
+ options.theme = path__default.default.basename(process.cwd());
686
+ }
687
+ }
682
688
  const sectionName = toKebabCase(name);
683
689
  if (!validateName(sectionName)) {
684
690
  logger.error(
@@ -910,6 +916,14 @@ ${hasTemplate ? `export { ${data.sectionNamePascal}Default } from "./${data.sect
910
916
  async function createBlockCommand(name, options) {
911
917
  logger.header("Create New Block");
912
918
  ensureOneXProject();
919
+ if (!options.theme) {
920
+ const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
921
+ (f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f))
922
+ );
923
+ if (isStandaloneTheme) {
924
+ options.theme = path__default.default.basename(process.cwd());
925
+ }
926
+ }
913
927
  const blockName = toKebabCase(name);
914
928
  if (!validateName(blockName)) {
915
929
  logger.error(
@@ -1470,8 +1484,8 @@ async function validateCommand(options) {
1470
1484
  }
1471
1485
  themeToValidate = options.theme;
1472
1486
  } else {
1473
- const manifestPath2 = path__default.default.join(process.cwd(), "manifest.ts");
1474
- if (fs__default.default.existsSync(manifestPath2)) {
1487
+ const isThemeDir = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"].some((f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f)));
1488
+ if (isThemeDir) {
1475
1489
  themeToValidate = path__default.default.basename(process.cwd());
1476
1490
  logger.info(`Validating current theme: ${themeToValidate}`);
1477
1491
  } else {
@@ -1648,8 +1662,8 @@ async function buildCommand(options) {
1648
1662
  process.exit(1);
1649
1663
  }
1650
1664
  } else {
1651
- const manifestPath = path__default.default.join(process.cwd(), "manifest.ts");
1652
- if (fs__default.default.existsSync(manifestPath)) {
1665
+ const isThemeDir = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"].some((f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f)));
1666
+ if (isThemeDir) {
1653
1667
  themePath = process.cwd();
1654
1668
  themeName = path__default.default.basename(themePath);
1655
1669
  logger.info(`Building current theme: ${themeName}`);
@@ -1750,8 +1764,8 @@ async function packageCommand(options) {
1750
1764
  process.exit(1);
1751
1765
  }
1752
1766
  } else {
1753
- const manifestPath = path__default.default.join(process.cwd(), "manifest.ts");
1754
- if (fs__default.default.existsSync(manifestPath)) {
1767
+ const isThemeDir = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"].some((f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f)));
1768
+ if (isThemeDir) {
1755
1769
  themePath = process.cwd();
1756
1770
  themeName = path__default.default.basename(themePath);
1757
1771
  logger.info(`Packaging current theme: ${themeName}`);
@@ -2693,9 +2707,13 @@ async function cloneCommand(themeName, options) {
2693
2707
  }
2694
2708
 
2695
2709
  // src/cli.ts
2696
- var projectRoot = getProjectRoot();
2697
- dotenv__default.default.config({ path: path__default.default.join(projectRoot, ".env.local"), quiet: true });
2698
- dotenv__default.default.config({ path: path__default.default.join(projectRoot, ".env"), quiet: true });
2710
+ try {
2711
+ const projectRoot = getProjectRoot();
2712
+ dotenv__default.default.config({ path: path__default.default.join(projectRoot, ".env.local"), quiet: true });
2713
+ dotenv__default.default.config({ path: path__default.default.join(projectRoot, ".env"), quiet: true });
2714
+ } catch (e) {
2715
+ }
2716
+ dotenv__default.default.config({ path: path__default.default.join(os__default.default.homedir(), ".onex", ".env"), quiet: true });
2699
2717
  var program = new commander.Command();
2700
2718
  program.name("onex").description("CLI tool for OneX theme development").version("0.1.0");
2701
2719
  program.command("init").description("Create a new OneX theme project").argument("[project-name]", "Name of the project").option(