Skip to content

Commit 9ab8535

Browse files
committed
refactor
1 parent 2aba490 commit 9ab8535

File tree

1 file changed

+42
-49
lines changed

1 file changed

+42
-49
lines changed

scripts/configure.mjs

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ import { parseArgs } from "./utils/parseargs.mjs";
3737
* @typedef {import("./types.js").Platform} Platform
3838
*/
3939

40+
/**
41+
* @param {...string} paths
42+
* @returns {{ source: string; }}
43+
*/
44+
function copyFrom(...paths) {
45+
return { source: path.join(...paths) };
46+
}
47+
4048
/**
4149
* Merges two objects.
4250
* @param {unknown} lhs
@@ -274,18 +282,14 @@ export const getConfig = (() => {
274282
configuration = {
275283
common: {
276284
files: {
277-
".gitignore": {
278-
source: path.join(testAppPath, "example", gitignore),
279-
},
280-
".watchmanconfig": {
281-
source: path.join(templateDir, "_watchmanconfig"),
282-
},
283-
"babel.config.js": {
284-
source: path.join(templateDir, "babel.config.js"),
285-
},
286-
"metro.config.js": {
287-
source: path.join(testAppPath, "example", "metro.config.js"),
288-
},
285+
".gitignore": copyFrom(testAppPath, "example", gitignore),
286+
".watchmanconfig": copyFrom(templateDir, "_watchmanconfig"),
287+
"babel.config.js": copyFrom(templateDir, "babel.config.js"),
288+
"metro.config.js": copyFrom(
289+
testAppPath,
290+
"example",
291+
"metro.config.js"
292+
),
289293
"react-native.config.js": reactNativeConfig(params),
290294
...(!init
291295
? undefined
@@ -294,23 +298,15 @@ export const getConfig = (() => {
294298
// drop support for 0.70
295299
...(fs.existsSync(path.join(templateDir, "App.tsx"))
296300
? {
297-
"App.tsx": {
298-
source: path.join(templateDir, "App.tsx"),
299-
},
300-
"tsconfig.json": {
301-
source: path.join(templateDir, "tsconfig.json"),
302-
},
301+
"App.tsx": copyFrom(templateDir, "App.tsx"),
302+
"tsconfig.json": copyFrom(templateDir, "tsconfig.json"),
303303
}
304304
: {
305-
"App.js": { source: path.join(templateDir, "App.js") },
305+
"App.js": copyFrom(templateDir, "App.js"),
306306
}),
307-
Gemfile: {
308-
source: path.join(templateDir, "Gemfile"),
309-
},
307+
Gemfile: copyFrom(templateDir, "Gemfile"),
310308
"app.json": appManifest(name),
311-
"index.js": {
312-
source: path.join(templateDir, "index.js"),
313-
},
309+
"index.js": copyFrom(templateDir, "index.js"),
314310
"package.json": readTextFile(
315311
path.join(templateDir, "package.json"),
316312
fs
@@ -329,16 +325,14 @@ export const getConfig = (() => {
329325
android: {
330326
files: {
331327
"build.gradle": buildGradle(),
332-
"gradle/wrapper/gradle-wrapper.jar": {
333-
source: path.join(
334-
testAppPath,
335-
"example",
336-
"android",
337-
"gradle",
338-
"wrapper",
339-
"gradle-wrapper.jar"
340-
),
341-
},
328+
"gradle/wrapper/gradle-wrapper.jar": copyFrom(
329+
testAppPath,
330+
"example",
331+
"android",
332+
"gradle",
333+
"wrapper",
334+
"gradle-wrapper.jar"
335+
),
342336
"gradle/wrapper/gradle-wrapper.properties": (() => {
343337
const gradleWrapperProperties = path.join(
344338
testAppPath,
@@ -358,17 +352,13 @@ export const getConfig = (() => {
358352
return props;
359353
})(),
360354
"gradle.properties": gradleProperties(targetVersionNum),
361-
gradlew: {
362-
source: path.join(testAppPath, "example", "android", "gradlew"),
363-
},
364-
"gradlew.bat": {
365-
source: path.join(
366-
testAppPath,
367-
"example",
368-
"android",
369-
"gradlew.bat"
370-
),
371-
},
355+
gradlew: copyFrom(testAppPath, "example", "android", "gradlew"),
356+
"gradlew.bat": copyFrom(
357+
testAppPath,
358+
"example",
359+
"android",
360+
"gradlew.bat"
361+
),
372362
"settings.gradle": settingsGradle(name),
373363
},
374364
oldFiles: [],
@@ -432,9 +422,12 @@ export const getConfig = (() => {
432422
},
433423
windows: {
434424
files: {
435-
".gitignore": {
436-
source: path.join(testAppPath, "example", "windows", gitignore),
437-
},
425+
".gitignore": copyFrom(
426+
testAppPath,
427+
"example",
428+
"windows",
429+
gitignore
430+
),
438431
},
439432
oldFiles: [
440433
`${name}.sln`,

0 commit comments

Comments
 (0)