react-native-ios-widget 0.0.10 → 0.0.12-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ios-widget",
3
- "version": "0.0.10",
3
+ "version": "0.0.12-beta.1",
4
4
  "description": "Expo config plugin to add widgets to a React Native app",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -45,4 +45,4 @@
45
45
  "engines": {
46
46
  "node": ">=18.16.0"
47
47
  }
48
- }
48
+ }
@@ -5,4 +5,4 @@ export type WidgetFiles = {
5
5
  fontFiles: string[];
6
6
  assetDirectories: string[];
7
7
  };
8
- export declare const getWidgetFiles: (widgetsPath: string, targetPath: string) => WidgetFiles;
8
+ export declare const getWidgetFiles: (widgetsPath: string, targetPath: string, moduleRoot: string) => WidgetFiles;
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getWidgetFiles = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const path = __importStar(require("path"));
29
- const getWidgetFiles = (widgetsPath, targetPath) => {
29
+ const getWidgetFiles = (widgetsPath, targetPath, moduleRoot) => {
30
30
  const widgetFiles = {
31
31
  swiftFiles: [],
32
32
  entitlementFiles: [],
@@ -37,6 +37,16 @@ const getWidgetFiles = (widgetsPath, targetPath) => {
37
37
  if (!fs.existsSync(targetPath)) {
38
38
  fs.mkdirSync(targetPath, { recursive: true });
39
39
  }
40
+ // Ensure moduleRoot directory exists
41
+ if (!fs.existsSync(moduleRoot)) {
42
+ fs.mkdirSync(moduleRoot, { recursive: true });
43
+ }
44
+ // Check if Module.swift exists before proceeding
45
+ const moduleSwiftPath = path.join(widgetsPath, "Module.swift");
46
+ if (!fs.existsSync(moduleSwiftPath)) {
47
+ throw new Error(`Module.swift not found at ${moduleSwiftPath}. ` +
48
+ `The widgets folder must contain a Module.swift file for the ReactNativeWidgetExtension module to build correctly.`);
49
+ }
40
50
  if (fs.lstatSync(widgetsPath).isDirectory()) {
41
51
  const files = fs.readdirSync(widgetsPath);
42
52
  files.forEach((file) => {
@@ -70,9 +80,8 @@ const getWidgetFiles = (widgetsPath, targetPath) => {
70
80
  const source = path.join(widgetsPath, file);
71
81
  copyFileSync(source, targetPath);
72
82
  });
73
- // Copy Module.swift and Attributes.swift
74
- const modulePath = path.join(__dirname, "../../../ios");
75
- copyFileSync(path.join(widgetsPath, "Module.swift"), path.join(modulePath, "Module.swift"));
83
+ // Copy Module.swift to moduleRoot (package ios directory)
84
+ copyFileSync(moduleSwiftPath, path.join(moduleRoot, "Module.swift"));
76
85
  // Copy directories
77
86
  widgetFiles.assetDirectories.forEach((directory) => {
78
87
  const imagesXcassetsSource = path.join(widgetsPath, directory);
@@ -86,7 +95,7 @@ const copyFileSync = (source, target) => {
86
95
  if (fs.existsSync(target) && fs.lstatSync(target).isDirectory()) {
87
96
  targetFile = path.join(target, path.basename(source));
88
97
  }
89
- fs.writeFileSync(targetFile, fs.readFileSync(source));
98
+ fs.copyFileSync(source, targetFile);
90
99
  };
91
100
  const copyDirectorySync = (source, target) => {
92
101
  const targetPath = path.join(target, path.basename(source));
@@ -37,12 +37,13 @@ const getWidgetFiles_1 = require("./lib/getWidgetFiles");
37
37
  const withXcode = (config, { enabled, targetName, bundleIdentifier, deploymentTarget, widgetsFolder }) => {
38
38
  return (0, config_plugins_1.withXcodeProject)(config, (config) => {
39
39
  const { platformProjectRoot, projectRoot } = config.modRequest;
40
- const widgetsPath = path.join(projectRoot, widgetsFolder);
41
- const targetPath = path.join(platformProjectRoot, targetName);
42
- const widgetFiles = (0, getWidgetFiles_1.getWidgetFiles)(widgetsPath, targetPath);
43
40
  if (!enabled) {
44
41
  return config;
45
42
  }
43
+ const widgetsPath = path.join(projectRoot, widgetsFolder);
44
+ const targetPath = path.join(platformProjectRoot, targetName);
45
+ const moduleRoot = path.join(projectRoot, "node_modules", "react-native-ios-widget", "ios");
46
+ const widgetFiles = (0, getWidgetFiles_1.getWidgetFiles)(widgetsPath, targetPath, moduleRoot);
46
47
  const xcodeProject = config.modResults;
47
48
  const marketingVersion = config.version;
48
49
  const xCConfigurationList = (0, addXCConfigurationList_1.addXCConfigurationList)(xcodeProject, {
@@ -9,7 +9,11 @@ export type WidgetFiles = {
9
9
  assetDirectories: string[];
10
10
  };
11
11
 
12
- export const getWidgetFiles = (widgetsPath: string, targetPath: string) => {
12
+ export const getWidgetFiles = (
13
+ widgetsPath: string,
14
+ targetPath: string,
15
+ moduleRoot: string
16
+ ) => {
13
17
  const widgetFiles: WidgetFiles = {
14
18
  swiftFiles: [],
15
19
  entitlementFiles: [],
@@ -22,6 +26,20 @@ export const getWidgetFiles = (widgetsPath: string, targetPath: string) => {
22
26
  fs.mkdirSync(targetPath, { recursive: true });
23
27
  }
24
28
 
29
+ // Ensure moduleRoot directory exists
30
+ if (!fs.existsSync(moduleRoot)) {
31
+ fs.mkdirSync(moduleRoot, { recursive: true });
32
+ }
33
+
34
+ // Check if Module.swift exists before proceeding
35
+ const moduleSwiftPath = path.join(widgetsPath, "Module.swift");
36
+ if (!fs.existsSync(moduleSwiftPath)) {
37
+ throw new Error(
38
+ `Module.swift not found at ${moduleSwiftPath}. ` +
39
+ `The widgets folder must contain a Module.swift file for the ReactNativeWidgetExtension module to build correctly.`
40
+ );
41
+ }
42
+
25
43
  if (fs.lstatSync(widgetsPath).isDirectory()) {
26
44
  const files = fs.readdirSync(widgetsPath);
27
45
 
@@ -55,12 +73,8 @@ export const getWidgetFiles = (widgetsPath: string, targetPath: string) => {
55
73
  copyFileSync(source, targetPath);
56
74
  });
57
75
 
58
- // Copy Module.swift and Attributes.swift
59
- const modulePath = path.join(__dirname, "../../../ios");
60
- copyFileSync(
61
- path.join(widgetsPath, "Module.swift"),
62
- path.join(modulePath, "Module.swift")
63
- );
76
+ // Copy Module.swift to moduleRoot (package ios directory)
77
+ copyFileSync(moduleSwiftPath, path.join(moduleRoot, "Module.swift"));
64
78
 
65
79
  // Copy directories
66
80
  widgetFiles.assetDirectories.forEach((directory) => {
@@ -78,7 +92,7 @@ const copyFileSync = (source: string, target: string) => {
78
92
  targetFile = path.join(target, path.basename(source));
79
93
  }
80
94
 
81
- fs.writeFileSync(targetFile, fs.readFileSync(source));
95
+ fs.copyFileSync(source, targetFile);
82
96
  };
83
97
 
84
98
  const copyDirectorySync = (source: string, target: string) => {
@@ -18,14 +18,20 @@ export const withXcode: ConfigPlugin<Required<WidgetConfig>> = (
18
18
  return withXcodeProject(config, (config) => {
19
19
  const { platformProjectRoot, projectRoot } = config.modRequest;
20
20
 
21
- const widgetsPath = path.join(projectRoot, widgetsFolder);
22
- const targetPath = path.join(platformProjectRoot, targetName);
23
- const widgetFiles = getWidgetFiles(widgetsPath, targetPath);
24
-
25
21
  if (!enabled) {
26
22
  return config;
27
23
  }
28
24
 
25
+ const widgetsPath = path.join(projectRoot, widgetsFolder);
26
+ const targetPath = path.join(platformProjectRoot, targetName);
27
+ const moduleRoot = path.join(
28
+ projectRoot,
29
+ "node_modules",
30
+ "react-native-ios-widget",
31
+ "ios"
32
+ );
33
+ const widgetFiles = getWidgetFiles(widgetsPath, targetPath, moduleRoot);
34
+
29
35
  const xcodeProject = config.modResults;
30
36
  const marketingVersion = config.version;
31
37
  const xCConfigurationList = addXCConfigurationList(xcodeProject, {