@sublay/cli 7.1.0 → 7.2.0

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/dist/index.js +53 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -60,6 +60,34 @@ async function detectTypeScript() {
60
60
  return false;
61
61
  }
62
62
  }
63
+ async function detectFramework(platform) {
64
+ if (platform !== "react") {
65
+ return platform;
66
+ }
67
+ try {
68
+ const packageJsonPath = path.join(process.cwd(), "package.json");
69
+ if (!await fs.pathExists(packageJsonPath)) {
70
+ return "other";
71
+ }
72
+ const packageJson2 = await fs.readJson(packageJsonPath);
73
+ const deps = {
74
+ ...packageJson2.dependencies,
75
+ ...packageJson2.devDependencies
76
+ };
77
+ if (deps["next"]) {
78
+ return "next";
79
+ }
80
+ if (deps["react-scripts"]) {
81
+ return "cra";
82
+ }
83
+ if (deps["vite"]) {
84
+ return "vite";
85
+ }
86
+ return "other";
87
+ } catch (error) {
88
+ return "other";
89
+ }
90
+ }
63
91
 
64
92
  // src/commands/init.ts
65
93
  async function init() {
@@ -653,6 +681,7 @@ function convertFileExtension(filePath) {
653
681
  // src/commands/add.ts
654
682
  var STRINGS_FILE = "utils/strings.ts";
655
683
  var DEFAULT_LANGUAGE = "en";
684
+ var ENV_FILE = "utils/env.ts";
656
685
  var FETCH_CONCURRENCY = 8;
657
686
  async function add(componentName, options = {}) {
658
687
  const spinner = ora("Initializing...").start();
@@ -712,6 +741,11 @@ async function add(componentName, options = {}) {
712
741
  (dep) => renameForPlatform(dep, config)
713
742
  );
714
743
  const languageFile = resolveLanguageFile(registry, options.lang, componentName);
744
+ const frameworkFile = resolveFrameworkFile(
745
+ registry,
746
+ await detectFramework(config.platform),
747
+ componentName
748
+ );
715
749
  const platform = getRegistryPlatform(config);
716
750
  const location = getComponentLocation(componentName, config);
717
751
  const componentManifestLabel = `${location}/registry.json`;
@@ -747,7 +781,7 @@ async function add(componentName, options = {}) {
747
781
  const fileContent = shared ? await fetchSharedFile(source, platform, registryPath) : await fetchFile(
748
782
  source,
749
783
  location,
750
- languageFile && registryPath === STRINGS_FILE ? languageFile : registryPath
784
+ languageFile && registryPath === STRINGS_FILE ? languageFile : frameworkFile && registryPath === ENV_FILE ? frameworkFile : registryPath
751
785
  );
752
786
  for (const used of findSharedAliasImports(fileContent)) {
753
787
  if (used.platform !== platform || !installedPieces.has(used.piece)) {
@@ -876,6 +910,24 @@ function resolveLanguageFile(registry, lang, componentName) {
876
910
  }
877
911
  return languageFile;
878
912
  }
913
+ function resolveFrameworkFile(registry, framework, componentName) {
914
+ const frameworks = registry.frameworks && typeof registry.frameworks === "object" ? registry.frameworks : {};
915
+ const frameworkFile = Object.prototype.hasOwnProperty.call(frameworks, framework) ? frameworks[framework] : void 0;
916
+ if (frameworkFile === void 0) {
917
+ return null;
918
+ }
919
+ if (typeof frameworkFile !== "string" || !/^[A-Za-z0-9_][A-Za-z0-9._/-]*$/.test(frameworkFile) || frameworkFile.split("/").includes("..")) {
920
+ throw new RegistryError(
921
+ `The "${framework}" entry under "frameworks" for ${componentName} is not a usable file path.`
922
+ );
923
+ }
924
+ if (!registry.files.some((file) => file.path === ENV_FILE)) {
925
+ throw new RegistryError(
926
+ `${componentName} lists frameworks but has no ${ENV_FILE} to put them in.`
927
+ );
928
+ }
929
+ return frameworkFile;
930
+ }
879
931
  function readSharedNames(registry, manifestLabel) {
880
932
  const { shared } = registry;
881
933
  if (shared === void 0 || shared === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublay/cli",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "author": "Sublay, maintained by Yanay Tsabary",