Skip to content

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

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
79 changes: 57 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 @@ -47,22 +40,50 @@ const environmentMap = {
"iOS/Objective-C": createObjCEnvironment
};

const defaultPathsMap = {
JS: ".",
iOS: "ios",
Android: "android"
};

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: defaultPathsMap[fileType],
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 +98,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 +140,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 +186,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 +199,20 @@ async function createSwiftEnvironment(templateName, templateFolder) {
"ios-swift"
);

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 +221,12 @@ async function createObjCEnvironment(templateName, templateFolder) {
"ios-objc"
);

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