react-native-macos 0.75.1 → 0.75.3
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/Libraries/Core/ReactNativeVersion.js +1 -1
- package/React/Base/RCTVersion.m +1 -1
- package/ReactAndroid/gradle.properties +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
- package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
- package/local-cli/cli.js +18 -0
- package/local-cli/generate-macos.js +38 -0
- package/local-cli/generator-common/index.js +384 -0
- package/local-cli/generator-macos/index.js +153 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.h +6 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.mm +40 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Assets.xcassets/Contents.json +6 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Base.lproj/Main.storyboard +684 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/HelloWorld.entitlements +12 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/Info.plist +47 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/main.m +5 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj +536 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/xcshareddata/xcschemes/HelloWorld-iOS.xcscheme +78 -0
- package/local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/xcshareddata/xcschemes/HelloWorld-macOS.xcscheme +78 -0
- package/local-cli/generator-macos/templates/macos/Podfile +24 -0
- package/local-cli/generator-macos/templates/macos/_gitignore +2 -0
- package/local-cli/runMacOS/findXcodeProject.js +37 -0
- package/local-cli/runMacOS/runMacOS.js +329 -0
- package/package.json +2 -1
package/React/Base/RCTVersion.m
CHANGED
package/local-cli/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var cli = require('@react-native-community/cli');
|
|
13
|
+
|
|
14
|
+
if (require.main === module) {
|
|
15
|
+
cli.run();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = cli;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
copyProjectTemplateAndReplace,
|
|
5
|
+
installDependencies,
|
|
6
|
+
installPods,
|
|
7
|
+
printFinishMessage,
|
|
8
|
+
} = require('./generator-macos');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Simple utility for running the macOS generator.
|
|
14
|
+
*
|
|
15
|
+
* @param {String} projectDir root project directory (i.e. contains index.js)
|
|
16
|
+
* @param {String} name name of the root JS module for this app
|
|
17
|
+
* @param {Object} options command line options container
|
|
18
|
+
*/
|
|
19
|
+
function generateMacOS (projectDir, name, options) {
|
|
20
|
+
if (!fs.existsSync(projectDir)) {
|
|
21
|
+
fs.mkdirSync(projectDir);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
installDependencies(options);
|
|
25
|
+
|
|
26
|
+
copyProjectTemplateAndReplace(
|
|
27
|
+
path.join(__dirname, 'generator-macos', 'templates'),
|
|
28
|
+
projectDir,
|
|
29
|
+
name,
|
|
30
|
+
{ overwrite: options.overwrite }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
installPods(options);
|
|
34
|
+
|
|
35
|
+
printFinishMessage(name);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = generateMacOS;
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
// Copied from `copyAndReplace` in react-native-community/cli as it's deleted in newer versions
|
|
8
|
+
|
|
9
|
+
function walk(current) {
|
|
10
|
+
if (!fs.lstatSync(current).isDirectory()) {
|
|
11
|
+
return [current];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const files = fs
|
|
15
|
+
.readdirSync(current)
|
|
16
|
+
.map(child => walk(path.join(current, child)));
|
|
17
|
+
const result = [];
|
|
18
|
+
return result.concat.apply([current], files);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Binary files, don't process these (avoid decoding as utf8)
|
|
22
|
+
const binaryExtensions = ['.png', '.jar', '.keystore'];
|
|
23
|
+
/**
|
|
24
|
+
* Copy a file to given destination, replacing parts of its contents.
|
|
25
|
+
* @param srcPath Path to a file to be copied.
|
|
26
|
+
* @param destPath Destination path.
|
|
27
|
+
* @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
|
|
28
|
+
* @param contentChangedCallback
|
|
29
|
+
* Used when upgrading projects. Based on if file contents would change
|
|
30
|
+
* when being replaced, allows the caller to specify whether the file
|
|
31
|
+
* should be replaced or not.
|
|
32
|
+
* If null, files will be overwritten.
|
|
33
|
+
* Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
|
|
34
|
+
*/
|
|
35
|
+
function copyAndReplace(
|
|
36
|
+
srcPath,
|
|
37
|
+
destPath,
|
|
38
|
+
replacements,
|
|
39
|
+
contentChangedCallback,
|
|
40
|
+
) {
|
|
41
|
+
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
42
|
+
if (!fs.existsSync(destPath)) {
|
|
43
|
+
fs.mkdirSync(destPath);
|
|
44
|
+
}
|
|
45
|
+
// Not recursive
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const extension = path.extname(srcPath);
|
|
50
|
+
if (binaryExtensions.indexOf(extension) !== -1) {
|
|
51
|
+
// Binary file
|
|
52
|
+
let shouldOverwrite = 'overwrite';
|
|
53
|
+
if (contentChangedCallback) {
|
|
54
|
+
const newContentBuffer = fs.readFileSync(srcPath);
|
|
55
|
+
let contentChanged = 'identical';
|
|
56
|
+
try {
|
|
57
|
+
const origContentBuffer = fs.readFileSync(destPath);
|
|
58
|
+
if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
|
|
59
|
+
contentChanged = 'changed';
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (err.code === 'ENOENT') {
|
|
63
|
+
contentChanged = 'new';
|
|
64
|
+
} else {
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
|
|
69
|
+
}
|
|
70
|
+
if (shouldOverwrite === 'overwrite') {
|
|
71
|
+
copyBinaryFile(srcPath, destPath, err => {
|
|
72
|
+
if (err) {
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
// Text file
|
|
79
|
+
const srcPermissions = fs.statSync(srcPath).mode;
|
|
80
|
+
let content = fs.readFileSync(srcPath, 'utf8');
|
|
81
|
+
Object.keys(replacements).forEach(regex => {
|
|
82
|
+
content = content.replace(new RegExp(regex, 'g'), replacements[regex]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
let shouldOverwrite = 'overwrite';
|
|
86
|
+
if (contentChangedCallback) {
|
|
87
|
+
// Check if contents changed and ask to overwrite
|
|
88
|
+
let contentChanged = 'identical';
|
|
89
|
+
try {
|
|
90
|
+
const origContent = fs.readFileSync(destPath, 'utf8');
|
|
91
|
+
if (content !== origContent) {
|
|
92
|
+
// logger.info('Content changed: ' + destPath);
|
|
93
|
+
contentChanged = 'changed';
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err.code === 'ENOENT') {
|
|
97
|
+
contentChanged = 'new';
|
|
98
|
+
} else {
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
|
|
103
|
+
}
|
|
104
|
+
if (shouldOverwrite === 'overwrite') {
|
|
105
|
+
fs.writeFileSync(destPath, content, {
|
|
106
|
+
encoding: 'utf8',
|
|
107
|
+
mode: srcPermissions,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Same as 'cp' on Unix. Don't do any replacements.
|
|
115
|
+
*/
|
|
116
|
+
function copyBinaryFile(srcPath, destPath, cb) {
|
|
117
|
+
let cbCalled = false;
|
|
118
|
+
const srcPermissions = fs.statSync(srcPath).mode;
|
|
119
|
+
const readStream = fs.createReadStream(srcPath);
|
|
120
|
+
readStream.on('error', err => {
|
|
121
|
+
done(err);
|
|
122
|
+
});
|
|
123
|
+
const writeStream = fs.createWriteStream(destPath, {
|
|
124
|
+
mode: srcPermissions,
|
|
125
|
+
});
|
|
126
|
+
writeStream.on('error', err => {
|
|
127
|
+
done(err);
|
|
128
|
+
});
|
|
129
|
+
writeStream.on('close', () => {
|
|
130
|
+
done();
|
|
131
|
+
});
|
|
132
|
+
readStream.pipe(writeStream);
|
|
133
|
+
function done(err) {
|
|
134
|
+
if (!cbCalled) {
|
|
135
|
+
cb(err);
|
|
136
|
+
cbCalled = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const term = 13; // carriage return
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
function prompt(ask, value, opts) {
|
|
145
|
+
let insert = 0;
|
|
146
|
+
opts = opts || {};
|
|
147
|
+
|
|
148
|
+
if (Object(ask) === ask) {
|
|
149
|
+
opts = ask;
|
|
150
|
+
ask = opts.ask;
|
|
151
|
+
} else if (Object(value) === value) {
|
|
152
|
+
opts = value;
|
|
153
|
+
value = opts.value;
|
|
154
|
+
}
|
|
155
|
+
ask = ask || '';
|
|
156
|
+
const echo = opts.echo;
|
|
157
|
+
const masked = 'echo' in opts;
|
|
158
|
+
|
|
159
|
+
const fd =
|
|
160
|
+
process.platform === 'win32'
|
|
161
|
+
? process.stdin.fd
|
|
162
|
+
: fs.openSync('/dev/tty', 'rs');
|
|
163
|
+
|
|
164
|
+
const wasRaw = process.stdin.isRaw;
|
|
165
|
+
if (!wasRaw) {
|
|
166
|
+
process.stdin.setRawMode(true);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let buf = Buffer.alloc(3);
|
|
170
|
+
let str = '';
|
|
171
|
+
|
|
172
|
+
let character;
|
|
173
|
+
|
|
174
|
+
let read;
|
|
175
|
+
|
|
176
|
+
if (ask) {
|
|
177
|
+
process.stdout.write(ask);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
while (true) {
|
|
181
|
+
read = fs.readSync(fd, buf, 0, 3);
|
|
182
|
+
if (read > 1) {
|
|
183
|
+
// received a control sequence
|
|
184
|
+
if (buf.toString()) {
|
|
185
|
+
str += buf.toString();
|
|
186
|
+
str = str.replace(/\0/g, '');
|
|
187
|
+
insert = str.length;
|
|
188
|
+
process.stdout.write(`\u001b[2K\u001b[0G${ask}${str}`);
|
|
189
|
+
process.stdout.write(`\u001b[${insert + ask.length + 1}G`);
|
|
190
|
+
buf = Buffer.alloc(3);
|
|
191
|
+
}
|
|
192
|
+
continue; // any other 3 character sequence is ignored
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// if it is not a control character seq, assume only one character is read
|
|
196
|
+
character = buf[read - 1];
|
|
197
|
+
|
|
198
|
+
// catch a ^C and return null
|
|
199
|
+
if (character === 3) {
|
|
200
|
+
process.stdout.write('^C\n');
|
|
201
|
+
fs.closeSync(fd);
|
|
202
|
+
process.exit(130);
|
|
203
|
+
process.stdin.setRawMode(wasRaw);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// catch the terminating character
|
|
208
|
+
if (character === term) {
|
|
209
|
+
fs.closeSync(fd);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
character === 127 ||
|
|
215
|
+
(process.platform === 'win32' && character === 8)
|
|
216
|
+
) {
|
|
217
|
+
// backspace
|
|
218
|
+
if (!insert) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
str = str.slice(0, insert - 1) + str.slice(insert);
|
|
222
|
+
insert--;
|
|
223
|
+
process.stdout.write('\u001b[2D');
|
|
224
|
+
} else {
|
|
225
|
+
if (character < 32 || character > 126) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
str =
|
|
229
|
+
str.slice(0, insert) +
|
|
230
|
+
String.fromCharCode(character) +
|
|
231
|
+
str.slice(insert);
|
|
232
|
+
insert++;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (masked) {
|
|
236
|
+
process.stdout.write(
|
|
237
|
+
`\u001b[2K\u001b[0G${ask}${Array(str.length + 1).join(echo)}`,
|
|
238
|
+
);
|
|
239
|
+
} else {
|
|
240
|
+
process.stdout.write('\u001b[s');
|
|
241
|
+
if (insert === str.length) {
|
|
242
|
+
process.stdout.write(`\u001b[2K\u001b[0G${ask}${str}`);
|
|
243
|
+
} else if (ask) {
|
|
244
|
+
process.stdout.write(`\u001b[2K\u001b[0G${ask}${str}`);
|
|
245
|
+
} else {
|
|
246
|
+
process.stdout.write(
|
|
247
|
+
`\u001b[2K\u001b[0G${str}\u001b[${str.length - insert}D`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
process.stdout.write('\u001b[u');
|
|
251
|
+
process.stdout.write('\u001b[1C');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
process.stdout.write('\n');
|
|
256
|
+
|
|
257
|
+
process.stdin.setRawMode(wasRaw);
|
|
258
|
+
|
|
259
|
+
return str || value || '';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// End copy
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @param {string} destPath
|
|
266
|
+
*/
|
|
267
|
+
function createDir(destPath) {
|
|
268
|
+
if (!fs.existsSync(destPath)) {
|
|
269
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @todo Move this upstream to @react-native-community/cli
|
|
275
|
+
*
|
|
276
|
+
* @param {string} templatePath
|
|
277
|
+
* @param {Record<string, string>} replacements
|
|
278
|
+
*/
|
|
279
|
+
function replaceInPath(templatePath, replacements) {
|
|
280
|
+
let result = templatePath;
|
|
281
|
+
Object.keys(replacements).forEach(key => {
|
|
282
|
+
result = result.replace(key, replacements[key]);
|
|
283
|
+
});
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function copyAndReplaceWithChangedCallback(srcPath, destRoot, relativeDestPath, replacements, alwaysOverwrite) {
|
|
288
|
+
if (!replacements) {
|
|
289
|
+
replacements = {};
|
|
290
|
+
}
|
|
291
|
+
const contentChangedCallback = alwaysOverwrite ? (_, contentChanged) =>
|
|
292
|
+
alwaysOverwriteContentChangedCallback(
|
|
293
|
+
srcPath,
|
|
294
|
+
relativeDestPath,
|
|
295
|
+
contentChanged
|
|
296
|
+
) : (_, contentChanged) =>
|
|
297
|
+
upgradeFileContentChangedCallback(
|
|
298
|
+
srcPath,
|
|
299
|
+
relativeDestPath,
|
|
300
|
+
contentChanged
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
copyAndReplace(
|
|
304
|
+
srcPath,
|
|
305
|
+
path.join(destRoot, relativeDestPath),
|
|
306
|
+
replacements,
|
|
307
|
+
contentChangedCallback
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @param {string} srcPath
|
|
313
|
+
* @param {string} destPath
|
|
314
|
+
* @param {string} relativeDestDir
|
|
315
|
+
* @param {Record<string, string>} replacements
|
|
316
|
+
* @param {boolean} alwaysOverwrite
|
|
317
|
+
*/
|
|
318
|
+
function copyAndReplaceAll(srcPath, destPath, relativeDestDir, replacements, alwaysOverwrite) {
|
|
319
|
+
walk(srcPath).forEach(absoluteSrcFilePath => {
|
|
320
|
+
const filename = path.relative(srcPath, absoluteSrcFilePath);
|
|
321
|
+
const relativeDestPath = path.join(relativeDestDir, replaceInPath(filename, replacements));
|
|
322
|
+
copyAndReplaceWithChangedCallback(absoluteSrcFilePath, destPath, relativeDestPath, replacements, alwaysOverwrite);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function alwaysOverwriteContentChangedCallback(
|
|
327
|
+
absoluteSrcFilePath,
|
|
328
|
+
relativeDestPath,
|
|
329
|
+
contentChanged
|
|
330
|
+
) {
|
|
331
|
+
if (contentChanged === 'new') {
|
|
332
|
+
console.log(`${chalk.bold('new')} ${relativeDestPath}`);
|
|
333
|
+
return 'overwrite';
|
|
334
|
+
}
|
|
335
|
+
if (contentChanged === 'changed') {
|
|
336
|
+
console.log(`${chalk.bold('changed')} ${relativeDestPath} ${chalk.yellow('[overwriting]')}`);
|
|
337
|
+
return 'overwrite';
|
|
338
|
+
}
|
|
339
|
+
if (contentChanged === 'identical') {
|
|
340
|
+
return 'keep';
|
|
341
|
+
}
|
|
342
|
+
throw new Error(
|
|
343
|
+
`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function upgradeFileContentChangedCallback(
|
|
348
|
+
absoluteSrcFilePath,
|
|
349
|
+
relativeDestPath,
|
|
350
|
+
contentChanged
|
|
351
|
+
) {
|
|
352
|
+
if (contentChanged === 'new') {
|
|
353
|
+
console.log(`${chalk.bold('new')} ${relativeDestPath}`);
|
|
354
|
+
return 'overwrite';
|
|
355
|
+
}
|
|
356
|
+
if (contentChanged === 'changed') {
|
|
357
|
+
console.log(
|
|
358
|
+
`${chalk.bold(relativeDestPath)} ` +
|
|
359
|
+
`has changed in the new version.\nDo you want to keep your ${relativeDestPath} or replace it with the ` +
|
|
360
|
+
'latest version?\nIf you ever made any changes ' +
|
|
361
|
+
'to this file, you\'ll probably want to keep it.\n' +
|
|
362
|
+
`You can see the new version here: ${absoluteSrcFilePath}\n` +
|
|
363
|
+
`Do you want to replace ${relativeDestPath}? ` +
|
|
364
|
+
'Answer y to replace, n to keep your version: '
|
|
365
|
+
);
|
|
366
|
+
const answer = prompt();
|
|
367
|
+
if (answer === 'y') {
|
|
368
|
+
console.log(`Replacing ${relativeDestPath}`);
|
|
369
|
+
return 'overwrite';
|
|
370
|
+
}
|
|
371
|
+
console.log(`Keeping your ${relativeDestPath}`);
|
|
372
|
+
return 'keep';
|
|
373
|
+
}
|
|
374
|
+
if (contentChanged === 'identical') {
|
|
375
|
+
return 'keep';
|
|
376
|
+
}
|
|
377
|
+
throw new Error(
|
|
378
|
+
`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
module.exports = {
|
|
383
|
+
createDir, copyAndReplaceWithChangedCallback, copyAndReplaceAll,
|
|
384
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
copyAndReplaceAll,
|
|
7
|
+
createDir,
|
|
8
|
+
} = require('../generator-common');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const childProcess = require('child_process');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const macOSDir = 'macos';
|
|
15
|
+
const oldProjectName = 'HelloWorld';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} srcRootPath
|
|
19
|
+
* @param {string} destPath
|
|
20
|
+
* @param {string} newProjectName
|
|
21
|
+
* @param {{ overwrite?: boolean }} options
|
|
22
|
+
*/
|
|
23
|
+
function copyProjectTemplateAndReplace(
|
|
24
|
+
srcRootPath,
|
|
25
|
+
destPath,
|
|
26
|
+
newProjectName,
|
|
27
|
+
options = {}
|
|
28
|
+
) {
|
|
29
|
+
if (!srcRootPath) {
|
|
30
|
+
throw new Error('Need a path to copy from');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!destPath) {
|
|
34
|
+
throw new Error('Need a path to copy to');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!newProjectName) {
|
|
38
|
+
throw new Error('Need a project name');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
createDir(path.join(destPath, macOSDir));
|
|
42
|
+
createDir(path.join(destPath, srcDirPath(newProjectName, 'macOS')));
|
|
43
|
+
createDir(path.join(destPath, xcodeprojPath(newProjectName)));
|
|
44
|
+
createDir(path.join(destPath, schemesPath(newProjectName)));
|
|
45
|
+
|
|
46
|
+
const templateVars = {
|
|
47
|
+
[oldProjectName]: newProjectName,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
[
|
|
51
|
+
{ from: path.join(srcRootPath, macOSDir, 'Podfile'), to: path.join(macOSDir, 'Podfile') },
|
|
52
|
+
{ from: path.join(srcRootPath, macOSDir, '_gitignore'), to: path.join(macOSDir, '.gitignore') },
|
|
53
|
+
{ from: path.join(srcRootPath, srcDirPath(oldProjectName, 'macOS')), to: srcDirPath(newProjectName, 'macOS') },
|
|
54
|
+
{ from: path.join(srcRootPath, pbxprojPath(oldProjectName)), to: pbxprojPath(newProjectName) },
|
|
55
|
+
{ from: path.join(srcRootPath, schemePath(oldProjectName, 'macOS')), to: schemePath(newProjectName, 'macOS') },
|
|
56
|
+
].forEach((mapping) => copyAndReplaceAll(mapping.from, destPath, mapping.to, templateVars, options.overwrite));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} basename
|
|
61
|
+
* @param {"iOS" | "macOS"} platform
|
|
62
|
+
*/
|
|
63
|
+
function projectName(basename, platform) {
|
|
64
|
+
return basename + '-' + platform;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} basename
|
|
69
|
+
* @param {"iOS" | "macOS"} platform
|
|
70
|
+
*/
|
|
71
|
+
function srcDirPath(basename, platform) {
|
|
72
|
+
return path.join(macOSDir, projectName(basename, platform));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} basename
|
|
77
|
+
*/
|
|
78
|
+
function xcodeprojPath(basename) {
|
|
79
|
+
return path.join(macOSDir, basename + '.xcodeproj');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} basename
|
|
84
|
+
*/
|
|
85
|
+
function xcworkspacePath(basename) {
|
|
86
|
+
return path.join(macOSDir, basename + '.xcworkspace');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} basename
|
|
91
|
+
*/
|
|
92
|
+
function pbxprojPath(basename) {
|
|
93
|
+
return path.join(xcodeprojPath(basename), 'project.pbxproj');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {string} basename
|
|
98
|
+
*/
|
|
99
|
+
function schemesPath(basename) {
|
|
100
|
+
return path.join(xcodeprojPath(basename), 'xcshareddata', 'xcschemes');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} basename
|
|
105
|
+
* @param {"iOS" | "macOS"} platform
|
|
106
|
+
*/
|
|
107
|
+
function schemePath(basename, platform) {
|
|
108
|
+
return path.join(schemesPath(basename), projectName(basename, platform) + '.xcscheme');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {{ verbose?: boolean }=} options
|
|
113
|
+
*/
|
|
114
|
+
function installDependencies(options) {
|
|
115
|
+
const cwd = process.cwd();
|
|
116
|
+
|
|
117
|
+
// Install dependencies using correct package manager
|
|
118
|
+
const isYarn = fs.existsSync(path.join(cwd, 'yarn.lock'));
|
|
119
|
+
|
|
120
|
+
/** @type {{ stdio?: 'inherit' }} */
|
|
121
|
+
const execOptions = options && options.verbose ? { stdio: 'inherit' } : {};
|
|
122
|
+
childProcess.execSync(isYarn ? 'yarn' : 'npm i', execOptions);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {{ verbose?: boolean }=} options
|
|
127
|
+
*/
|
|
128
|
+
function installPods(options) {
|
|
129
|
+
const cwd = path.join(process.cwd(), macOSDir);
|
|
130
|
+
const quietFlag = options && options.verbose ? '' : '--quiet';
|
|
131
|
+
childProcess.execSync(`npx ${quietFlag} pod-install --non-interactive ${quietFlag}`, { stdio: 'inherit', cwd });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} newProjectName
|
|
136
|
+
*/
|
|
137
|
+
function printFinishMessage(newProjectName) {
|
|
138
|
+
console.log(`
|
|
139
|
+
${chalk.blue(`Run instructions for ${chalk.bold('macOS')}`)}:
|
|
140
|
+
• npx react-native run-macos
|
|
141
|
+
${chalk.dim('- or -')}
|
|
142
|
+
• Open ${xcworkspacePath(newProjectName)} in Xcode or run "xed -b ${macOSDir}"
|
|
143
|
+
• yarn start:macos
|
|
144
|
+
• Hit the Run button
|
|
145
|
+
`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
copyProjectTemplateAndReplace,
|
|
150
|
+
installDependencies,
|
|
151
|
+
installPods,
|
|
152
|
+
printFinishMessage,
|
|
153
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#import "AppDelegate.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTBundleURLProvider.h>
|
|
4
|
+
|
|
5
|
+
@implementation AppDelegate
|
|
6
|
+
|
|
7
|
+
- (void)applicationDidFinishLaunching:(NSNotification *)notification
|
|
8
|
+
{
|
|
9
|
+
self.moduleName = @"HelloWorld";
|
|
10
|
+
// You can add your custom initial props in the dictionary below.
|
|
11
|
+
// They will be passed down to the ViewController used by React Native.
|
|
12
|
+
self.initialProps = @{};
|
|
13
|
+
|
|
14
|
+
return [super applicationDidFinishLaunching:notification];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
18
|
+
{
|
|
19
|
+
#if DEBUG
|
|
20
|
+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
|
|
21
|
+
#else
|
|
22
|
+
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
23
|
+
#endif
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
|
|
27
|
+
///
|
|
28
|
+
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
|
|
29
|
+
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
|
|
30
|
+
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
|
|
31
|
+
- (BOOL)concurrentRootEnabled
|
|
32
|
+
{
|
|
33
|
+
#ifdef RN_FABRIC_ENABLED
|
|
34
|
+
return true;
|
|
35
|
+
#else
|
|
36
|
+
return false;
|
|
37
|
+
#endif
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@end
|