@onexapis/cli 1.0.3 → 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/dist/cli.js CHANGED
@@ -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,12 @@ 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
+ }
2699
2716
  dotenv__default.default.config({ path: path__default.default.join(os__default.default.homedir(), ".onex", ".env"), quiet: true });
2700
2717
  var program = new commander.Command();
2701
2718
  program.name("onex").description("CLI tool for OneX theme development").version("0.1.0");