@codemoreira/esad 1.4.6-3 → 1.4.6-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/package.json +1 -1
- package/src/cli/utils/scaffold.js +31 -15
- package/src/plugin/config-plugin.js +45 -0
- package/src/plugin/index.js +8 -0
package/package.json
CHANGED
|
@@ -35,15 +35,21 @@ async function renameProject(targetDir, newName) {
|
|
|
35
35
|
if (appJson.expo) {
|
|
36
36
|
appJson.expo.name = newName;
|
|
37
37
|
appJson.expo.slug = newName;
|
|
38
|
+
appJson.expo.scheme = newName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
|
|
39
|
+
|
|
38
40
|
if (appJson.expo.android) {
|
|
39
41
|
appJson.expo.android.package = `com.anonymous.${newName.replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
40
42
|
}
|
|
43
|
+
|
|
44
|
+
if (appJson.expo.ios) {
|
|
45
|
+
appJson.expo.ios.bundleIdentifier = `com.anonymous.${newName.replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
46
|
+
}
|
|
41
47
|
} else {
|
|
42
48
|
appJson.name = newName;
|
|
43
49
|
appJson.slug = newName;
|
|
44
50
|
}
|
|
45
51
|
await fs.writeJson(appJsonPath, appJson, { spaces: 2 });
|
|
46
|
-
console.log(`✅ Updated app.json name/slug/package.`);
|
|
52
|
+
console.log(`✅ Updated app.json name/slug/package/scheme.`);
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
// 3. Update Rspack Config if exists
|
|
@@ -60,27 +66,37 @@ async function renameProject(targetDir, newName) {
|
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
/**
|
|
63
|
-
* Prepares the native folders and
|
|
69
|
+
* Prepares the native folders and ensures the ESAD Config Plugin is registered
|
|
64
70
|
*/
|
|
65
71
|
async function prepareNative(cwd, platform = 'android') {
|
|
72
|
+
const appJsonPath = path.join(cwd, 'app.json');
|
|
73
|
+
|
|
74
|
+
// 1. Ensure Config Plugin is in app.json
|
|
75
|
+
if (fs.existsSync(appJsonPath)) {
|
|
76
|
+
const appJson = await fs.readJson(appJsonPath);
|
|
77
|
+
if (appJson.expo) {
|
|
78
|
+
const plugins = appJson.expo.plugins || [];
|
|
79
|
+
const pluginName = '@codemoreira/esad/plugin/config-plugin';
|
|
80
|
+
|
|
81
|
+
if (!plugins.includes(pluginName) && !plugins.some(p => Array.isArray(p) && p[0] === pluginName)) {
|
|
82
|
+
appJson.expo.plugins = [...plugins, pluginName];
|
|
83
|
+
await fs.writeJson(appJsonPath, appJson, { spaces: 2 });
|
|
84
|
+
console.log(`✅ Added ESAD Config Plugin to app.json.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 2. Run Prebuild (this will trigger the plugin)
|
|
66
90
|
if (!fs.existsSync(path.join(cwd, 'android')) && (platform === 'android' || platform === 'all')) {
|
|
67
91
|
console.log(`📦 Native folder not found. Running expo prebuild...`);
|
|
68
92
|
await runProcess('npx', ['expo', 'prebuild', '--platform', 'android'], cwd);
|
|
93
|
+
} else if (platform === 'all' || platform === 'ios' || platform === 'android') {
|
|
94
|
+
// If folder exists, we still might want to run prebuild to sync changes if forced,
|
|
95
|
+
// but ESAD's dev command usually assumes it's managed.
|
|
96
|
+
// For now, let's just ensure react-native.config.js exists.
|
|
69
97
|
}
|
|
70
98
|
|
|
71
|
-
//
|
|
72
|
-
const buildGradlePath = path.join(cwd, 'android/app/build.gradle');
|
|
73
|
-
if (fs.existsSync(buildGradlePath)) {
|
|
74
|
-
let content = await fs.readFile(buildGradlePath, 'utf8');
|
|
75
|
-
if (!content.includes('project.ext.react')) {
|
|
76
|
-
const patch = `\nproject.ext.react = [\n bundleCommand: "repack-bundle",\n bundleConfig: "rspack.config.mjs"\n]\n\n`;
|
|
77
|
-
content = content.replace(/react \{/, `${patch}react {`);
|
|
78
|
-
await fs.writeFile(buildGradlePath, content);
|
|
79
|
-
console.log(`✅ Patched android/app/build.gradle for Re.Pack.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Create react-native.config.js if missing
|
|
99
|
+
// 3. Create react-native.config.js if missing
|
|
84
100
|
const rnConfigPath = path.join(cwd, 'react-native.config.js');
|
|
85
101
|
if (!fs.existsSync(rnConfigPath)) {
|
|
86
102
|
const content = `module.exports = {\n commands: require('@callstack/repack/commands/rspack'),\n};\n`;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { withAppBuildGradle, withXcodeProject } = require('expo/config-plugins');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ESAD Re.Pack Config Plugin
|
|
5
|
+
*
|
|
6
|
+
* Automates the native patching required for Re.Pack/Rspack to work with Expo.
|
|
7
|
+
* Replaces manual patching in ESAD CLI.
|
|
8
|
+
*/
|
|
9
|
+
module.exports = (config) => {
|
|
10
|
+
// --- iOS Patching ---
|
|
11
|
+
config = withXcodeProject(config, (configuration) => {
|
|
12
|
+
const xcodeProject = configuration.modResults;
|
|
13
|
+
const bundleReactNativeCodeAndImagesBuildPhase = xcodeProject.buildPhaseObject(
|
|
14
|
+
'PBXShellScriptBuildPhase',
|
|
15
|
+
'Bundle React Native code and images'
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (bundleReactNativeCodeAndImagesBuildPhase) {
|
|
19
|
+
const script = JSON.parse(bundleReactNativeCodeAndImagesBuildPhase.shellScript);
|
|
20
|
+
const patched = script
|
|
21
|
+
.replace(
|
|
22
|
+
/if \[\[ -z "\$CLI_PATH" \]\]; then[\s\S]*?fi\n?/g,
|
|
23
|
+
`export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native-community/cli/package.json')) + '/build/bin.js'")"`
|
|
24
|
+
)
|
|
25
|
+
.replace(/if \[\[ -z "\$BUNDLE_COMMAND" \]\]; then[\s\S]*?fi\n?/g, '');
|
|
26
|
+
|
|
27
|
+
bundleReactNativeCodeAndImagesBuildPhase.shellScript = JSON.stringify(patched);
|
|
28
|
+
}
|
|
29
|
+
return configuration;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// --- Android Patching ---
|
|
33
|
+
config = withAppBuildGradle(config, (configuration) => {
|
|
34
|
+
const buildGradle = configuration.modResults.contents;
|
|
35
|
+
// Ensure Re.Pack bundle command is used
|
|
36
|
+
const patched = buildGradle
|
|
37
|
+
.replace(/cliFile.*/, '')
|
|
38
|
+
.replace(/bundleCommand.*/, 'bundleCommand = "bundle"');
|
|
39
|
+
|
|
40
|
+
configuration.modResults.contents = patched;
|
|
41
|
+
return configuration;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return config;
|
|
45
|
+
};
|
package/src/plugin/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const fs = require('node:fs');
|
|
|
3
3
|
const Repack = require('@callstack/repack');
|
|
4
4
|
const { ExpoModulesPlugin } = require('@callstack/repack-plugin-expo-modules');
|
|
5
5
|
const { ProvidePlugin, DefinePlugin } = require('@rspack/core');
|
|
6
|
+
const { ReanimatedPlugin } = require('@callstack/repack-plugin-reanimated');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* ESAD Re.Pack Plugin Wrapper
|
|
@@ -86,9 +87,16 @@ function withESAD(env, options) {
|
|
|
86
87
|
new DefinePlugin({
|
|
87
88
|
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
|
88
89
|
'__DEV__': JSON.stringify(isDev),
|
|
90
|
+
'process.env.EXPO_BASE_URL': JSON.stringify(''),
|
|
91
|
+
'process.env.EXPO_OS': JSON.stringify(platform),
|
|
92
|
+
'process.env.EXPO_PROJECT_ROOT': JSON.stringify(dirname),
|
|
93
|
+
'process.env.EXPO_ROUTER_ABS_APP_ROOT': JSON.stringify(path.resolve(dirname, 'app')),
|
|
94
|
+
'process.env.EXPO_ROUTER_APP_ROOT': JSON.stringify('./app'),
|
|
95
|
+
'process.env.EXPO_ROUTER_IMPORT_MODE': JSON.stringify('sync'),
|
|
89
96
|
}),
|
|
90
97
|
new ExpoModulesPlugin(),
|
|
91
98
|
new Repack.RepackPlugin(),
|
|
99
|
+
new ReanimatedPlugin(),
|
|
92
100
|
new Repack.plugins.ModuleFederationPluginV2({
|
|
93
101
|
name: id,
|
|
94
102
|
filename: `${id}.container.js.bundle`,
|