11#!/usr/bin/env node
22// @ts -check
3+ /**
4+ * @import {
5+ * Configuration,
6+ * ConfigureParams,
7+ * FileCopy,
8+ * Manifest,
9+ * Platform,
10+ * PlatformConfiguration,
11+ * PlatformPackage,
12+ * } from "./types.js";
13+ */
314import * as nodefs from "node:fs" ;
415import { createRequire } from "node:module" ;
516import * as path from "node:path" ;
@@ -28,14 +39,12 @@ import { downloadPackage } from "./utils/npm.mjs";
2839import { parseArgs } from "./utils/parseargs.mjs" ;
2940
3041/**
31- * @typedef {import("./types.js").Configuration } Configuration
32- * @typedef {import("./types.js").ConfigureParams } ConfigureParams
33- * @typedef {import("./types.js").FileCopy } FileCopy
34- * @typedef {Required<import("./types.js").Manifest> } Manifest
35- * @typedef {import("./types.js").PlatformConfiguration } PlatformConfiguration
36- * @typedef {import("./types.js").PlatformPackage } PlatformPackage
37- * @typedef {import("./types.js").Platform } Platform
42+ * @param {...string } paths
43+ * @returns {{ source: string; } }
3844 */
45+ function copyFrom ( ...paths ) {
46+ return { source : path . join ( ...paths ) } ;
47+ }
3948
4049/**
4150 * Merges two objects.
@@ -49,7 +58,7 @@ function mergeObjects(lhs, rhs) {
4958 : sortByKeys ( rhs ) ;
5059}
5160
52- /** @type {() => Manifest } */
61+ /** @type {() => Required< Manifest> } */
5362const readManifest = memo ( ( ) =>
5463 readJSONFile ( new URL ( "../package.json" , import . meta. url ) )
5564) ;
@@ -274,18 +283,14 @@ export const getConfig = (() => {
274283 configuration = {
275284 common : {
276285 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- } ,
286+ ".gitignore" : copyFrom ( testAppPath , "example" , gitignore ) ,
287+ ".watchmanconfig" : copyFrom ( templateDir , "_watchmanconfig" ) ,
288+ "babel.config.js" : copyFrom ( templateDir , "babel.config.js" ) ,
289+ "metro.config.js" : copyFrom (
290+ testAppPath ,
291+ "example" ,
292+ "metro.config.js"
293+ ) ,
289294 "react-native.config.js" : reactNativeConfig ( params ) ,
290295 ...( ! init
291296 ? undefined
@@ -294,20 +299,15 @@ export const getConfig = (() => {
294299 // drop support for 0.70
295300 ...( fs . existsSync ( path . join ( templateDir , "App.tsx" ) )
296301 ? {
297- "App.tsx" : {
298- source : path . join ( templateDir , "App.tsx" ) ,
299- } ,
300- "tsconfig.json" : {
301- source : path . join ( templateDir , "tsconfig.json" ) ,
302- } ,
302+ "App.tsx" : copyFrom ( templateDir , "App.tsx" ) ,
303+ "tsconfig.json" : copyFrom ( templateDir , "tsconfig.json" ) ,
303304 }
304305 : {
305- "App.js" : { source : path . join ( templateDir , "App.js" ) } ,
306+ "App.js" : copyFrom ( templateDir , "App.js" ) ,
306307 } ) ,
308+ Gemfile : copyFrom ( templateDir , "Gemfile" ) ,
307309 "app.json" : appManifest ( name ) ,
308- "index.js" : {
309- source : path . join ( templateDir , "index.js" ) ,
310- } ,
310+ "index.js" : copyFrom ( templateDir , "index.js" ) ,
311311 "package.json" : readTextFile (
312312 path . join ( templateDir , "package.json" ) ,
313313 fs
@@ -326,16 +326,14 @@ export const getConfig = (() => {
326326 android : {
327327 files : {
328328 "build.gradle" : buildGradle ( ) ,
329- "gradle/wrapper/gradle-wrapper.jar" : {
330- source : path . join (
331- testAppPath ,
332- "example" ,
333- "android" ,
334- "gradle" ,
335- "wrapper" ,
336- "gradle-wrapper.jar"
337- ) ,
338- } ,
329+ "gradle/wrapper/gradle-wrapper.jar" : copyFrom (
330+ testAppPath ,
331+ "example" ,
332+ "android" ,
333+ "gradle" ,
334+ "wrapper" ,
335+ "gradle-wrapper.jar"
336+ ) ,
339337 "gradle/wrapper/gradle-wrapper.properties" : ( ( ) => {
340338 const gradleWrapperProperties = path . join (
341339 testAppPath ,
@@ -355,17 +353,13 @@ export const getConfig = (() => {
355353 return props ;
356354 } ) ( ) ,
357355 "gradle.properties" : gradleProperties ( targetVersionNum ) ,
358- gradlew : {
359- source : path . join ( testAppPath , "example" , "android" , "gradlew" ) ,
360- } ,
361- "gradlew.bat" : {
362- source : path . join (
363- testAppPath ,
364- "example" ,
365- "android" ,
366- "gradlew.bat"
367- ) ,
368- } ,
356+ gradlew : copyFrom ( testAppPath , "example" , "android" , "gradlew" ) ,
357+ "gradlew.bat" : copyFrom (
358+ testAppPath ,
359+ "example" ,
360+ "android" ,
361+ "gradlew.bat"
362+ ) ,
369363 "settings.gradle" : settingsGradle ( name ) ,
370364 } ,
371365 oldFiles : [ ] ,
@@ -429,9 +423,12 @@ export const getConfig = (() => {
429423 } ,
430424 windows : {
431425 files : {
432- ".gitignore" : {
433- source : path . join ( testAppPath , "example" , "windows" , gitignore ) ,
434- } ,
426+ ".gitignore" : copyFrom (
427+ testAppPath ,
428+ "example" ,
429+ "windows" ,
430+ gitignore
431+ ) ,
435432 } ,
436433 oldFiles : [
437434 `${ name } .sln` ,
0 commit comments