Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(path ios files): [WIP] Support user to specify path for ios/android files #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
77 changes: 55 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ const promptConfig = [
message: "What OS & languages would you like to support?",
default: ["Android/Java", "iOS/Objective-C"],
choices: ["Android/Java", "Android/Kotlin", "iOS/Swift", "iOS/Objective-C"]
},
{
type: "input",
name: "jsPath",
message: "What directory should we deliver your JS files to?",
default: ".",
validate: input => isValid(input)
}
];

Expand All @@ -49,20 +42,42 @@ const environmentMap = {

async function init() {
try {
const {
environment,
bridgeType,
templateName,
jsPath
} = await inquirer.prompt(promptConfig);
const { environment, bridgeType, templateName } = await inquirer.prompt(
promptConfig
);

const fileTypes = ["JS"];
const includediOS = environment.find(
answer => answer.indexOf("iOS") !== -1
);
if (includediOS) fileTypes.unshift("iOS");
const includedAndroid = environment.find(
answer => answer.indexOf("Android") !== -1
);
if (includedAndroid) fileTypes.unshift("Android");

const extraPromptConfig = fileTypes.map(fileType => {
return {
type: "input",
name: `${fileType.toLowerCase()}Path`,
message: `What directory should we deliver your ${fileType} files to?`,
default: fileType === "JS" ? "." : fileType.toLowerCase(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the default, we should create an object above with the file types as the keys and the default paths as the values. Then, you can look them up.

You can use the paths that we're currently delivering the files to in RNCB as your defaults.

validate: input => isValid(input)
};
});

const { iosPath, androidPath, jsPath } = await inquirer.prompt(
extraPromptConfig
);

const templateFolder = bridgeType.length > 1
? "combined"
: bridgeType[0] === "Native Module" ? "modules" : "ui-components";

const promises = environment.map(env =>
environmentMap[env](templateName, templateFolder)
);
const promises = environment.map(env => {
const nativePath = env.indexOf("iOS") !== -1 ? iosPath : androidPath;
return environmentMap[env](templateName, templateFolder, nativePath);
});

promises.push(createJSEnvironment(templateName, templateFolder, jsPath));
await Promise.all(promises);
Expand All @@ -77,7 +92,7 @@ async function init() {
}
}

async function createJavaEnvironment(templateName, templateFolder) {
async function createJavaEnvironment(templateName, templateFolder, nativePath) {
const appPath = path.join(
process.cwd(),
"android",
Expand Down Expand Up @@ -119,7 +134,11 @@ async function createJavaEnvironment(templateName, templateFolder) {
);
}

async function createKotlinEnvironment(templateName, templateFolder) {
async function createKotlinEnvironment(
templateName,
templateFolder,
nativePath
) {
const appPath = path.join(
process.cwd(),
"android",
Expand Down Expand Up @@ -161,7 +180,11 @@ async function createKotlinEnvironment(templateName, templateFolder) {
);
}

async function createSwiftEnvironment(templateName, templateFolder) {
async function createSwiftEnvironment(
templateName,
templateFolder,
nativePath
) {
const readDirPath = path.join(
__dirname,
"..",
Expand All @@ -170,17 +193,22 @@ async function createSwiftEnvironment(templateName, templateFolder) {
"ios-swift"
);

if (nativePath !== "ios") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nativePath will always be the writeDirPath so I think you can get rid of this if block.

nativePath = path.join(process.cwd(), "ios", nativePath);
await mkdir(nativePath);
}

const paths = {
readDirPath,
writeDirPath: path.join(process.cwd(), "ios")
writeDirPath: nativePath
};

const files = await getFileNames(readDirPath);

return readAndWriteFiles(files, paths, templateName);
}

async function createObjCEnvironment(templateName, templateFolder) {
async function createObjCEnvironment(templateName, templateFolder, nativePath) {
const readDirPath = path.join(
__dirname,
"..",
Expand All @@ -189,9 +217,14 @@ async function createObjCEnvironment(templateName, templateFolder) {
"ios-objc"
);

if (nativePath !== "ios") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as the Swift function

nativePath = path.join(process.cwd(), "ios", nativePath);
await mkdir(nativePath);
}

const paths = {
readDirPath,
writeDirPath: path.join(process.cwd(), "ios")
writeDirPath: nativePath
};

const files = await getFileNames(readDirPath);
Expand Down