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

[template-files][tools-public] don't use jq in check-dynamic-macros-android.sh #7607

Merged
merged 1 commit into from Apr 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -45,6 +45,9 @@ xcuserdata
.project
.settings

# VSCode
.history/

Comment on lines +48 to +50
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I move this to a separate commit?

# Android
*.apk
*.hprof
Expand Down
1 change: 1 addition & 0 deletions template-files/android-paths.check-ignore
@@ -0,0 +1 @@
apps/bare-expo/android/app/google-services.json
14 changes: 5 additions & 9 deletions template-files/android-paths.json
@@ -1,11 +1,7 @@
{
"paths": {
"AndroidManifest.xml": "android/app/src/main/",
"google-services.json": "android/app/",
"ExponentKeys.java": "android/expoview/src/main/java/host/exp/exponent/generated/",
"fabric.properties": "android/app/"
},
"generateOnly": {
"bare-expo/android/app/google-services.json": "apps/"
}
"AndroidManifest.xml": "android/app/src/main/AndroidManifest.xml",
"google-services.json": "android/app/google-services.json",
"ExponentKeys.java": "android/expoview/src/main/java/host/exp/exponent/generated/ExponentKeys.java",
"fabric.properties": "android/app/fabric.properties",
"bare-expo/android/app/google-services.json": "apps/bare-expo/android/app/google-services.json"
}
1 change: 1 addition & 0 deletions template-files/ios-paths.check-ignore
@@ -0,0 +1 @@
bare-expo/ios/BareExpo/GoogleService-Info.plist
8 changes: 2 additions & 6 deletions template-files/ios-paths.json
@@ -1,8 +1,4 @@
{
"paths": {
"GoogleService-Info.plist": "ios/Exponent/Supporting/"
},
"generateOnly": {
"bare-expo/ios/BareExpo/GoogleService-Info.plist": "apps/"
}
"GoogleService-Info.plist": "ios/Exponent/Supporting/GoogleService-Info.plist",
"bare-expo/ios/BareExpo/GoogleService-Info.plist": "apps/bare-expo/ios/BareExpo/GoogleService-Info.plist"
}
8 changes: 4 additions & 4 deletions tools-public/check-dynamic-macros-android.sh
Expand Up @@ -25,17 +25,17 @@ function throwIfFileDoesntExist() {
fi
}

jq '.["paths"]' ../template-files/android-paths.json | awk -F'"' '
comm -3 <(sort <(awk -F'"' '
# splits lines on `"` character which lets us detect key and value in:
# "fileName": "pathForFile",
# $1" $2 "$3" $4 "$5
(length($2) > 0) { print $4 $2 }
(length($2) > 0) { print $4 }
# if $5 is empty or equal to "," it is ok,
# otherwise something is wrong
(length($5) > 0 && $5 != ",") {
(length($5) > 0 && $5 != ",") {
printf("Failed to naively parse JSON file line %s.\n", $0) > "/dev/stderr"
exit 1
}' |
}' ../template-files/android-paths.json)) <(sort ../template-files/android-paths.check-ignore) |
while read PATH_TO_CHECK
do
throwIfFileDoesntExist $PATH_TO_CHECK
Expand Down
@@ -1,8 +1,8 @@
import path from 'path';
import { Command } from '@expo/commander';
import path from 'path';

import { Directories } from '../expotools';
import { generateDynamicMacrosAsync } from '../dynamic-macros/generateDynamicMacros';
import { Directories } from '../expotools';

const EXPO_DIR = Directories.getExpoRepositoryRootDir();
const ANDROID_DIR = Directories.getAndroidDir();
Expand Down
12 changes: 7 additions & 5 deletions tools/expotools/src/commands/IosGenerateDynamicMacros.ts
@@ -1,11 +1,11 @@
import path from 'path';
import { Command } from '@expo/commander';
import path from 'path';

import { Directories } from '../expotools';
import {
generateDynamicMacrosAsync,
cleanupDynamicMacrosAsync,
} from '../dynamic-macros/generateDynamicMacros';
import { Directories } from '../expotools';

const EXPO_DIR = Directories.getExpoRepositoryRootDir();
const IOS_DIR = Directories.getIosDir();
Expand All @@ -21,7 +21,7 @@ async function generateAction(options): Promise<void> {
await generateDynamicMacrosAsync({
buildConstantsPath,
platform: 'ios',
infoPlistPath: infoPlistPath,
infoPlistPath,
expoKitPath: EXPO_DIR,
templateFilesPath: TEMPLATE_FILES_DIR,
configuration,
Expand All @@ -34,7 +34,7 @@ async function cleanupAction(options): Promise<void> {

await cleanupDynamicMacrosAsync({
platform: 'ios',
infoPlistPath: infoPlistPath,
infoPlistPath,
expoKitPath: EXPO_DIR,
});
}
Expand All @@ -61,7 +61,9 @@ export default (program: Command) => {
)
.option(
'--skip-template [string]',
'Skip generating a template (ie) GoogleService-Info.plist. Optional.', collect, []
'Skip generating a template (ie) GoogleService-Info.plist. Optional.',
collect,
[]
)
.description('Generates dynamic macros for iOS client.')
.asyncAction(generateAction);
Expand Down
49 changes: 26 additions & 23 deletions tools/expotools/src/dynamic-macros/generateDynamicMacros.ts
@@ -1,13 +1,12 @@
import path from 'path';
import fs from 'fs-extra';
import chalk from 'chalk';
import JsonFile from '@expo/json-file';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';

import macros from './macros';
import { Directories } from '../expotools';

import IosMacrosGenerator from './IosMacrosGenerator';
import AndroidMacrosGenerator from './AndroidMacrosGenerator';
import IosMacrosGenerator from './IosMacrosGenerator';
import macros from './macros';

const EXPO_DIR = Directories.getExpoRepositoryRootDir();

Expand Down Expand Up @@ -141,44 +140,38 @@ async function copyTemplateFileAsync(
}
}

interface AndroidPaths {
paths: {
[id: string]: string
},
generateOnly: {
[id: string]: string
}
}
type TemplatePaths = Record<string, string>;
type CheckIgnoredTemplatePaths = string[];

async function copyTemplateFilesAsync(platform, args, templateSubstitutions) {
async function copyTemplateFilesAsync(platform: string, args: any, templateSubstitutions: any) {
const templateFilesPath = args.templateFilesPath || path.join(EXPO_DIR, 'template-files');
const templatePathsFile = await new JsonFile(
const templatePaths = (await new JsonFile(
path.join(templateFilesPath, `${platform}-paths.json`)
).readAsync() as unknown as AndroidPaths;
).readAsync()) as TemplatePaths;
const checkIgnoredTemplatePaths = await readCheckIgnoredTemplatePaths(platform);
const promises: Promise<any>[] = [];
const skipTemplates: Array<string> = args.skipTemplates || [];
const templatePaths = { ...templatePathsFile.paths, ...templatePathsFile.generateOnly };
const skipTemplates: string[] = args.skipTemplates || [];
for (const [source, dest] of Object.entries(templatePaths)) {
if (skipTemplates.includes(source)){
if (skipTemplates.includes(source)) {
console.log(
'Skipping template %s ...',
chalk.cyan(path.join(templateFilesPath, platform, source))
);
continue;
}

const isOptional = !!templatePathsFile.generateOnly[source];
const isOptional = checkIgnoredTemplatePaths.includes(source);
console.log(
'Rendering %s from template %s %s...',
chalk.cyan(path.join(EXPO_DIR, dest as string, source)),
chalk.cyan(path.join(EXPO_DIR, dest)),
chalk.cyan(path.join(templateFilesPath, platform, source)),
isOptional ? chalk.yellow('(Optional) ') : ''
);

promises.push(
copyTemplateFileAsync(
path.join(templateFilesPath, platform, source),
path.join(EXPO_DIR, dest as string, source),
path.join(EXPO_DIR, dest),
templateSubstitutions,
args.configuration,
isOptional
Expand All @@ -189,4 +182,14 @@ async function copyTemplateFilesAsync(platform, args, templateSubstitutions) {
await Promise.all(promises);
}

async function readCheckIgnoredTemplatePaths(platform: string): Promise<CheckIgnoredTemplatePaths> {
const fileContents = (await readExistingSourceAsync(`${platform}-paths.check-ignore`)) || '';
const fileContentsTrimmed = fileContents.trim();
if (fileContentsTrimmed) {
return fileContentsTrimmed.split('\n');
} else {
return [];
}
}

export { generateDynamicMacrosAsync, cleanupDynamicMacrosAsync, getTemplateSubstitutionsAsync };