Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 51 additions & 54 deletions scripts/configure.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/usr/bin/env node
// @ts-check
/**
* @import {
* Configuration,
* ConfigureParams,
* FileCopy,
* Manifest,
* Platform,
* PlatformConfiguration,
* PlatformPackage,
* } from "./types.js";
*/
import * as nodefs from "node:fs";
import { createRequire } from "node:module";
import * as path from "node:path";
Expand Down Expand Up @@ -28,14 +39,12 @@ import { downloadPackage } from "./utils/npm.mjs";
import { parseArgs } from "./utils/parseargs.mjs";

/**
* @typedef {import("./types.js").Configuration} Configuration
* @typedef {import("./types.js").ConfigureParams} ConfigureParams
* @typedef {import("./types.js").FileCopy} FileCopy
* @typedef {Required<import("./types.js").Manifest>} Manifest
* @typedef {import("./types.js").PlatformConfiguration} PlatformConfiguration
* @typedef {import("./types.js").PlatformPackage} PlatformPackage
* @typedef {import("./types.js").Platform} Platform
* @param {...string} paths
* @returns {{ source: string; }}
*/
function copyFrom(...paths) {
return { source: path.join(...paths) };
}

/**
* Merges two objects.
Expand All @@ -49,7 +58,7 @@ function mergeObjects(lhs, rhs) {
: sortByKeys(rhs);
}

/** @type {() => Manifest} */
/** @type {() => Required<Manifest>} */
const readManifest = memo(() =>
readJSONFile(new URL("../package.json", import.meta.url))
);
Expand Down Expand Up @@ -274,18 +283,14 @@ export const getConfig = (() => {
configuration = {
common: {
files: {
".gitignore": {
source: path.join(testAppPath, "example", gitignore),
},
".watchmanconfig": {
source: path.join(templateDir, "_watchmanconfig"),
},
"babel.config.js": {
source: path.join(templateDir, "babel.config.js"),
},
"metro.config.js": {
source: path.join(testAppPath, "example", "metro.config.js"),
},
".gitignore": copyFrom(testAppPath, "example", gitignore),
".watchmanconfig": copyFrom(templateDir, "_watchmanconfig"),
"babel.config.js": copyFrom(templateDir, "babel.config.js"),
"metro.config.js": copyFrom(
testAppPath,
"example",
"metro.config.js"
),
"react-native.config.js": reactNativeConfig(params),
...(!init
? undefined
Expand All @@ -294,20 +299,15 @@ export const getConfig = (() => {
// drop support for 0.70
...(fs.existsSync(path.join(templateDir, "App.tsx"))
? {
"App.tsx": {
source: path.join(templateDir, "App.tsx"),
},
"tsconfig.json": {
source: path.join(templateDir, "tsconfig.json"),
},
"App.tsx": copyFrom(templateDir, "App.tsx"),
"tsconfig.json": copyFrom(templateDir, "tsconfig.json"),
}
: {
"App.js": { source: path.join(templateDir, "App.js") },
"App.js": copyFrom(templateDir, "App.js"),
}),
Gemfile: copyFrom(templateDir, "Gemfile"),
"app.json": appManifest(name),
"index.js": {
source: path.join(templateDir, "index.js"),
},
"index.js": copyFrom(templateDir, "index.js"),
"package.json": readTextFile(
path.join(templateDir, "package.json"),
fs
Expand All @@ -326,16 +326,14 @@ export const getConfig = (() => {
android: {
files: {
"build.gradle": buildGradle(),
"gradle/wrapper/gradle-wrapper.jar": {
source: path.join(
testAppPath,
"example",
"android",
"gradle",
"wrapper",
"gradle-wrapper.jar"
),
},
"gradle/wrapper/gradle-wrapper.jar": copyFrom(
testAppPath,
"example",
"android",
"gradle",
"wrapper",
"gradle-wrapper.jar"
),
"gradle/wrapper/gradle-wrapper.properties": (() => {
const gradleWrapperProperties = path.join(
testAppPath,
Expand All @@ -355,17 +353,13 @@ export const getConfig = (() => {
return props;
})(),
"gradle.properties": gradleProperties(targetVersionNum),
gradlew: {
source: path.join(testAppPath, "example", "android", "gradlew"),
},
"gradlew.bat": {
source: path.join(
testAppPath,
"example",
"android",
"gradlew.bat"
),
},
gradlew: copyFrom(testAppPath, "example", "android", "gradlew"),
"gradlew.bat": copyFrom(
testAppPath,
"example",
"android",
"gradlew.bat"
),
"settings.gradle": settingsGradle(name),
},
oldFiles: [],
Expand Down Expand Up @@ -429,9 +423,12 @@ export const getConfig = (() => {
},
windows: {
files: {
".gitignore": {
source: path.join(testAppPath, "example", "windows", gitignore),
},
".gitignore": copyFrom(
testAppPath,
"example",
"windows",
gitignore
),
},
oldFiles: [
`${name}.sln`,
Expand Down
1 change: 1 addition & 0 deletions test/configure/getConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("getConfig()", () => {
".gitignore",
".watchmanconfig",
"App.tsx",
"Gemfile",
"app.json",
"babel.config.js",
"index.js",
Expand Down
Loading