Parse match patterns from static directory into Flipper
Summary: Here I parse in the match patterns belonging to the Facebook app into Flipper. In order to keep things generalized, we can add match patterns for other apps here also e.g. Instagram. These functions are internal only, but I cannot hide them as we do not have dynamic imports. Instead, the match patterns file is hidden, and I plan to have the file read fail silently for external use. Reviewed By: danielbuechele Differential Revision: D16646444 fbshipit-source-id: c7978f61e5e9cfc137552777a9ed53b264184293
This commit is contained in:
committed by
Facebook Github Bot
parent
80b2929992
commit
c3b266c925
@@ -39,3 +39,8 @@ export type AutoCompleteLineItem = {|
|
||||
matchPattern: string,
|
||||
uri: URI,
|
||||
|};
|
||||
|
||||
export type AppMatchPattern = {|
|
||||
className: string,
|
||||
pattern: string,
|
||||
|};
|
||||
|
||||
43
src/plugins/navigation/util/appMatchPatterns.js
Normal file
43
src/plugins/navigation/util/appMatchPatterns.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import type {AppMatchPattern} from '../flow-types';
|
||||
|
||||
const extractAppNameFromSelectedApp = (selectedApp: ?string) => {
|
||||
if (selectedApp == null) {
|
||||
return null;
|
||||
} else {
|
||||
return selectedApp.split('#')[0];
|
||||
}
|
||||
};
|
||||
|
||||
export const getAppMatchPatterns = (selectedApp: ?string) => {
|
||||
return new Promise<Array<AppMatchPattern>>((resolve, reject) => {
|
||||
const appName = extractAppNameFromSelectedApp(selectedApp);
|
||||
if (appName === 'Facebook') {
|
||||
const patternsPath = path.join(
|
||||
'facebook',
|
||||
'facebook-match-patterns.json',
|
||||
);
|
||||
fs.readFile(patternsPath, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(JSON.parse(data.toString()));
|
||||
}
|
||||
});
|
||||
} else if (appName != null) {
|
||||
reject(new Error('No rule for app ' + appName));
|
||||
} else {
|
||||
reject(new Error('selectedApp was null'));
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user