@bacons/apple-targets 0.0.9 → 0.0.10

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
@@ -97,14 +97,32 @@ There are certain values that are shared across targets. We use a predefined con
97
97
 
98
98
  Adding a file `pods.rb` in the root of the repo will enable you to modify the target settings for the project.
99
99
 
100
- The ruby module evaluates with global access to the property `podfile_properties` and the method `use_native_modules`.
100
+ The ruby module evaluates with global access to the property `podfile_properties`.
101
101
 
102
102
  For example, the following is useful for enabling React Native in an App Clip target:
103
103
 
104
104
  ```rb
105
+ require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
106
+
105
107
  exclude = []
106
108
  use_expo_modules!(exclude: exclude)
107
- config = use_native_modules!
109
+
110
+ if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
111
+ config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
112
+ else
113
+ config_command = [
114
+ 'node',
115
+ '--no-warnings',
116
+ '--eval',
117
+ 'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
118
+ 'react-native-config',
119
+ '--json',
120
+ '--platform',
121
+ 'ios'
122
+ ]
123
+ end
124
+
125
+ config = use_native_modules!(config_command)
108
126
 
109
127
  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
110
128
  use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']
package/build/index.d.ts CHANGED
@@ -4,5 +4,5 @@ export declare const withTargetsDir: ConfigPlugin<{
4
4
  appleTeamId?: string;
5
5
  match?: string;
6
6
  root?: string;
7
- }>;
7
+ } | void>;
8
8
  export { Config };
package/build/index.js CHANGED
@@ -9,11 +9,12 @@ const path_1 = __importDefault(require("path"));
9
9
  const withPodTargetExtension_1 = require("./withPodTargetExtension");
10
10
  const withWidget_1 = __importDefault(require("./withWidget"));
11
11
  const withXcparse_1 = require("./withXcparse");
12
- const withTargetsDir = (config, _a) => {
13
- var _b;
14
- var {
15
- // @ts-expect-error: not on type yet
16
- appleTeamId = (_b = config.ios) === null || _b === void 0 ? void 0 : _b.appleTeamId, root = "./targets", match = "*", } = _a;
12
+ const withTargetsDir = (config, _props) => {
13
+ var _a;
14
+ const { appleTeamId = (_a = config === null || config === void 0 ? void 0 : config.ios) === null || _a === void 0 ? void 0 : _a.appleTeamId, root = "./targets", match = "*", } = _props || {};
15
+ if (!appleTeamId) {
16
+ throw new Error(`You must specify an \`appleTeamId\` in your app config to use the \`withTargetsDir\` plugin.`);
17
+ }
17
18
  const projectRoot = config._internal.projectRoot;
18
19
  const targets = (0, glob_1.sync)(`${root}/${match}/expo-target.config.@(json|js)`, {
19
20
  // const targets = globSync(`./targets/action/expo-target.config.@(json|js)`, {
@@ -12,7 +12,9 @@ function safeSet(obj, key, value) {
12
12
  }
13
13
  obj = obj[segment];
14
14
  });
15
- obj[last] = value;
15
+ if (!obj[last]) {
16
+ obj[last] = value;
17
+ }
16
18
  return obj;
17
19
  }
18
20
  const withEASTargets = (config, { bundleIdentifier, targetName, entitlements }) => {
@@ -10,7 +10,6 @@ Dir.glob(File.join(__dir__, '..', 'targets', '**', 'pods.rb')).each do |target_f
10
10
  # Create a new binding with access to necessary methods and variables
11
11
  target_binding = binding
12
12
  target_binding.local_variable_set(:podfile_properties, podfile_properties)
13
- target_binding.local_variable_set(:config, use_native_modules!)
14
13
 
15
14
  # Evaluate the target file content in the new binding
16
15
  eval(File.read(target_file), target_binding, target_file)
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.withXcodeChanges = void 0;
7
7
  const xcode_1 = require("@bacons/xcode");
8
+ const json_1 = require("@bacons/xcode/json");
8
9
  const fs_1 = __importDefault(require("fs"));
9
10
  const glob_1 = require("glob");
10
11
  const path_1 = __importDefault(require("path"));
@@ -126,7 +127,7 @@ function createShareConfigurationList(project, { name, cwd, bundleId, deployment
126
127
  CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: "YES",
127
128
  CLANG_WARN_UNGUARDED_AVAILABILITY: "YES_AGGRESSIVE",
128
129
  CODE_SIGN_STYLE: "Automatic",
129
- DEBUG_INFORMATION_FORMAT: "dwarf",
130
+ DEBUG_INFORMATION_FORMAT: "dwarf", // NOTE
130
131
  GCC_C_LANGUAGE_STANDARD: "gnu11",
131
132
  GENERATE_INFOPLIST_FILE: "YES",
132
133
  CURRENT_PROJECT_VERSION: currentProjectVersion,
@@ -193,7 +194,7 @@ function createIMessageConfigurationList(project, { name, cwd, bundleId, deploym
193
194
  CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: "YES",
194
195
  CLANG_WARN_UNGUARDED_AVAILABILITY: "YES_AGGRESSIVE",
195
196
  CODE_SIGN_STYLE: "Automatic",
196
- DEBUG_INFORMATION_FORMAT: "dwarf",
197
+ DEBUG_INFORMATION_FORMAT: "dwarf", // NOTE
197
198
  GCC_C_LANGUAGE_STANDARD: "gnu11",
198
199
  GENERATE_INFOPLIST_FILE: "YES",
199
200
  CURRENT_PROJECT_VERSION: currentProjectVersion,
@@ -667,13 +668,56 @@ async function applyXcodeChanges(config, project, props) {
667
668
  }
668
669
  function syncMarketingVersions() {
669
670
  const mainVersion = getMainMarketingVersion(project);
670
- // console.log('main marketing version:', mainVersion)
671
671
  project.rootObject.props.targets.forEach((target) => {
672
672
  if (xcode_1.PBXNativeTarget.is(target)) {
673
673
  target.setBuildSetting("MARKETING_VERSION", mainVersion);
674
674
  }
675
675
  });
676
676
  }
677
+ function buildFileGroupHierarchy(files) {
678
+ const root = [];
679
+ function getOrCreateGroup(name, segment, group) {
680
+ const fullPath = path_1.default.join(magicCwd, name);
681
+ let newGroup = group.find((child) => child.props.isa === json_1.ISA.PBXGroup && child.props.path === fullPath);
682
+ if (!newGroup) {
683
+ newGroup = xcode_1.PBXGroup.create(project, {
684
+ name: segment,
685
+ path: fullPath,
686
+ children: [],
687
+ });
688
+ group.push(newGroup);
689
+ }
690
+ return newGroup;
691
+ }
692
+ files.forEach((filePath) => {
693
+ const pathSegments = filePath.split(path_1.default.sep);
694
+ let currentLevel = root;
695
+ pathSegments.forEach((part, index) => {
696
+ const isRoot = part === ".";
697
+ const currentPath = pathSegments.slice(0, index + 1).join(path_1.default.sep);
698
+ currentLevel = isRoot ? currentLevel : getOrCreateGroup(currentPath, part, currentLevel).props.children;
699
+ const isFinalPart = index === pathSegments.length - 1;
700
+ if (swiftBuildFiles[filePath] && isFinalPart) {
701
+ const filex = swiftBuildFiles[filePath];
702
+ currentLevel.push(...filex);
703
+ }
704
+ });
705
+ });
706
+ return root;
707
+ }
708
+ function generateProjectGroups(project, structure, magicCwd) {
709
+ return structure.map((item) => {
710
+ if (item.props.isa === json_1.ISA.PBXGroup) {
711
+ // @ts-ignore
712
+ const childGroups = generateProjectGroups(project, item.props.children, path_1.default.join(magicCwd, item.props.name));
713
+ item.props.children = childGroups;
714
+ return item;
715
+ }
716
+ else if (item.props.isa === json_1.ISA.PBXBuildFile) {
717
+ return item.props.fileRef;
718
+ }
719
+ });
720
+ }
677
721
  function configureTargetWithPreview(target) {
678
722
  const assets = (0, glob_1.sync)("preview/*.xcassets", {
679
723
  absolute: true,
@@ -733,8 +777,7 @@ async function applyXcodeChanges(config, project, props) {
733
777
  });
734
778
  targetToUpdate.props.buildConfigurationList.removeFromProject();
735
779
  // Create new build phases
736
- targetToUpdate.props.buildConfigurationList =
737
- createConfigurationListForType(project, props);
780
+ targetToUpdate.props.buildConfigurationList = createConfigurationListForType(project, props);
738
781
  configureTargetWithEntitlements(targetToUpdate);
739
782
  configureTargetWithPreview(targetToUpdate);
740
783
  configureTargetWithKnownSettings(targetToUpdate);
@@ -744,18 +787,26 @@ async function applyXcodeChanges(config, project, props) {
744
787
  return project;
745
788
  }
746
789
  // Build Files
747
- // NOTE: Single-level only
748
- const swiftFiles = (0, glob_1.sync)("*.swift", {
790
+ const swiftBuildFiles = {};
791
+ (0, glob_1.sync)("**/*.swift", {
749
792
  absolute: true,
750
793
  cwd: magicCwd,
751
- }).map((file) => {
752
- return xcode_1.PBXBuildFile.create(project, {
794
+ }).forEach((file) => {
795
+ const fileDir = path_1.default.dirname(path_1.default.relative(magicCwd, file));
796
+ const pbxFile = xcode_1.PBXBuildFile.create(project, {
753
797
  fileRef: xcode_1.PBXFileReference.create(project, {
754
- path: path_1.default.basename(file),
798
+ path: file,
755
799
  sourceTree: "<group>",
756
800
  }),
757
801
  });
802
+ if (!swiftBuildFiles[fileDir]) {
803
+ swiftBuildFiles[fileDir] = [];
804
+ }
805
+ swiftBuildFiles[fileDir].push(pbxFile);
806
+ return undefined;
758
807
  });
808
+ const swiftStructure = buildFileGroupHierarchy(Object.keys(swiftBuildFiles));
809
+ const swiftGroups = generateProjectGroups(project, swiftStructure, magicCwd);
759
810
  // NOTE: Single-level only
760
811
  const intentFiles = (0, glob_1.sync)("*.intentdefinition", {
761
812
  absolute: true,
@@ -879,10 +930,9 @@ async function applyXcodeChanges(config, project, props) {
879
930
  configureTargetWithKnownSettings(widgetTarget);
880
931
  const entitlementFiles = configureTargetWithEntitlements(widgetTarget);
881
932
  configureTargetWithPreview(widgetTarget);
882
- // CD0706062A2EBE2E009C1192
883
933
  widgetTarget.createBuildPhase(xcode_1.PBXSourcesBuildPhase, {
884
934
  files: [
885
- ...swiftFiles,
935
+ ...Object.values(swiftBuildFiles).flat(),
886
936
  ...intentBuildFiles[0],
887
937
  // ...entitlementFiles
888
938
  ],
@@ -959,22 +1009,15 @@ async function applyXcodeChanges(config, project, props) {
959
1009
  path: props.cwd,
960
1010
  sourceTree: "<group>",
961
1011
  children: [
962
- // @ts-expect-error
963
- ...swiftFiles
964
- .map((buildFile) => buildFile.props.fileRef)
965
- .sort((a, b) => a.getDisplayName().localeCompare(b.getDisplayName())),
966
- // @ts-expect-error
1012
+ ...swiftGroups,
967
1013
  ...intentFiles.sort((a, b) => a.getDisplayName().localeCompare(b.getDisplayName())),
968
- // @ts-expect-error
969
1014
  ...assetFiles
970
1015
  .map((buildFile) => buildFile.props.fileRef)
971
1016
  .sort((a, b) => a.getDisplayName().localeCompare(b.getDisplayName())),
972
- // @ts-expect-error
973
1017
  ...entitlementFiles
974
1018
  .map((buildFile) => buildFile.props.fileRef)
975
1019
  .sort((a, b) => a.getDisplayName().localeCompare(b.getDisplayName())),
976
1020
  // CD0706192A2EBE2F009C1192 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
977
- // @ts-expect-error
978
1021
  xcode_1.PBXFileReference.create(project, {
979
1022
  path: "Info.plist",
980
1023
  sourceTree: "<group>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bacons/apple-targets",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Generate Apple Targets with Expo Prebuild",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -28,7 +28,7 @@
28
28
  "author": "Evan Bacon",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@react-native/normalize-colors": "^0.75.4",
31
+ "@react-native/normalize-colors": "^0.76.1",
32
32
  "glob": "^10.2.6",
33
33
  "@bacons/xcode": "^1.0.0-alpha.13",
34
34
  "fs-extra": "^11.2.0"