initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

2
node_modules/react-native/local-cli/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,2 @@
__fixtures__
__tests__

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
// beeper@1.1.0 has a return statement outside of a function
// and therefore doesn't parse. Let's mock it so that we can
// run the tests.
module.exports = function () {};

436
node_modules/react-native/local-cli/__mocks__/fs.js generated vendored Normal file
View File

@@ -0,0 +1,436 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const asyncify = require('async/asyncify');
const {EventEmitter} = require('events');
const {dirname} = require.requireActual('path');
const fs = jest.genMockFromModule('fs');
const invariant = require('fbjs/lib/invariant');
const path = require('path');
const stream = require.requireActual('stream');
const noop = () => {};
function asyncCallback(cb) {
return function() {
setImmediate(() => cb.apply(this, arguments));
};
}
const mtime = {
getTime: () => Math.ceil(Math.random() * 10000000),
};
fs.realpath.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let node;
try {
node = getToNode(filepath);
} catch (e) {
return callback(e);
}
if (node && typeof node === 'object' && node.SYMLINK != null) {
return callback(null, node.SYMLINK);
}
return callback(null, filepath);
});
fs.readdirSync.mockImplementation(filepath => Object.keys(getToNode(filepath)));
fs.readdir.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let node;
try {
node = getToNode(filepath);
if (node && typeof node === 'object' && node.SYMLINK != null) {
node = getToNode(node.SYMLINK);
}
} catch (e) {
return callback(e);
}
if (!(node && typeof node === 'object' && node.SYMLINK == null)) {
return callback(new Error(filepath + ' is not a directory.'));
}
return callback(null, Object.keys(node));
});
fs.readFile.mockImplementation(asyncify(fs.readFileSync));
fs.readFileSync.mockImplementation(function(filepath, encoding) {
filepath = path.normalize(filepath);
const node = getToNode(filepath);
if (isDirNode(node)) {
throw new Error('Error readFileSync a dir: ' + filepath);
}
if (Buffer.isBuffer(node) && typeof encoding !== 'undefined') {
return node.toString();
}
return node;
});
fs.writeFile.mockImplementation(asyncify(fs.writeFileSync));
fs.writeFileSync.mockImplementation((filePath, content, options) => {
filePath = path.normalize(filePath);
if (options == null || typeof options === 'string') {
options = {encoding: options};
}
invariant(
options.encoding == null || options.encoding === 'utf8',
'`options` argument supports only `null` or `"utf8"`',
);
const dirPath = path.dirname(filePath);
const node = getToNode(dirPath);
if (!isDirNode(node)) {
throw fsError('ENOTDIR', 'not a directory: ' + dirPath);
}
node[path.basename(filePath)] = content;
});
const openFds = new Map();
let nextFd = 3;
fs.openSync.mockImplementation((filePath, flags) => {
const dirPath = path.dirname(filePath);
const node = getToNode(dirPath);
if (!isDirNode(node)) {
throw fsError('ENOTDIR', 'not a directory: ' + dirPath);
}
node[path.basename(filePath)] = '';
openFds.set(nextFd, {filePath, flags, node});
return nextFd++;
});
fs.writeSync.mockImplementation((fd, str) => {
invariant(typeof str === 'string', 'only strings supported');
const data = openFds.get(fd);
if (data == null || data.flags !== 'w') {
throw fsError('EBADF', 'bad file descriptor, write');
}
data.node[path.basename(data.filePath)] += str;
});
fs.closeSync.mockImplementation(fd => {
openFds.delete(fd);
});
fs.mkdir.mockImplementation(asyncify(fs.mkdirSync));
fs.mkdirSync.mockImplementation((dirPath, mode) => {
const parentPath = path.dirname(dirPath);
const node = getToNode(parentPath);
if (!isDirNode(node)) {
throw fsError('ENOTDIR', 'not a directory: ' + parentPath);
}
if (node[path.basename(dirPath)] == null) {
node[path.basename(dirPath)] = {};
}
});
function fsError(code, message) {
const error = new Error(code + ': ' + message);
error.code = code;
return error;
}
function isDirNode(node) {
return (
node &&
typeof node === 'object' &&
node.SYMLINK == null &&
Buffer.isBuffer(node) === false
);
}
function readlinkSync(filepath) {
const node = getToNode(filepath);
if (node !== null && typeof node === 'object' && !!node.SYMLINK) {
return node.SYMLINK;
} else {
throw new Error(`EINVAL: invalid argument, readlink '${filepath}'`);
}
}
fs.readlink.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let result;
try {
result = readlinkSync(filepath);
} catch (e) {
callback(e);
return;
}
callback(null, result);
});
fs.readlinkSync.mockImplementation(readlinkSync);
function existsSync(filepath) {
try {
const node = getToNode(filepath);
return node !== null;
} catch (e) {
return false;
}
}
fs.exists.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let result;
try {
result = existsSync(filepath);
} catch (e) {
callback(e);
return;
}
callback(null, result);
});
fs.existsSync.mockImplementation(existsSync);
function makeStatResult(node) {
const isSymlink = node != null && node.SYMLINK != null;
return {
isBlockDevice: () => false,
isCharacterDevice: () => false,
isDirectory: () => node != null && typeof node === 'object' && !isSymlink,
isFIFO: () => false,
isFile: () => node != null && typeof node === 'string',
isSocket: () => false,
isSymbolicLink: () => isSymlink,
mtime,
};
}
function statSync(filepath) {
const node = getToNode(filepath);
if (node != null && node.SYMLINK) {
return statSync(node.SYMLINK);
}
return makeStatResult(node);
}
fs.stat.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let result;
try {
result = statSync(filepath);
} catch (e) {
callback(e);
return;
}
callback(null, result);
});
fs.statSync.mockImplementation(statSync);
function lstatSync(filepath) {
const node = getToNode(filepath);
return makeStatResult(node);
}
fs.lstat.mockImplementation((filepath, callback) => {
callback = asyncCallback(callback);
let result;
try {
result = lstatSync(filepath);
} catch (e) {
callback(e);
return;
}
callback(null, result);
});
fs.lstatSync.mockImplementation(lstatSync);
fs.open.mockImplementation(function(filepath) {
const callback = arguments[arguments.length - 1] || noop;
let data, error, fd;
try {
data = getToNode(filepath);
} catch (e) {
error = e;
}
if (error || data == null) {
error = Error(`ENOENT: no such file or directory: \`${filepath}\``);
}
if (data != null) {
/* global Buffer: true */
fd = {buffer: new Buffer(data, 'utf8'), position: 0};
}
callback(error, fd);
});
fs.read.mockImplementation(
(fd, buffer, writeOffset, length, position, callback = noop) => {
let bytesWritten;
try {
if (position == null || position < 0) {
({position} = fd);
}
bytesWritten = fd.buffer.copy(
buffer,
writeOffset,
position,
position + length,
);
fd.position = position + bytesWritten;
} catch (e) {
callback(Error('invalid argument'));
return;
}
callback(null, bytesWritten, buffer);
},
);
fs.close.mockImplementation((fd, callback = noop) => {
try {
fd.buffer = fs.position = undefined;
} catch (e) {
callback(Error('invalid argument'));
return;
}
callback(null);
});
let filesystem = {};
fs.mock = {
clear() {
filesystem = {};
},
};
fs.createReadStream.mockImplementation(filepath => {
if (!filepath.startsWith('/')) {
throw Error('Cannot open file ' + filepath);
}
const parts = filepath.split('/').slice(1);
let file = filesystem;
for (const part of parts) {
file = file[part];
if (!file) {
break;
}
}
if (typeof file !== 'string') {
throw Error('Cannot open file ' + filepath);
}
return new stream.Readable({
read() {
this.push(file, 'utf8');
this.push(null);
},
});
});
fs.createWriteStream.mockImplementation(filePath => {
let node;
const writeStream = new stream.Writable({
write(chunk, encoding, callback) {
this.__chunks.push(chunk);
node[path.basename(filePath)] = this.__chunks.join('');
callback();
},
});
writeStream.__file = filePath;
writeStream.__chunks = [];
writeStream.end = jest.fn(writeStream.end);
fs.createWriteStream.mock.returned.push(writeStream);
try {
const dirPath = dirname(filePath);
node = getToNode(dirPath);
if (!isDirNode(node)) {
throw fsError('ENOTDIR', 'not a directory: ' + dirPath);
}
// Truncate the file on opening.
node[path.basename(filePath)] = '';
} catch (error) {
process.nextTick(() => writeStream.emit('error', error));
}
return writeStream;
});
fs.createWriteStream.mock.returned = [];
fs.__setMockFilesystem = object => (filesystem = object);
const watcherListByPath = new Map();
fs.watch.mockImplementation((filename, options, listener) => {
if (options.recursive) {
throw new Error('recursive watch not implemented');
}
let watcherList = watcherListByPath.get(filename);
if (watcherList == null) {
watcherList = [];
watcherListByPath.set(filename, watcherList);
}
const fsWatcher = new EventEmitter();
fsWatcher.on('change', listener);
fsWatcher.close = () => {
watcherList.splice(watcherList.indexOf(fsWatcher), 1);
fsWatcher.close = () => {
throw new Error('FSWatcher is already closed');
};
};
watcherList.push(fsWatcher);
});
fs.__triggerWatchEvent = (eventType, filename) => {
const directWatchers = watcherListByPath.get(filename) || [];
directWatchers.forEach(wtc => wtc.emit('change', eventType));
const dirPath = path.dirname(filename);
const dirWatchers = watcherListByPath.get(dirPath) || [];
dirWatchers.forEach(wtc =>
wtc.emit('change', eventType, path.relative(dirPath, filename)),
);
};
function getToNode(filepath) {
// Ignore the drive for Windows paths.
if (filepath.match(/^[a-zA-Z]:\\/)) {
filepath = filepath.substring(2);
}
if (filepath.endsWith(path.sep)) {
filepath = filepath.slice(0, -1);
}
const parts = filepath.split(/[\/\\]/);
if (parts[0] !== '') {
throw new Error('Make sure all paths are absolute.');
}
let node = filesystem;
parts.slice(1).forEach(part => {
if (node && node.SYMLINK) {
node = getToNode(node.SYMLINK);
}
node = node[part];
if (node == null) {
const err = new Error(
`ENOENT: no such file or directory: \`${filepath}\``,
);
err.code = 'ENOENT';
throw err;
}
});
return node;
}
module.exports = fs;

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
function sign(source) {
return source;
}
module.exports = sign;

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
/**
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
* floating point numbers imprecision.
*/
function getAndroidAssetSuffix(scale: number): string {
switch (scale) {
case 0.75: return 'ldpi';
case 1: return 'mdpi';
case 1.5: return 'hdpi';
case 2: return 'xhdpi';
case 3: return 'xxhdpi';
case 4: return 'xxxhdpi';
}
throw new Error('no such scale');
}
// See https://developer.android.com/guide/topics/resources/drawable-resource.html
const drawableFileTypes = new Set([
'gif',
'jpeg',
'jpg',
'png',
'svg',
'webp',
'xml',
]);
function getAndroidResourceFolderName(asset: PackagerAsset, scale: number) {
if (!drawableFileTypes.has(asset.type)) {
return 'raw';
}
var suffix = getAndroidAssetSuffix(scale);
if (!suffix) {
throw new Error(
'Don\'t know which android drawable suffix to use for asset: ' +
JSON.stringify(asset)
);
}
const androidFolder = 'drawable-' + suffix;
return androidFolder;
}
function getAndroidResourceIdentifier(asset: PackagerAsset) {
var folderPath = getBasePath(asset);
return (folderPath + '/' + asset.name)
.toLowerCase()
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
}
function getBasePath(asset: PackagerAsset) {
var basePath = asset.httpServerLocation;
if (basePath[0] === '/') {
basePath = basePath.substr(1);
}
return basePath;
}
module.exports = {
getAndroidAssetSuffix: getAndroidAssetSuffix,
getAndroidResourceFolderName: getAndroidResourceFolderName,
getAndroidResourceIdentifier: getAndroidResourceIdentifier,
getBasePath: getBasePath
};

View File

@@ -0,0 +1,134 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const log = require('../util/log').out('bundle');
/* $FlowFixMe(site=react_native_oss) */
const Server = require('metro/src/Server');
const {Terminal} = require('metro-core');
/* $FlowFixMe(site=react_native_oss) */
const TerminalReporter = require('metro/src/lib/TerminalReporter');
/* $FlowFixMe(site=react_native_oss) */
const TransformCaching = require('metro/src/lib/TransformCaching');
const {defaults} = require('metro');
/* $FlowFixMe(site=react_native_oss) */
const outputBundle = require('metro/src/shared/output/bundle');
const path = require('path');
const saveAssets = require('./saveAssets');
const {ASSET_REGISTRY_PATH} = require('../core/Constants');
import type {RequestOptions, OutputOptions} from './types.flow';
import type {ConfigT} from 'metro';
const defaultAssetExts = defaults.assetExts;
const defaultSourceExts = defaults.sourceExts;
const defaultPlatforms = defaults.platforms;
const defaultProvidesModuleNodeModules = defaults.providesModuleNodeModules;
async function buildBundle(
args: OutputOptions & {
assetsDest: mixed,
entryFile: string,
maxWorkers: number,
resetCache: boolean,
transformer: string,
minify: boolean,
},
config: ConfigT,
output = outputBundle,
) {
// This is used by a bazillion of npm modules we don't control so we don't
// have other choice than defining it as an env variable here.
process.env.NODE_ENV = args.dev ? 'development' : 'production';
let sourceMapUrl = args.sourcemapOutput;
if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
sourceMapUrl = path.basename(sourceMapUrl);
}
const requestOpts: RequestOptions = {
entryFile: args.entryFile,
sourceMapUrl,
dev: args.dev,
minify: args.minify !== undefined ? args.minify : !args.dev,
platform: args.platform,
};
const assetExts = (config.getAssetExts && config.getAssetExts()) || [];
const sourceExts = (config.getSourceExts && config.getSourceExts()) || [];
const platforms = (config.getPlatforms && config.getPlatforms()) || [];
const transformModulePath = args.transformer
? path.resolve(args.transformer)
: config.getTransformModulePath();
const providesModuleNodeModules =
typeof config.getProvidesModuleNodeModules === 'function'
? config.getProvidesModuleNodeModules()
: defaultProvidesModuleNodeModules;
const terminal = new Terminal(process.stdout);
const server = new Server({
assetExts: defaultAssetExts.concat(assetExts),
assetRegistryPath: ASSET_REGISTRY_PATH,
blacklistRE: config.getBlacklistRE(),
cacheStores: config.cacheStores,
cacheVersion: config.cacheVersion,
dynamicDepsInPackages: config.dynamicDepsInPackages,
enableBabelRCLookup: config.getEnableBabelRCLookup(),
extraNodeModules: config.extraNodeModules,
getModulesRunBeforeMainModule: config.getModulesRunBeforeMainModule,
getPolyfills: config.getPolyfills,
getTransformOptions: config.getTransformOptions,
globalTransformCache: null,
hasteImplModulePath: config.hasteImplModulePath,
maxWorkers: args.maxWorkers,
platforms: defaultPlatforms.concat(platforms),
postMinifyProcess: config.postMinifyProcess,
postProcessModules: config.postProcessModules,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
projectRoots: config.getProjectRoots(),
providesModuleNodeModules: providesModuleNodeModules,
resetCache: args.resetCache,
reporter: new TerminalReporter(terminal),
sourceExts: sourceExts.concat(defaultSourceExts),
transformCache: TransformCaching.useTempDir(),
transformModulePath: transformModulePath,
watch: false,
workerPath: config.getWorkerPath && config.getWorkerPath(),
});
const bundle = await output.build(server, requestOpts);
await output.save(bundle, args, log);
// Save the assets of the bundle
const outputAssets = await server.getAssets({
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOpts,
bundleType: 'todo',
});
// When we're done saving bundle output and the assets, we're done.
const assets = await saveAssets(
outputAssets,
args.platform,
args.assetsDest,
);
server.end();
return assets;
}
module.exports = buildBundle;

31
node_modules/react-native/local-cli/bundle/bundle.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const buildBundle = require('./buildBundle');
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
const outputBundle = require('metro/src/shared/output/bundle');
/**
* Builds the bundle starting to look for dependencies at the given entry path.
*/
function bundleWithOutput(argv, config, args, output) {
if (!output) {
output = outputBundle;
}
return buildBundle(args, config, output);
}
module.exports = {
name: 'bundle',
description: 'builds the javascript bundle for offline use',
func: bundleWithOutput,
options: bundleCommandLineArgs,
// not used by the CLI itself
withOutput: bundleWithOutput,
};

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = [
{
command: '--entry-file <path>',
description: 'Path to the root JS file, either absolute or relative to JS root',
}, {
command: '--platform [string]',
description: 'Either "ios" or "android"',
default: 'ios',
}, {
command: '--transformer [string]',
description: 'Specify a custom transformer to be used',
}, {
command: '--dev [boolean]',
description: 'If false, warnings are disabled and the bundle is minified',
parse: (val) => val === 'false' ? false : true,
default: true,
}, {
command: '--minify [boolean]',
description: 'Allows overriding whether bundle is minified. This defaults to ' +
'false if dev is true, and true if dev is false. Disabling minification ' +
'can be useful for speeding up production builds for testing purposes.',
parse: (val) => val === 'false' ? false : true,
}, {
command: '--bundle-output <string>',
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
}, {
command: '--bundle-encoding [string]',
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
default: 'utf8',
}, {
command: '--max-workers [number]',
description: 'Specifies the maximum number of workers the worker-pool ' +
'will spawn for transforming files. This defaults to the number of the ' +
'cores available on your machine.',
parse: (workers: string) => Number(workers),
}, {
command: '--sourcemap-output [string]',
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
}, {
command: '--sourcemap-sources-root [string]',
description: 'Path to make sourcemap\'s sources entries relative to, ex. /root/dir',
}, {
command: '--sourcemap-use-absolute-path',
description: 'Report SourceMapURL using its full path',
default: false,
}, {
command: '--assets-dest [string]',
description: 'Directory name where to store assets referenced in the bundle',
}, {
command: '--verbose',
description: 'Enables logging',
default: false,
}, {
command: '--reset-cache',
description: 'Removes cached files',
default: false,
}, {
command: '--read-global-cache',
description: 'Try to fetch transformed JS code from the global cache, if configured.',
default: false,
},
];

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const ALLOWED_SCALES = {
ios: [1, 2, 3],
};
function filterPlatformAssetScales(
platform: string,
scales: $ReadOnlyArray<number>,
): $ReadOnlyArray<number> {
const whitelist = ALLOWED_SCALES[platform];
if (!whitelist) {
return scales;
}
const result = scales.filter(scale => whitelist.indexOf(scale) > -1);
if (result.length === 0 && scales.length > 0) {
// No matching scale found, but there are some available. Ideally we don't
// want to be in this situation and should throw, but for now as a fallback
// let's just use the closest larger image
const maxScale = whitelist[whitelist.length - 1];
for (const scale of scales) {
if (scale > maxScale) {
result.push(scale);
break;
}
}
// There is no larger scales available, use the largest we have
if (result.length === 0) {
result.push(scales[scales.length - 1]);
}
}
return result;
}
module.exports = filterPlatformAssetScales;

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const assetPathUtils = require('./assetPathUtils');
const path = require('path');
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
const androidFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale);
const fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
return path.join(androidFolder, fileName + '.' + asset.type);
}
module.exports = getAssetDestPathAndroid;

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const path = require('path');
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
const suffix = scale === 1 ? '' : '@' + scale + 'x';
const fileName = asset.name + suffix + '.' + asset.type;
return path.join(asset.httpServerLocation.substr(1), fileName);
}
module.exports = getAssetDestPathIOS;

View File

@@ -0,0 +1,85 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const filterPlatformAssetScales = require('./filterPlatformAssetScales');
const fs = require('fs');
const getAssetDestPathAndroid = require('./getAssetDestPathAndroid');
const getAssetDestPathIOS = require('./getAssetDestPathIOS');
const log = require('../util/log').out('bundle');
const mkdirp = require('mkdirp');
const path = require('path');
function saveAssets(
assets,
platform,
assetsDest
) {
if (!assetsDest) {
console.warn('Assets destination folder is not set, skipping...');
return Promise.resolve();
}
const getAssetDestPath = platform === 'android'
? getAssetDestPathAndroid
: getAssetDestPathIOS;
const filesToCopy = Object.create(null); // Map src -> dest
assets
.forEach(asset => {
const validScales = new Set(filterPlatformAssetScales(platform, asset.scales));
asset.scales.forEach((scale, idx) => {
if (!validScales.has(scale)) {
return;
}
const src = asset.files[idx];
const dest = path.join(assetsDest, getAssetDestPath(asset, scale));
filesToCopy[src] = dest;
});
});
return copyAll(filesToCopy);
}
function copyAll(filesToCopy) {
const queue = Object.keys(filesToCopy);
if (queue.length === 0) {
return Promise.resolve();
}
log('Copying ' + queue.length + ' asset files');
return new Promise((resolve, reject) => {
const copyNext = (error) => {
if (error) {
return reject(error);
}
if (queue.length === 0) {
log('Done copying assets');
resolve();
} else {
const src = queue.shift();
const dest = filesToCopy[src];
copy(src, dest, copyNext);
}
};
copyNext();
});
}
function copy(src, dest, callback) {
const destDir = path.dirname(dest);
mkdirp(destDir, err => {
if (err) {
return callback(err);
}
fs.createReadStream(src)
.pipe(fs.createWriteStream(dest))
.on('finish', callback);
});
}
module.exports = saveAssets;

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
/* $FlowFixMe(site=react_native_oss) */
export type {OutputOptions, RequestOptions} from 'metro/src/shared/types.flow';

29
node_modules/react-native/local-cli/bundle/unbundle.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const bundleWithOutput = require('./bundle').withOutput;
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
const outputUnbundle = require('metro/src/shared/output/unbundle');
/**
* Builds the bundle starting to look for dependencies at the given entry path.
*/
function unbundle(argv, config, args) {
return bundleWithOutput(argv, config, args, outputUnbundle);
}
module.exports = {
name: 'unbundle',
description: 'builds javascript as "unbundle" for offline use',
func: unbundle,
options: bundleCommandLineArgs.concat({
command: '--indexed-unbundle',
description: 'Force indexed unbundle file format, even when building for android',
default: false,
}),
};

24
node_modules/react-native/local-cli/cli.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
// gracefulify() has to be called before anything else runs
require('graceful-fs').gracefulify(require('fs'));
// This file must be able to run in node 0.12 without babel so we can show that
// it is not supported. This is why the rest of the cli code is in `cliEntry.js`.
require('./server/checkNodeVersion')();
require('../setupBabel')();
var cliEntry = require('./cliEntry');
if (require.main === module) {
cliEntry.run();
}
module.exports = cliEntry;

161
node_modules/react-native/local-cli/cliEntry.js generated vendored Normal file
View File

@@ -0,0 +1,161 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const config = require('./core');
const assertRequiredOptions = require('./util/assertRequiredOptions');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const chalk = require('chalk');
const childProcess = require('child_process');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const commander = require('commander');
const commands = require('./commands');
const init = require('./init/init');
const path = require('path');
const pkg = require('../package.json');
import type {CommandT} from './commands';
import type {RNConfig} from './core';
commander.version(pkg.version);
const defaultOptParser = (val) => val;
const handleError = (err) => {
console.error();
console.error(err.message || err);
console.error();
process.exit(1);
};
// Custom printHelpInformation command inspired by internal Commander.js
// one modified to suit our needs
function printHelpInformation() {
let cmdName = this._name;
if (this._alias) {
cmdName = cmdName + '|' + this._alias;
}
const sourceInformation = this.pkg
? [
` ${chalk.bold('Source:')} ${this.pkg.name}@${this.pkg.version}`,
'',
]
: [];
let output = [
'',
chalk.bold(chalk.cyan((` react-native ${cmdName} ${this.usage()}`))),
` ${this._description}`,
'',
...sourceInformation,
` ${chalk.bold('Options:')}`,
'',
this.optionHelp().replace(/^/gm, ' '),
'',
];
if (this.examples && this.examples.length > 0) {
const formattedUsage = this.examples.map(
example => ` ${example.desc}: \n ${chalk.cyan(example.cmd)}`,
).join('\n\n');
output = output.concat([
chalk.bold(' Example usage:'),
'',
formattedUsage,
]);
}
return output.concat([
'',
'',
]).join('\n');
}
function printUnknownCommand(cmdName) {
console.log([
'',
cmdName
? chalk.red(` Unrecognized command '${cmdName}'`)
: chalk.red(' You didn\'t pass any command'),
` Run ${chalk.cyan('react-native --help')} to see list of all available commands`,
'',
].join('\n'));
}
const addCommand = (command: CommandT, cfg: RNConfig) => {
const options = command.options || [];
const cmd = commander
.command(command.name, undefined, {
noHelp: !command.description,
})
.description(command.description)
.action(function runAction() {
const passedOptions = this.opts();
const argv: Array<string> = Array.from(arguments).slice(0, -1);
Promise.resolve()
.then(() => {
assertRequiredOptions(options, passedOptions);
return command.func(argv, cfg, passedOptions);
})
.catch(handleError);
});
cmd.helpInformation = printHelpInformation.bind(cmd);
cmd.examples = command.examples;
cmd.pkg = command.pkg;
options
.forEach(opt => cmd.option(
opt.command,
opt.description,
opt.parse || defaultOptParser,
typeof opt.default === 'function' ? opt.default(cfg) : opt.default,
));
// Placeholder option for --config, which is parsed before any other option,
// but needs to be here to avoid "unknown option" errors when specified
cmd.option('--config [string]', 'Path to the CLI configuration file');
};
function run() {
const setupEnvScript = /^win/.test(process.platform)
? 'setup_env.bat'
: 'setup_env.sh';
childProcess.execFileSync(path.join(__dirname, setupEnvScript));
commands.forEach(cmd => addCommand(cmd, config));
commander.parse(process.argv);
const isValidCommand = commands.find(cmd => cmd.name.split(' ')[0] === process.argv[2]);
if (!isValidCommand) {
printUnknownCommand(process.argv[2]);
return;
}
if (!commander.args.length) {
commander.help();
}
}
module.exports = {
run: run,
init: init,
};

75
node_modules/react-native/local-cli/commands.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const { getProjectCommands } = require('./core');
import type { RNConfig } from './core';
export type CommandT = {
name: string,
description?: string,
usage?: string,
func: (argv: Array<string>, config: RNConfig, args: Object) => ?Promise<void>,
options?: Array<{
command: string,
description?: string,
parse?: (val: string) => any,
default?: ((config: RNConfig) => mixed) | mixed,
}>,
examples?: Array<{
desc: string,
cmd: string,
}>,
pkg?: {
version: string,
name: string,
},
};
const documentedCommands = [
require('./server/server'),
require('./runIOS/runIOS'),
require('./runAndroid/runAndroid'),
require('./library/library'),
require('./bundle/bundle'),
require('./bundle/unbundle'),
require('./eject/eject'),
require('./link/link'),
require('./link/unlink'),
require('./install/install'),
require('./install/uninstall'),
require('./upgrade/upgrade'),
require('./logAndroid/logAndroid'),
require('./logIOS/logIOS'),
require('./dependencies/dependencies'),
require('./info/info'),
];
// The user should never get here because projects are inited by
// using `react-native-cli` from outside a project directory.
const undocumentedCommands = [
{
name: 'init',
func: () => {
console.log([
'Looks like React Native project already exists in the current',
'folder. Run this command from a different folder or remove node_modules/react-native',
].join('\n'));
},
},
];
const commands: Array<CommandT> = [
...documentedCommands,
...undocumentedCommands,
...getProjectCommands(),
];
module.exports = commands;

20
node_modules/react-native/local-cli/core/Constants.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const ASSET_REGISTRY_PATH = 'react-native/Libraries/Image/AssetRegistry';
const ASSET_SOURCE_RESOLVER_PATH =
'react-native/Libraries/Image/AssetSourceResolver';
module.exports = {
ASSET_REGISTRY_PATH,
ASSET_SOURCE_RESOLVER_PATH,
};

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const fs = require('fs');
const path = require('path');
/**
* @param {String} folder Folder to seek in
* @return {String}
*/
module.exports = function findAndroidAppFolder(folder) {
const flat = 'android';
const nested = path.join('android', 'app');
if (fs.existsSync(path.join(folder, nested))) {
return nested;
}
if (fs.existsSync(path.join(folder, flat))) {
return flat;
}
return null;
};

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const glob = require('glob');
const path = require('path');
/**
* Find an android application path in the folder
*
* @param {String} folder Name of the folder where to seek
* @return {String}
*/
module.exports = function findManifest(folder) {
const manifestPath = glob.sync(path.join('**', 'AndroidManifest.xml'), {
cwd: folder,
ignore: ['node_modules/**', '**/build/**', 'Examples/**', 'examples/**'],
})[0];
return manifestPath ? path.join(folder, manifestPath) : null;
};

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const fs = require('fs');
const glob = require('glob');
const path = require('path');
/**
* Gets package's class name (class that implements ReactPackage)
* by searching for its declaration in all Java/Kotlin files present in the folder
*
* @param {String} folder Folder to find java/kt files
*/
module.exports = function getPackageClassName(folder) {
const files = glob.sync('**/+(*.java|*.kt)', { cwd: folder });
const packages = files
.map(filePath => fs.readFileSync(path.join(folder, filePath), 'utf8'))
.map(file => file.match(/class (.*) +(implements|:) ReactPackage/))
.filter(match => match);
return packages.length ? packages[0][1] : null;
};

View File

@@ -0,0 +1,128 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const findAndroidAppFolder = require('./findAndroidAppFolder');
const findManifest = require('./findManifest');
const findPackageClassName = require('./findPackageClassName');
const path = require('path');
const readManifest = require('./readManifest');
const getPackageName = (manifest) => manifest.attr.package;
/**
* Gets android project config by analyzing given folder and taking some
* defaults specified by user into consideration
*/
exports.projectConfig = function projectConfigAndroid(folder, userConfig) {
const src = userConfig.sourceDir || findAndroidAppFolder(folder);
if (!src) {
return null;
}
const sourceDir = path.join(folder, src);
const isFlat = sourceDir.indexOf('app') === -1;
const manifestPath = userConfig.manifestPath
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);
if (!manifestPath) {
return null;
}
const manifest = readManifest(manifestPath);
const packageName = userConfig.packageName || getPackageName(manifest);
if (!packageName) {
throw new Error(`Package name not found in ${manifestPath}`);
}
const packageFolder = userConfig.packageFolder ||
packageName.replace(/\./g, path.sep);
const mainFilePath = path.join(
sourceDir,
userConfig.mainFilePath || `src/main/java/${packageFolder}/MainApplication.java`
);
const stringsPath = path.join(
sourceDir,
userConfig.stringsPath || 'src/main/res/values/strings.xml'
);
const settingsGradlePath = path.join(
folder,
'android',
userConfig.settingsGradlePath || 'settings.gradle'
);
const assetsPath = path.join(
sourceDir,
userConfig.assetsPath || 'src/main/assets'
);
const buildGradlePath = path.join(
sourceDir,
userConfig.buildGradlePath || 'build.gradle'
);
return {
sourceDir,
isFlat,
folder,
stringsPath,
manifestPath,
buildGradlePath,
settingsGradlePath,
assetsPath,
mainFilePath,
};
};
/**
* Same as projectConfigAndroid except it returns
* different config that applies to packages only
*/
exports.dependencyConfig = function dependencyConfigAndroid(folder, userConfig) {
const src = userConfig.sourceDir || findAndroidAppFolder(folder);
if (!src) {
return null;
}
const sourceDir = path.join(folder, src);
const manifestPath = userConfig.manifestPath
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);
if (!manifestPath) {
return null;
}
const manifest = readManifest(manifestPath);
const packageName = userConfig.packageName || getPackageName(manifest);
const packageClassName = findPackageClassName(sourceDir);
/**
* This module has no package to export
*/
if (!packageClassName) {
return null;
}
const packageImportPath = userConfig.packageImportPath ||
`import ${packageName}.${packageClassName};`;
const packageInstance = userConfig.packageInstance ||
`new ${packageClassName}()`;
return { sourceDir, folder, manifest, packageImportPath, packageInstance };
};
exports.linkConfig = require('../../link/android');

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const fs = require('fs');
const xml = require('xmldoc');
/**
* @param {String} manifestPath
* @return {XMLDocument} Parsed manifest's content
*/
module.exports = function readManifest(manifestPath) {
return new xml.XmlDocument(fs.readFileSync(manifestPath, 'utf8'));
};

28
node_modules/react-native/local-cli/core/findAssets.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const glob = require('glob');
const path = require('path');
const findAssetsInFolder = (folder) =>
glob.sync(path.join(folder, '**'), { nodir: true });
/**
* Given an array of assets folders, e.g. ['Fonts', 'Images'],
* it globs in them to find all files that can be copied.
*
* It returns an array of absolute paths to files found.
*/
module.exports = function findAssets(folder, assets) {
return (assets || [])
.map(assetsFolder => path.join(folder, assetsFolder))
.reduce((_assets, assetsFolder) =>
_assets.concat(findAssetsInFolder(assetsFolder)),
[]
);
};

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const path = require('path');
const union = require('lodash').union;
const uniq = require('lodash').uniq;
const flatten = require('lodash').flatten;
/**
* Filter dependencies by name pattern
* @param {String} dependency Name of the dependency
* @return {Boolean} If dependency is a rnpm plugin
*/
const isRNPMPlugin = (dependency) => dependency.indexOf('rnpm-plugin-') === 0;
const isReactNativePlugin = (dependency) => dependency.indexOf('react-native-') === 0;
const readPackage = (folder) => {
try {
return require(path.join(folder, 'package.json'));
} catch (e) {
return null;
}
};
const findPluginsInReactNativePackage = (pjson) => {
if (!pjson.rnpm || !pjson.rnpm.plugin) {
return [];
}
return path.join(pjson.name, pjson.rnpm.plugin);
};
const findPlatformsInPackage = (pjson) => {
if (!pjson.rnpm || !pjson.rnpm.platform) {
return [];
}
return path.join(pjson.name, pjson.rnpm.platform);
};
const findPluginInFolder = (folder) => {
const pjson = readPackage(folder);
if (!pjson) {
return {commands: [], platforms: []};
}
const deps = union(
Object.keys(pjson.dependencies || {}),
Object.keys(pjson.devDependencies || {})
);
return deps.reduce(
(acc, pkg) => {
let commands = acc.commands;
let platforms = acc.platforms;
if (isRNPMPlugin(pkg)) {
commands = commands.concat(pkg);
}
if (isReactNativePlugin(pkg)) {
const pkgJson = readPackage(path.join(folder, 'node_modules', pkg));
if (pkgJson) {
commands = commands.concat(findPluginsInReactNativePackage(pkgJson));
platforms = platforms.concat(findPlatformsInPackage(pkgJson));
}
}
return {commands: commands, platforms: platforms};
},
{commands: [], platforms: []}
);
};
/**
* Find plugins in package.json of the given folder
* @param {String} folder Path to the folder to get the package.json from
* @type {Object} Object of commands and platform plugins
*/
module.exports = function findPlugins(folders) {
const plugins = folders.map(findPluginInFolder);
return {
commands: uniq(flatten(plugins.map(p => p.commands))),
platforms: uniq(flatten(plugins.map(p => p.platforms)))
};
};

145
node_modules/react-native/local-cli/core/index.js generated vendored Normal file
View File

@@ -0,0 +1,145 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const android = require('./android');
const Config = require('../util/Config');
const findPlugins = require('./findPlugins');
const findAssets = require('./findAssets');
const ios = require('./ios');
const wrapCommands = require('./wrapCommands');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const flatten = require('lodash').flatten;
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const minimist = require('minimist');
const path = require('path');
import type {CommandT} from '../commands';
import type {ConfigT} from 'metro';
export type RNConfig = {
...ConfigT,
/**
* Returns an object with all platform configurations.
*/
getPlatformConfig(): Object,
/**
* Returns an array of project commands used by the CLI to load
*/
getProjectCommands(): Array<CommandT>,
/**
* Returns project config from the current working directory
*/
getProjectConfig(): Object,
/**
* Returns dependency config from <node_modules>/packageName
*/
getDependencyConfig(pkgName: string): Object,
};
const getRNPMConfig = (folder) =>
// $FlowFixMe non-literal require
require(path.join(folder, './package.json')).rnpm || {};
const attachPackage = (command, pkg) => Array.isArray(command)
? command.map(cmd => attachPackage(cmd, pkg))
: { ...command, pkg };
const appRoot = process.cwd();
const plugins = findPlugins([appRoot]);
const pluginPlatforms = plugins
.platforms
.reduce((acc, pathToPlatforms) => {
// $FlowFixMe non-literal require
return Object.assign(acc, require(path.join(appRoot, 'node_modules', pathToPlatforms)));
},
{});
const defaultRNConfig = {
getProjectCommands(): Array<CommandT> {
const commands = plugins
.commands
.map(pathToCommands => {
const name = pathToCommands.split(path.sep)[0];
return attachPackage(
// $FlowFixMe non-literal require
require(path.join(appRoot, 'node_modules', pathToCommands)),
// $FlowFixMe non-literal require
require(path.join(appRoot, 'node_modules', name, 'package.json'))
);
});
return flatten(commands);
},
getPlatformConfig(): Object {
return {
ios,
android,
...pluginPlatforms
};
},
getProjectConfig(): Object {
const platforms = this.getPlatformConfig();
const folder = process.cwd();
const rnpm = getRNPMConfig(folder);
let config = Object.assign({}, rnpm, {
assets: findAssets(folder, rnpm.assets),
});
Object.keys(platforms).forEach(key => {
config[key] = platforms[key].projectConfig(folder, rnpm[key] || {});
});
return config;
},
getDependencyConfig(packageName: string) {
const platforms = this.getPlatformConfig();
const folder = path.join(process.cwd(), 'node_modules', packageName);
const rnpm = getRNPMConfig(
path.join(process.cwd(), 'node_modules', packageName)
);
let config = Object.assign({}, rnpm, {
assets: findAssets(folder, rnpm.assets),
commands: wrapCommands(rnpm.commands),
params: rnpm.params || [],
});
Object.keys(platforms).forEach(key => {
config[key] = platforms[key].dependencyConfig(folder, rnpm[key] || {});
});
return config;
},
};
/**
* Loads the CLI configuration
*/
function getCliConfig(): RNConfig {
const cliArgs = minimist(process.argv.slice(2));
const config = cliArgs.config != null
? Config.load(path.resolve(__dirname, cliArgs.config))
: Config.findOptional(__dirname);
return {...defaultRNConfig, ...config};
}
module.exports = getCliConfig();

View File

@@ -0,0 +1,11 @@
'use strict';
const fs = require('fs');
const path = require('path');
module.exports = function findPodfilePath(projectFolder) {
const podFilePath = path.join(projectFolder, '..', 'Podfile');
const podFileExists = fs.existsSync(podFilePath);
return podFileExists ? podFilePath : null;
};

View File

@@ -0,0 +1,28 @@
'use strict';
const glob = require('glob');
const path = require('path');
module.exports = function findPodspecName(folder) {
const podspecs = glob.sync('*.podspec', { cwd: folder });
let podspecFile = null;
if (podspecs.length === 0) {
return null;
}
else if (podspecs.length === 1) {
podspecFile = podspecs[0];
}
else {
const folderParts = folder.split(path.sep);
const currentFolder = folderParts[folderParts.length - 1];
const toSelect = podspecs.indexOf(currentFolder + '.podspec');
if (toSelect === -1) {
podspecFile = podspecs[0];
}
else {
podspecFile = podspecs[toSelect];
}
}
return podspecFile.replace('.podspec', '');
};

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const glob = require('glob');
const path = require('path');
/**
* Glob pattern to look for xcodeproj
*/
const GLOB_PATTERN = '**/*.xcodeproj';
/**
* Regexp matching all test projects
*/
const TEST_PROJECTS = /test|example|sample/i;
/**
* Base iOS folder
*/
const IOS_BASE = 'ios';
/**
* These folders will be excluded from search to speed it up
*/
const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules)/**'];
/**
* Finds iOS project by looking for all .xcodeproj files
* in given folder.
*
* Returns first match if files are found or null
*
* Note: `./ios/*.xcodeproj` are returned regardless of the name
*/
module.exports = function findProject(folder) {
const projects = glob
.sync(GLOB_PATTERN, {
cwd: folder,
ignore: GLOB_EXCLUDE_PATTERN,
})
.filter(project => {
return path.dirname(project) === IOS_BASE || !TEST_PROJECTS.test(project);
})
.sort((projectA, projectB) => {
return path.dirname(projectA) === IOS_BASE ? -1 : 1;
});
if (projects.length === 0) {
return null;
}
return projects[0];
};

59
node_modules/react-native/local-cli/core/ios/index.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const findProject = require('./findProject');
const findPodfilePath = require('./findPodfilePath');
const findPodspecName = require('./findPodspecName');
const path = require('path');
/**
* For libraries specified without an extension, add '.tbd' for those that
* start with 'lib' and '.framework' to the rest.
*/
const mapSharedLibaries = (libraries) => {
return libraries.map(name => {
if (path.extname(name)) {
return name;
}
return name + (name.indexOf('lib') === 0 ? '.tbd' : '.framework');
});
};
/**
* Returns project config by analyzing given folder and applying some user defaults
* when constructing final object
*/
exports.projectConfig = function projectConfigIOS(folder, userConfig) {
const project = userConfig.project || findProject(folder);
/**
* No iOS config found here
*/
if (!project) {
return null;
}
const projectPath = path.join(folder, project);
return {
sourceDir: path.dirname(projectPath),
folder: folder,
pbxprojPath: path.join(projectPath, 'project.pbxproj'),
podfile: findPodfilePath(projectPath),
podspec: findPodspecName(folder),
projectPath: projectPath,
projectName: path.basename(projectPath),
libraryFolder: userConfig.libraryFolder || 'Libraries',
sharedLibraries: mapSharedLibaries(userConfig.sharedLibraries || []),
plist: userConfig.plist || [],
};
};
exports.dependencyConfig = exports.projectConfig;
exports.linkConfig = require('../../link/ios');

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const spawn = require('child_process').spawn;
module.exports = function makeCommand(command) {
return (cb) => {
if (!cb) {
throw new Error(`You missed a callback function for the ${command} command`);
}
const args = command.split(' ');
const cmd = args.shift();
const commandProcess = spawn(cmd, args, {
stdio: 'inherit',
stdin: 'inherit',
});
commandProcess.on('close', function prelink(code) {
if (code) {
throw new Error(`Error occurred during executing "${command}" command`);
}
cb();
});
};
};

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const makeCommand = require('./makeCommand');
module.exports = function wrapCommands(commands) {
const mappedCommands = {};
Object.keys(commands || []).forEach((k) => {
mappedCommands[k] = makeCommand(commands[k]);
});
return mappedCommands;
};

View File

@@ -0,0 +1,123 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const Metro = require('metro');
const denodeify = require('denodeify');
const fs = require('fs');
const path = require('path');
const {ASSET_REGISTRY_PATH} = require('../core/Constants');
function dependencies(argv, config, args, packagerInstance) {
const rootModuleAbsolutePath = args.entryFile;
if (!fs.existsSync(rootModuleAbsolutePath)) {
return Promise.reject(new Error(`File ${rootModuleAbsolutePath} does not exist`));
}
const transformModulePath =
args.transformer ? path.resolve(args.transformer) :
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
undefined;
const packageOpts = {
assetRegistryPath: ASSET_REGISTRY_PATH,
cacheStores: [],
projectRoots: config.getProjectRoots(),
blacklistRE: config.getBlacklistRE(),
dynamicDepsInPackages: config.dynamicDepsInPackages,
getPolyfills: config.getPolyfills,
getTransformOptions: config.getTransformOptions,
hasteImplModulePath: config.hasteImplModulePath,
postMinifyProcess: config.postMinifyProcess,
transformModulePath: transformModulePath,
extraNodeModules: config.extraNodeModules,
verbose: config.verbose,
workerPath: config.getWorkerPath(),
};
const relativePath = packageOpts.projectRoots.map(root =>
path.relative(
root,
rootModuleAbsolutePath
)
)[0];
const options = {
platform: args.platform,
entryFile: relativePath,
dev: args.dev,
minify: false,
generateSourceMaps: !args.dev,
};
const writeToFile = args.output;
const outStream = writeToFile
? fs.createWriteStream(args.output)
: process.stdout;
return Promise.resolve((packagerInstance ?
packagerInstance.getOrderedDependencyPaths(options) :
Metro.getOrderedDependencyPaths(packageOpts, options)).then(
deps => {
deps.forEach(modulePath => {
// Temporary hack to disable listing dependencies not under this directory.
// Long term, we need either
// (a) JS code to not depend on anything outside this directory, or
// (b) Come up with a way to declare this dependency in Buck.
const isInsideProjectRoots = packageOpts.projectRoots.filter(
root => modulePath.startsWith(root)
).length > 0;
if (isInsideProjectRoots) {
outStream.write(modulePath + '\n');
}
});
return writeToFile
? denodeify(outStream.end).bind(outStream)()
: Promise.resolve();
}
));
}
module.exports = {
name: 'dependencies',
description: 'lists dependencies',
func: dependencies,
options: [
{
command: '--entry-file <path>',
description: 'Absolute path to the root JS file',
}, {
command: '--output [path]',
description: 'File name where to store the output, ex. /tmp/dependencies.txt',
}, {
command: '--platform [extension]',
description: 'The platform extension used for selecting modules',
}, {
command: '--transformer [path]',
description: 'Specify a custom transformer to be used'
}, {
command: '--max-workers [number]',
description: 'Specifies the maximum number of workers the worker-pool ' +
'will spawn for transforming files. This defaults to the number of the ' +
'cores available on your machine.',
parse: (workers: string) => Number(workers),
}, {
command: '--dev [boolean]',
description: 'If false, skip all dev-only code path',
parse: (val) => val === 'false' ? false : true,
default: true,
}, {
command: '--verbose',
description: 'Enables logging',
default: false,
},
],
};

94
node_modules/react-native/local-cli/eject/eject.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const copyProjectTemplateAndReplace = require('../generator/copyProjectTemplateAndReplace');
const path = require('path');
const fs = require('fs');
/**
* The eject command re-creates the `android` and `ios` native folders. Because native code can be
* difficult to maintain, this new script allows an `app.json` to be defined for the project, which
* is used to configure the native app.
*
* The `app.json` config may contain the following keys:
*
* - `name` - The short name used for the project, should be TitleCase
* - `displayName` - The app's name on the home screen
*/
function eject() {
const doesIOSExist = fs.existsSync(path.resolve('ios'));
const doesAndroidExist = fs.existsSync(path.resolve('android'));
if (doesIOSExist && doesAndroidExist) {
console.error(
'Both the iOS and Android folders already exist! Please delete `ios` and/or `android` ' +
'before ejecting.'
);
process.exit(1);
}
let appConfig = null;
try {
appConfig = require(path.resolve('app.json'));
} catch (e) {
console.error(
'Eject requires an `app.json` config file to be located at ' +
`${path.resolve('app.json')}, and it must at least specify a \`name\` for the project ` +
'name, and a `displayName` for the app\'s home screen label.'
);
process.exit(1);
}
const appName = appConfig.name;
if (!appName) {
console.error(
'App `name` must be defined in the `app.json` config file to define the project name. ' +
'It must not contain any spaces or dashes.'
);
process.exit(1);
}
const displayName = appConfig.displayName;
if (!displayName) {
console.error(
'App `displayName` must be defined in the `app.json` config file, to define the label ' +
'of the app on the home screen.'
);
process.exit(1);
}
const templateOptions = { displayName };
if (!doesIOSExist) {
console.log('Generating the iOS folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'ios'),
path.resolve('ios'),
appName,
templateOptions
);
}
if (!doesAndroidExist) {
console.log('Generating the Android folder.');
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld', 'android'),
path.resolve('android'),
appName,
templateOptions
);
}
}
module.exports = {
name: 'eject',
description: 'Re-create the iOS and Android folders and native code',
func: eject,
options: [],
};

View File

@@ -0,0 +1,142 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const chalk = require('chalk');
const copyAndReplace = require('../util/copyAndReplace');
const path = require('path');
const prompt = require('./promptSync')();
const walk = require('../util/walk');
/**
* Util for creating a new React Native project.
* Copy the project from a template and use the correct project name in
* all files.
* @param srcPath e.g. '/Users/martin/AwesomeApp/node_modules/react-native/local-cli/templates/HelloWorld'
* @param destPath e.g. '/Users/martin/AwesomeApp'
* @param newProjectName e.g. 'AwesomeApp'
* @param options e.g. {
* upgrade: true,
* force: false,
* displayName: 'Hello World',
* ignorePaths: ['template/file/to/ignore.md'],
* }
*/
function copyProjectTemplateAndReplace(srcPath, destPath, newProjectName, options) {
if (!srcPath) { throw new Error('Need a path to copy from'); }
if (!destPath) { throw new Error('Need a path to copy to'); }
if (!newProjectName) { throw new Error('Need a project name'); }
options = options || {};
walk(srcPath).forEach(absoluteSrcFilePath => {
// 'react-native upgrade'
if (options.upgrade) {
// Don't upgrade these files
const fileName = path.basename(absoluteSrcFilePath);
// This also includes __tests__/index.*.js
if (fileName === 'index.ios.js') { return; }
if (fileName === 'index.android.js') { return; }
if (fileName === 'index.js') { return; }
if (fileName === 'App.js') { return; }
}
const relativeFilePath = path.relative(srcPath, absoluteSrcFilePath);
const relativeRenamedPath = dotFilePath(relativeFilePath)
.replace(/HelloWorld/g, newProjectName)
.replace(/helloworld/g, newProjectName.toLowerCase());
// Templates may contain files that we don't want to copy.
// Examples:
// - Dummy package.json file included in the template only for publishing to npm
// - Docs specific to the template (.md files)
if (options.ignorePaths) {
if (!Array.isArray(options.ignorePaths)) {
throw new Error('options.ignorePaths must be an array');
}
if (options.ignorePaths.some(ignorePath => ignorePath === relativeFilePath)) {
// Skip copying this file
return;
}
}
let contentChangedCallback = null;
if (options.upgrade && (!options.force)) {
contentChangedCallback = (_, contentChanged) => {
return upgradeFileContentChangedCallback(
absoluteSrcFilePath,
relativeRenamedPath,
contentChanged,
);
};
}
copyAndReplace(
absoluteSrcFilePath,
path.resolve(destPath, relativeRenamedPath),
{
'Hello App Display Name': options.displayName || newProjectName,
'HelloWorld': newProjectName,
'helloworld': newProjectName.toLowerCase(),
},
contentChangedCallback,
);
});
}
/**
* There are various dotfiles in the templates folder in the RN repo. We want
* these to be ignored by tools when working with React Native itself.
* Example: _babelrc file is ignored by Babel, renamed to .babelrc inside
* a real app folder.
* This is especially important for .gitignore because npm has some special
* behavior of automatically renaming .gitignore to .npmignore.
*/
function dotFilePath(path) {
if (!path) {return path;}
return path
.replace('_gitignore', '.gitignore')
.replace('_gitattributes', '.gitattributes')
.replace('_babelrc', '.babelrc')
.replace('_flowconfig', '.flowconfig')
.replace('_buckconfig', '.buckconfig')
.replace('_watchmanconfig', '.watchmanconfig');
}
function upgradeFileContentChangedCallback(
absoluteSrcFilePath,
relativeDestPath,
contentChanged
) {
if (contentChanged === 'new') {
console.log(chalk.bold('new') + ' ' + relativeDestPath);
return 'overwrite';
} else if (contentChanged === 'changed') {
console.log(chalk.bold(relativeDestPath) + ' ' +
'has changed in the new version.\nDo you want to keep your ' +
relativeDestPath + ' or replace it with the ' +
'latest version?\nIf you ever made any changes ' +
'to this file, you\'ll probably want to keep it.\n' +
'You can see the new version here: ' + absoluteSrcFilePath + '\n' +
'Do you want to replace ' + relativeDestPath + '? ' +
'Answer y to replace, n to keep your version: ');
const answer = prompt();
if (answer === 'y') {
console.log('Replacing ' + relativeDestPath);
return 'overwrite';
} else {
console.log('Keeping your ' + relativeDestPath);
return 'keep';
}
} else if (contentChanged === 'identical') {
return 'keep';
} else {
throw new Error(`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
}
}
module.exports = copyProjectTemplateAndReplace;

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var chalk = require('chalk');
var path = require('path');
function printRunInstructions(projectDir, projectName) {
const absoluteProjectDir = path.resolve(projectDir);
// iOS
const xcodeProjectPath = path.resolve(projectDir, 'ios', projectName) + '.xcodeproj';
const relativeXcodeProjectPath = path.relative(process.cwd(), xcodeProjectPath);
console.log(chalk.white.bold('To run your app on iOS:'));
console.log(' cd ' + absoluteProjectDir);
console.log(' react-native run-ios');
console.log(' - or -');
console.log(' Open ' + relativeXcodeProjectPath + ' in Xcode');
console.log(' Hit the Run button');
// Android
console.log(chalk.white.bold('To run your app on Android:'));
console.log(' cd ' + absoluteProjectDir);
console.log(' Have an Android emulator running (quickest way to get started), or a device connected');
console.log(' react-native run-android');
}
module.exports = printRunInstructions;

View File

@@ -0,0 +1,118 @@
// Simplified version of:
// https://github.com/0x00A/prompt-sync/blob/master/index.js
'use strict';
var fs = require('fs');
var term = 13; // carriage return
function create() {
return prompt;
function prompt(ask, value, opts) {
var insert = 0, savedinsert = 0, res, i, savedstr;
opts = opts || {};
if (Object(ask) === ask) {
opts = ask;
ask = opts.ask;
} else if (Object(value) === value) {
opts = value;
value = opts.value;
}
ask = ask || '';
var echo = opts.echo;
var masked = 'echo' in opts;
var fd = (process.platform === 'win32') ?
process.stdin.fd :
fs.openSync('/dev/tty', 'rs');
var wasRaw = process.stdin.isRaw;
if (!wasRaw) { process.stdin.setRawMode(true); }
var buf = new Buffer(3);
var str = '', character, read;
savedstr = '';
if (ask) {
process.stdout.write(ask);
}
var cycle = 0;
var prevComplete;
while (true) {
read = fs.readSync(fd, buf, 0, 3);
if (read > 1) { // received a control sequence
if (buf.toString()) {
str = str + buf.toString();
str = str.replace(/\0/g, '');
insert = str.length;
process.stdout.write('\u001b[2K\u001b[0G' + ask + str);
process.stdout.write('\u001b[' + (insert + ask.length + 1) + 'G');
buf = new Buffer(3);
}
continue; // any other 3 character sequence is ignored
}
// if it is not a control character seq, assume only one character is read
character = buf[read - 1];
// catch a ^C and return null
if (character == 3){
process.stdout.write('^C\n');
fs.closeSync(fd);
process.exit(130);
process.stdin.setRawMode(wasRaw);
return null;
}
// catch the terminating character
if (character == term) {
fs.closeSync(fd);
break;
}
if (character == 127 || (process.platform == 'win32' && character == 8)) { //backspace
if (!insert) {continue;}
str = str.slice(0, insert - 1) + str.slice(insert);
insert--;
process.stdout.write('\u001b[2D');
} else {
if ((character < 32 ) || (character > 126))
{continue;}
str = str.slice(0, insert) + String.fromCharCode(character) + str.slice(insert);
insert++;
}
if (masked) {
process.stdout.write('\u001b[2K\u001b[0G' + ask + Array(str.length + 1).join(echo));
} else {
process.stdout.write('\u001b[s');
if (insert == str.length) {
process.stdout.write('\u001b[2K\u001b[0G' + ask + str);
} else {
if (ask) {
process.stdout.write('\u001b[2K\u001b[0G' + ask + str);
} else {
process.stdout.write('\u001b[2K\u001b[0G' + str + '\u001b[' + (str.length - insert) + 'D');
}
}
process.stdout.write('\u001b[u');
process.stdout.write('\u001b[1C');
}
}
process.stdout.write('\n');
process.stdin.setRawMode(wasRaw);
return str || value || '';
}
}
module.exports = create;

View File

@@ -0,0 +1,202 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const copyProjectTemplateAndReplace = require('./copyProjectTemplateAndReplace');
const execSync = require('child_process').execSync;
const fs = require('fs');
const path = require('path');
/**
* Templates released as part of react-native in local-cli/templates.
*/
const builtInTemplates = {
navigation: 'HelloNavigation',
};
function listTemplatesAndExit(newProjectName, options) {
if (options.template === true) {
// Just listing templates using 'react-native init --template'.
// Not creating a new app.
// Print available templates and exit.
const templateKeys = Object.keys(builtInTemplates);
if (templateKeys.length === 0) {
// Just a guard, should never happen as long builtInTemplates
// above is defined correctly :)
console.log(
'There are no templates available besides ' +
'the default "Hello World" one.'
);
} else {
console.log(
'The available templates are:\n' +
templateKeys.join('\n') +
'\nYou can use these to create an app based on a template, for example: ' +
'you could run: ' +
'react-native init ' + newProjectName + ' --template ' + templateKeys[0]
);
}
// Exit 'react-native init'
return true;
}
// Continue 'react-native init'
return false;
}
/**
* @param destPath Create the new project at this path.
* @param newProjectName For example 'AwesomeApp'.
* @param template Template to use, for example 'navigation'.
* @param yarnVersion Version of yarn available on the system, or null if
* yarn is not available. For example '0.18.1'.
*/
function createProjectFromTemplate(destPath, newProjectName, template, yarnVersion) {
// Expand the basic 'HelloWorld' template
copyProjectTemplateAndReplace(
path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld'),
destPath,
newProjectName
);
if (template === undefined) {
// No specific template, use just the HelloWorld template above
return;
}
// Keep the files from the 'HelloWorld' template, and overwrite some of them
// with the specified project template.
// The 'HelloWorld' template contains the native files (these are used by
// all templates) and every other template only contains additional JS code.
// Reason:
// This way we don't have to duplicate the native files in every template.
// If we duplicated them we'd make RN larger and risk that people would
// forget to maintain all the copies so they would go out of sync.
const builtInTemplateName = builtInTemplates[template];
if (builtInTemplateName) {
// template is e.g. 'navigation',
// use the built-in local-cli/templates/HelloNavigation folder
createFromBuiltInTemplate(builtInTemplateName, destPath, newProjectName, yarnVersion);
} else {
// template is e.g. 'ignite',
// use the template react-native-template-ignite from npm
createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion);
}
}
// (We might want to get rid of built-in templates in the future -
// publish them to npm and install from there.)
function createFromBuiltInTemplate(templateName, destPath, newProjectName, yarnVersion) {
const templatePath = path.resolve(
'node_modules', 'react-native', 'local-cli', 'templates', templateName
);
copyProjectTemplateAndReplace(
templatePath,
destPath,
newProjectName,
);
installTemplateDependencies(templatePath, yarnVersion);
}
/**
* The following formats are supported for the template:
* - 'demo' -> Fetch the package react-native-template-demo from npm
* - git://..., http://..., file://... or any other URL supported by npm
*/
function createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion) {
let installPackage;
let templateName;
if (template.includes('://')) {
// URL, e.g. git://, file://
installPackage = template;
templateName = template.substr(template.lastIndexOf('/') + 1);
} else {
// e.g 'demo'
installPackage = 'react-native-template-' + template;
templateName = installPackage;
}
// Check if the template exists
console.log(`Fetching template ${installPackage}...`);
try {
if (yarnVersion) {
execSync(`yarn add ${installPackage} --ignore-scripts`, {stdio: 'inherit'});
} else {
execSync(`npm install ${installPackage} --save --save-exact --ignore-scripts`, {stdio: 'inherit'});
}
const templatePath = path.resolve(
'node_modules', templateName
);
copyProjectTemplateAndReplace(
templatePath,
destPath,
newProjectName,
{
// Every template contains a dummy package.json file included
// only for publishing the template to npm.
// We want to ignore this dummy file, otherwise it would overwrite
// our project's package.json file.
ignorePaths: ['package.json', 'dependencies.json'],
}
);
installTemplateDependencies(templatePath, yarnVersion);
} finally {
// Clean up the temp files
try {
if (yarnVersion) {
execSync(`yarn remove ${templateName} --ignore-scripts`);
} else {
execSync(`npm uninstall ${templateName} --ignore-scripts`);
}
} catch (err) {
// Not critical but we still want people to know and report
// if this the clean up fails.
console.warn(
`Failed to clean up template temp files in node_modules/${templateName}. ` +
'This is not a critical error, you can work on your app.'
);
}
}
}
function installTemplateDependencies(templatePath, yarnVersion) {
// dependencies.json is a special file that lists additional dependencies
// that are required by this template
const dependenciesJsonPath = path.resolve(
templatePath, 'dependencies.json'
);
console.log('Adding dependencies for the project...');
if (!fs.existsSync(dependenciesJsonPath)) {
console.log('No additional dependencies.');
return;
}
let dependencies;
try {
dependencies = JSON.parse(fs.readFileSync(dependenciesJsonPath));
} catch (err) {
throw new Error(
'Could not parse the template\'s dependencies.json: ' + err.message
);
}
for (let depName in dependencies) {
const depVersion = dependencies[depName];
const depToInstall = depName + '@' + depVersion;
console.log('Adding ' + depToInstall + '...');
if (yarnVersion) {
execSync(`yarn add ${depToInstall}`, {stdio: 'inherit'});
} else {
execSync(`npm install ${depToInstall} --save --save-exact`, {stdio: 'inherit'});
}
}
console.log('Linking native dependencies into the project\'s build files...');
execSync('react-native link', {stdio: 'inherit'});
}
module.exports = {
listTemplatesAndExit,
createProjectFromTemplate,
};

45
node_modules/react-native/local-cli/info/info.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const envinfo = require('envinfo');
const info = function() {
const args = Array.prototype.slice.call(arguments)[2];
try {
envinfo.print({
packages: typeof args.packages === 'string' ? ['react', 'react-native'].concat(args.packages.split(',')) : args.packages
});
} catch (error) {
console.log('Error: unable to print environment info');
console.log(error);
}
};
module.exports = {
name: 'info',
description: 'Get relevant version info about OS, toolchain and libraries',
options: [
{
command: '--packages [string]',
description: 'Which packages from your package.json to include, in addition to the default React Native and React versions.',
default: ['react', 'react-native']
},
],
examples: [
{
desc: 'Get standard version info',
cmd: 'react-native info',
},
{
desc: 'Get standard version info & specified package versions',
cmd: 'react-native info --packages jest,eslint,babel-polyfill',
}
],
func: info,
};

117
node_modules/react-native/local-cli/init/init.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const {
listTemplatesAndExit,
createProjectFromTemplate,
} = require('../generator/templates');
const execSync = require('child_process').execSync;
const fs = require('fs');
const minimist = require('minimist');
const path = require('path');
const printRunInstructions = require('../generator/printRunInstructions');
const process = require('process');
const yarn = require('../util/yarn');
/**
* Creates the template for a React Native project given the provided
* parameters:
* @param projectDir Templates will be copied here.
* @param argsOrName Project name or full list of custom arguments
* for the generator.
* @param options Command line options passed from the react-native-cli directly.
* E.g. `{ version: '0.43.0', template: 'navigation' }`
*/
function init(projectDir, argsOrName) {
const args = Array.isArray(argsOrName)
? argsOrName // argsOrName was e.g. ['AwesomeApp', '--verbose']
: [argsOrName].concat(process.argv.slice(4)); // argsOrName was e.g. 'AwesomeApp'
// args array is e.g. ['AwesomeApp', '--verbose', '--template', 'navigation']
if (!args || args.length === 0) {
console.error('react-native init requires a project name.');
return;
}
const newProjectName = args[0];
const options = minimist(args);
if (listTemplatesAndExit(newProjectName, options)) {
// Just listing templates using 'react-native init --template'
// Not creating a new app.
return;
} else {
console.log('Setting up new React Native app in ' + projectDir);
generateProject(projectDir, newProjectName, options);
}
}
/**
* Generates a new React Native project based on the template.
* @param Absolute path at which the project folder should be created.
* @param options Command line arguments parsed by minimist.
*/
function generateProject(destinationRoot, newProjectName, options) {
var reactNativePackageJson = require('../../package.json');
var { peerDependencies } = reactNativePackageJson;
if (!peerDependencies) {
console.error('Missing React peer dependency in React Native\'s package.json. Aborting.');
return;
}
var reactVersion = peerDependencies.react;
if (!reactVersion) {
console.error('Missing React peer dependency in React Native\'s package.json. Aborting.');
return;
}
const yarnVersion =
(!options.npm) &&
yarn.getYarnVersionIfAvailable() &&
yarn.isGlobalCliUsingYarn(destinationRoot);
createProjectFromTemplate(destinationRoot, newProjectName, options.template, yarnVersion);
if (yarnVersion) {
console.log('Adding React...');
execSync(`yarn add react@${reactVersion}`, {stdio: 'inherit'});
} else {
console.log('Installing React...');
execSync(`npm install react@${reactVersion} --save --save-exact`, {stdio: 'inherit'});
}
if (!options['skip-jest']) {
const jestDeps = (
`jest babel-jest babel-preset-react-native react-test-renderer@${reactVersion}`
);
if (yarnVersion) {
console.log('Adding Jest...');
execSync(`yarn add ${jestDeps} --dev --exact`, {stdio: 'inherit'});
} else {
console.log('Installing Jest...');
execSync(`npm install ${jestDeps} --save-dev --save-exact`, {stdio: 'inherit'});
}
addJestToPackageJson(destinationRoot);
}
printRunInstructions(destinationRoot, newProjectName);
}
/**
* Add Jest-related stuff to package.json, which was created by the react-native-cli.
*/
function addJestToPackageJson(destinationRoot) {
var packageJSONPath = path.join(destinationRoot, 'package.json');
var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
preset: 'react-native'
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
}
module.exports = init;

41
node_modules/react-native/local-cli/install/install.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const spawnSync = require('child_process').spawnSync;
const log = require('npmlog');
const PackageManager = require('../util/PackageManager');
const spawnOpts = {
stdio: 'inherit',
stdin: 'inherit',
};
log.heading = 'rnpm-install';
function install(args, config) {
const name = args[0];
let res = PackageManager.add(name);
if (res.status) {
process.exit(res.status);
}
res = spawnSync('react-native', ['link', name], spawnOpts);
if (res.status) {
process.exit(res.status);
}
log.info(`Module ${name} has been successfully installed & linked`);
}
module.exports = {
func: install,
description: 'install and link native dependencies',
name: 'install <packageName>',
};

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const spawnSync = require('child_process').spawnSync;
const log = require('npmlog');
const PackageManager = require('../util/PackageManager');
const spawnOpts = {
stdio: 'inherit',
stdin: 'inherit',
};
log.heading = 'rnpm-install';
function uninstall(args, config) {
const name = args[0];
var res = spawnSync('react-native', ['unlink', name], spawnOpts);
if (res.status) {
process.exit(res.status);
}
res = PackageManager.remove(name);
if (res.status) {
process.exit(res.status);
}
log.info(`Module ${name} has been successfully uninstalled & unlinked`);
}
module.exports = {
func: uninstall,
description: 'uninstall and unlink native dependencies',
name: 'uninstall <packageName>',
};

71
node_modules/react-native/local-cli/library/library.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const copyAndReplace = require('../util/copyAndReplace');
const fs = require('fs');
const isValidPackageName = require('../util/isValidPackageName');
const path = require('path');
const walk = require('../util/walk');
/**
* Creates a new native library with the given name
*/
function library(argv, config, args) {
if (!isValidPackageName(args.name)) {
return Promise.reject(
args.name + ' is not a valid name for a project. Please use a valid ' +
'identifier name (alphanumeric).'
);
}
const root = process.cwd();
const libraries = path.resolve(root, 'Libraries');
const libraryDest = path.resolve(libraries, args.name);
const source = path.resolve('node_modules', 'react-native', 'Libraries', 'Sample');
if (!fs.existsSync(libraries)) {
fs.mkdirSync(libraries);
}
if (fs.existsSync(libraryDest)) {
return Promise.reject(new Error(`Library already exists in ${libraryDest}`));
}
walk(source).forEach(f => {
if (f.indexOf('project.xcworkspace') !== -1 ||
f.indexOf('.xcodeproj/xcuserdata') !== -1) {
return;
}
const dest = path.relative(source, f.replace(/Sample/g, args.name).replace(/^_/, '.'));
copyAndReplace(
path.resolve(source, f),
path.resolve(libraryDest, dest),
{'Sample': args.name}
);
});
console.log('Created library in', libraryDest);
console.log('Next Steps:');
console.log(' Link your library in Xcode:');
console.log(
' https://facebook.github.io/react-native/docs/' +
'linking-libraries-ios.html#content\n'
);
}
module.exports = {
name: 'new-library',
func: library,
description: 'generates a native library bridge',
options: [{
command: '--name <string>',
description: 'name of the library to generate',
default: null,
}],
};

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
const path = require('path');
const groupFilesByType = require('../groupFilesByType');
/**
* Copies each file from an array of assets provided to targetPath directory
*
* For now, the only types of files that are handled are:
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
*/
module.exports = function copyAssetsAndroid(files, project) {
const assets = groupFilesByType(files);
(assets.font || []).forEach(asset =>
fs.copySync(asset, path.join(project.assetsPath, 'fonts', path.basename(asset)))
);
};

15
node_modules/react-native/local-cli/link/android/fs.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
exports.readFile = (file) =>
() => fs.readFileSync(file, 'utf8');
exports.writeFile = (file, content) => content ?
fs.writeFileSync(file, content, 'utf8') :
(c) => fs.writeFileSync(file, c, 'utf8');

View File

@@ -0,0 +1,9 @@
module.exports = function() {
return {
isInstalled: require('./isInstalled'),
register: require('./registerNativeModule'),
unregister: require('./unregisterNativeModule'),
copyAssets: require('./copyAssets'),
unlinkAssets: require('./unlinkAssets')
};
};

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs');
const makeBuildPatch = require('./patches/makeBuildPatch');
module.exports = function isInstalled(config, name) {
const buildGradle = fs.readFileSync(config.buildGradlePath);
return makeBuildPatch(name).installPattern.test(buildGradle);
};

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const toCamelCase = require('lodash').camelCase;
module.exports = function applyParams(str, params, prefix) {
return str.replace(
/\$\{(\w+)\}/g,
(pattern, param) => {
const name = toCamelCase(prefix) + '_' + param;
return params[param]
? `getResources().getString(R.string.${name})`
: null;
}
);
};

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs');
module.exports = function applyPatch(file, patch) {
fs.writeFileSync(file, fs
.readFileSync(file, 'utf8')
.replace(patch.pattern, match => `${match}${patch.patch}`)
);
};

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = function makeBuildPatch(name) {
const installPattern = new RegExp(
`\\s{4}(compile)(\\(|\\s)(project)\\(\\\':${name}\\\'\\)(\\)|\\s)`
);
return {
installPattern,
pattern: /[^ \t]dependencies {\n/,
patch: ` compile project(':${name}')\n`
};
};

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = function makeImportPatch(packageImportPath) {
return {
pattern: 'import com.facebook.react.ReactApplication;',
patch: '\n' + packageImportPath,
};
};

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const applyParams = require('./applyParams');
module.exports = function makePackagePatch(packageInstance, params, prefix) {
const processedInstance = applyParams(packageInstance, params, prefix);
return {
pattern: 'new MainReactPackage()',
patch: ',\n ' + processedInstance,
};
};

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
const isWin = process.platform === 'win32';
module.exports = function makeSettingsPatch(name, androidConfig, projectConfig) {
var projectDir = path.relative(
path.dirname(projectConfig.settingsGradlePath),
androidConfig.sourceDir
);
/*
* Fix for Windows
* Backslashes is the escape character and will result in
* an invalid path in settings.gradle
* https://github.com/rnpm/rnpm/issues/113
*/
if (isWin) {
projectDir = projectDir.replace(/\\/g, '/');
}
return {
pattern: '\n',
patch: `include ':${name}'\n` +
`project(':${name}').projectDir = ` +
`new File(rootProject.projectDir, '${projectDir}')\n`,
};
};

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const toCamelCase = require('lodash').camelCase;
module.exports = function makeStringsPatch(params, prefix) {
const values = Object.keys(params)
.map(param => {
const name = toCamelCase(prefix) + '_' + param;
return ' ' +
`<string moduleConfig="true" name="${name}">${params[param]}</string>`;
});
const patch = values.length > 0
? values.join('\n') + '\n'
: '';
return {
pattern: '<resources>\n',
patch,
};
};

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs');
module.exports = function revokePatch(file, patch) {
fs.writeFileSync(file, fs
.readFileSync(file, 'utf8')
.replace(patch.patch, '')
);
};

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const applyPatch = require('./patches/applyPatch');
const makeStringsPatch = require('./patches/makeStringsPatch');
const makeSettingsPatch = require('./patches/makeSettingsPatch');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeImportPatch = require('./patches/makeImportPatch');
const makePackagePatch = require('./patches/makePackagePatch');
module.exports = function registerNativeAndroidModule(
name,
androidConfig,
params,
projectConfig
) {
const buildPatch = makeBuildPatch(name);
applyPatch(
projectConfig.settingsGradlePath,
makeSettingsPatch(name, androidConfig, projectConfig)
);
applyPatch(projectConfig.buildGradlePath, buildPatch);
applyPatch(projectConfig.stringsPath, makeStringsPatch(params, name));
applyPatch(
projectConfig.mainFilePath,
makePackagePatch(androidConfig.packageInstance, params, name)
);
applyPatch(
projectConfig.mainFilePath,
makeImportPatch(androidConfig.packageImportPath)
);
};

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
const path = require('path');
const groupFilesByType = require('../groupFilesByType');
/**
* Copies each file from an array of assets provided to targetPath directory
*
* For now, the only types of files that are handled are:
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
*/
module.exports = function unlinkAssetsAndroid(files, project) {
const assets = groupFilesByType(files);
(assets.font || []).forEach((file) => {
const filePath = path.join(project.assetsPath, 'fonts', path.basename(file));
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
});
};

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs');
const toCamelCase = require('lodash').camelCase;
const revokePatch = require('./patches/revokePatch');
const makeSettingsPatch = require('./patches/makeSettingsPatch');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeStringsPatch = require('./patches/makeStringsPatch');
const makeImportPatch = require('./patches/makeImportPatch');
const makePackagePatch = require('./patches/makePackagePatch');
module.exports = function unregisterNativeAndroidModule(
name,
androidConfig,
projectConfig
) {
const buildPatch = makeBuildPatch(name);
const strings = fs.readFileSync(projectConfig.stringsPath, 'utf8');
var params = {};
strings.replace(
/moduleConfig="true" name="(\w+)">(.*)</g,
(_, param, value) => {
params[param.slice(toCamelCase(name).length + 1)] = value;
}
);
revokePatch(
projectConfig.settingsGradlePath,
makeSettingsPatch(name, androidConfig, projectConfig)
);
revokePatch(projectConfig.buildGradlePath, buildPatch);
revokePatch(projectConfig.stringsPath, makeStringsPatch(params, name));
revokePatch(
projectConfig.mainFilePath,
makePackagePatch(androidConfig.packageInstance, params, name)
);
revokePatch(
projectConfig.mainFilePath,
makeImportPatch(androidConfig.packageImportPath)
);
};

View File

@@ -0,0 +1,8 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = (cb) => cb();

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given an array of dependencies - it returns their RNPM config
* if they were valid.
*/
module.exports = function getDependencyConfig(config, deps) {
return deps.reduce((acc, name) => {
try {
return acc.concat({
config: config.getDependencyConfig(name),
name,
});
} catch (err) {
console.log(err);
return acc;
}
}, []);
};

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
/**
* Returns an array of dependencies that should be linked/checked.
*/
module.exports = function getProjectDependencies() {
const pjson = require(path.join(process.cwd(), './package.json'));
return Object.keys(pjson.dependencies || {}).filter(name => name !== 'react-native');
};

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const groupBy = require('lodash').groupBy;
const mime = require('mime');
/**
* Since there are no officially registered MIME types
* for ttf/otf yet http://www.iana.org/assignments/media-types/media-types.xhtml,
* we define two non-standard ones for the sake of parsing
*/
mime.define({
'font/opentype': ['otf'],
'font/truetype': ['ttf'],
});
/**
* Given an array of files, it groups it by it's type.
* Type of the file is inferred from it's mimetype based on the extension
* file ends up with. The returned value is an object with properties that
* correspond to the first part of the mimetype, e.g. images will be grouped
* under `image` key since the mimetype for them is `image/jpg` etc.
*
* Example:
* Given an array ['fonts/a.ttf', 'images/b.jpg'],
* the returned object will be: {font: ['fonts/a.ttf'], image: ['images/b.jpg']}
*/
module.exports = function groupFilesByType(assets) {
return groupBy(assets, type => mime.lookup(type).split('/')[0]);
};

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const PbxFile = require('xcode/lib/pbxFile');
/**
* Given xcodeproj and filePath, it creates new file
* from path provided, adds it to the project
* and returns newly created instance of a file
*/
module.exports = function addFileToProject(project, filePath) {
const file = new PbxFile(filePath);
file.uuid = project.generateUuid();
file.fileRef = project.generateUuid();
project.addToPbxFileReferenceSection(file);
return file;
};

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given an array of xcodeproj libraries and pbxFile,
* it appends it to that group
*
* Important: That function mutates `libraries` and it's not pure.
* It's mainly due to limitations of `xcode` library.
*/
module.exports = function addProjectToLibraries(libraries, file) {
return libraries.children.push({
value: file.fileRef,
comment: file.basename,
});
};

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const createGroupWithMessage = require('./createGroupWithMessage');
module.exports = function addSharedLibraries(project, libraries) {
if (!libraries.length) {
return;
}
// Create a Frameworks group if necessary.
createGroupWithMessage(project, 'Frameworks');
const target = project.getFirstTarget().uuid;
for (var name of libraries) {
project.addFramework(name, { target });
}
};

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const mapHeaderSearchPaths = require('./mapHeaderSearchPaths');
module.exports = function addToHeaderSearchPaths(project, path) {
mapHeaderSearchPaths(project, searchPaths => searchPaths.concat(path));
};

View File

@@ -0,0 +1,6 @@
const isInstalledIOS = require('../isInstalled');
const isInstalledPods = require('../../pods/isInstalled');
module.exports = function isInstalled(projectConfig, name, dependencyConfig) {
return isInstalledIOS(projectConfig, dependencyConfig) || isInstalledPods(projectConfig, dependencyConfig);
};

View File

@@ -0,0 +1,16 @@
const registerDependencyIOS = require('../registerNativeModule');
const registerDependencyPods = require('../../pods/registerNativeModule');
module.exports = function registerNativeModule(
name,
dependencyConfig,
params,
projectConfig
) {
if (projectConfig.podfile && dependencyConfig.podspec) {
registerDependencyPods(name, dependencyConfig, projectConfig);
}
else {
registerDependencyIOS(dependencyConfig, projectConfig);
}
};

View File

@@ -0,0 +1,22 @@
const compact = require('lodash').compact;
const isInstalledIOS = require('../isInstalled');
const isInstalledPods = require('../../pods/isInstalled');
const unregisterDependencyIOS = require('../unregisterNativeModule');
const unregisterDependencyPods = require('../../pods/unregisterNativeModule');
module.exports = function unregisterNativeModule(
name,
dependencyConfig,
projectConfig,
otherDependencies
) {
const isIosInstalled = isInstalledIOS(projectConfig, dependencyConfig);
const isPodInstalled = isInstalledPods(projectConfig, dependencyConfig);
if (isIosInstalled) {
const iOSDependencies = compact(otherDependencies.map(d => d.config.ios));
unregisterDependencyIOS(dependencyConfig, projectConfig, iOSDependencies);
}
else if (isPodInstalled) {
unregisterDependencyPods(dependencyConfig, projectConfig);
}
};

View File

@@ -0,0 +1,54 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
const path = require('path');
const xcode = require('xcode');
const log = require('npmlog');
const groupFilesByType = require('../groupFilesByType');
const createGroupWithMessage = require('./createGroupWithMessage');
const getPlist = require('./getPlist');
const writePlist = require('./writePlist');
/**
* This function works in a similar manner to its Android version,
* except it does not copy fonts but creates Xcode Group references
*/
module.exports = function linkAssetsIOS(files, projectConfig) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const assets = groupFilesByType(files);
const plist = getPlist(project, projectConfig.sourceDir);
createGroupWithMessage(project, 'Resources');
function addResourceFile(f) {
return (f || [])
.map(asset =>
project.addResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
)
)
.filter(file => file) // xcode returns false if file is already there
.map(file => file.basename);
}
addResourceFile(assets.image);
const fonts = addResourceFile(assets.font);
const existingFonts = (plist.UIAppFonts || []);
const allFonts = [...existingFonts, ...fonts];
plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
writePlist(project, projectConfig.sourceDir, plist);
};

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const getGroup = require('./getGroup');
const hasGroup = (pbxGroup, name) => pbxGroup.children.find(group => group.comment === name);
/**
* Given project and path of the group, it deeply creates a given group
* making all outer groups if necessary
*
* Returns newly created group
*/
module.exports = function createGroup(project, path) {
return path.split('/').reduce(
(group, name) => {
if (!hasGroup(group, name)) {
const uuid = project.pbxCreateGroup(name, '""');
group.children.push({
value: uuid,
comment: name,
});
}
return project.pbxGroupByName(name);
},
getGroup(project)
);
};

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const log = require('npmlog');
const createGroup = require('./createGroup');
const getGroup = require('./getGroup');
/**
* Given project and path of the group, it checks if a group exists at that path,
* and deeply creates a group for that path if its does not already exist.
*
* Returns the existing or newly created group
*/
module.exports = function createGroupWithMessage(project, path) {
var group = getGroup(project, path);
if (!group) {
group = createGroup(project, path);
log.warn(
'ERRGROUP',
`Group '${path}' does not exist in your Xcode project. We have created it automatically for you.`
);
}
return group;
};

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Gets build property from the main target build section
*
* It differs from the project.getBuildProperty exposed by xcode in the way that:
* - it only checks for build property in the main target `Debug` section
* - `xcode` library iterates over all build sections and because it misses
* an early return when property is found, it will return undefined/wrong value
* when there's another build section typically after the one you want to access
* without the property defined (e.g. CocoaPods sections appended to project
* miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765
*/
module.exports = function getBuildProperty(project, prop) {
const target = project.getFirstTarget().firstTarget;
const config = project.pbxXCConfigurationList()[target.buildConfigurationList];
const buildSection = project.pbxXCBuildConfigurationSection()[config.buildConfigurations[0].value];
return buildSection.buildSettings[prop];
};

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const getFirstProject = (project) => project.getFirstProject().firstProject;
const findGroup = (group, name) => group.children.find(group => group.comment === name);
/**
* Returns group from .xcodeproj if one exists, null otherwise
*
* Unlike node-xcode `pbxGroupByName` - it does not return `first-matching`
* group if multiple groups with the same name exist
*
* If path is not provided, it returns top-level group
*/
module.exports = function getGroup(project, path) {
const firstProject = getFirstProject(project);
var group = project.getPBXGroupByKey(firstProject.mainGroup);
if (!path) {
return group;
}
for (var name of path.split('/')) {
var foundGroup = findGroup(group, name);
if (foundGroup) {
group = project.getPBXGroupByKey(foundGroup.value);
} else {
group = null;
break;
}
}
return group;
};

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
const union = require('lodash').union;
const last = require('lodash').last;
/**
* Given an array of directories, it returns the one that contains
* all the other directories in a given array inside it.
*
* Example:
* Given an array of directories: ['/Users/Kureev/a', '/Users/Kureev/b']
* the returned folder is `/Users/Kureev`
*
* Check `getHeaderSearchPath.spec.js` for more use-cases.
*/
const getOuterDirectory = (directories) =>
directories.reduce((topDir, currentDir) => {
const currentFolders = currentDir.split(path.sep);
const topMostFolders = topDir.split(path.sep);
if (currentFolders.length === topMostFolders.length
&& last(currentFolders) !== last(topMostFolders)) {
return currentFolders.slice(0, -1).join(path.sep);
}
return currentFolders.length < topMostFolders.length
? currentDir
: topDir;
});
/**
* Given an array of headers it returns search path so Xcode can resolve
* headers when referenced like below:
* ```
* #import "CodePush.h"
* ```
* If all files are located in one directory (directories.length === 1),
* we simply return a relative path to that location.
*
* Otherwise, we loop through them all to find the outer one that contains
* all the headers inside. That location is then returned with /** appended at
* the end so Xcode marks that location as `recursive` and will look inside
* every folder of it to locate correct headers.
*/
module.exports = function getHeaderSearchPath(sourceDir, headers) {
const directories = union(
headers.map(path.dirname)
);
return directories.length === 1
? `"$(SRCROOT)${path.sep}${path.relative(sourceDir, directories[0])}"`
: `"$(SRCROOT)${path.sep}${path.relative(sourceDir, getOuterDirectory(directories))}/**"`;
};

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const glob = require('glob');
const path = require('path');
const GLOB_EXCLUDE_PATTERN = ['node_modules/**', 'Pods/**', 'Examples/**', 'examples/**'];
/**
* Given folder, it returns an array of all header files
* inside it, ignoring node_modules and examples
*/
module.exports = function getHeadersInFolder(folder) {
return glob
.sync('**/*.h', {
cwd: folder,
nodir: true,
ignore: GLOB_EXCLUDE_PATTERN,
})
.map(file => path.join(folder, file));
};

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const plistParser = require('plist');
const getPlistPath = require('./getPlistPath');
const fs = require('fs');
/**
* Returns Info.plist located in the iOS project
*
* Returns `null` if INFOPLIST_FILE is not specified.
*/
module.exports = function getPlist(project, sourceDir) {
const plistPath = getPlistPath(project, sourceDir);
if (!plistPath || !fs.existsSync(plistPath)) {
return null;
}
return plistParser.parse(
fs.readFileSync(plistPath, 'utf-8')
);
};

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
const getBuildProperty = require('./getBuildProperty');
module.exports = function getPlistPath(project, sourceDir) {
const plistFile = getBuildProperty(project, 'INFOPLIST_FILE');
if (!plistFile) {
return null;
}
return path.join(
sourceDir,
plistFile.replace(/"/g, '').replace('$(SRCROOT)', '')
);
};

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given xcodeproj it returns list of products ending with
* .a extension, so that we know what elements add to target
* project static library
*/
module.exports = function getProducts(project) {
return project
.pbxGroupByName('Products')
.children
.map(c => c.comment)
.filter(c => c.indexOf('.a') > -1);
};

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given xcodeproj it returns list of targets
*/
module.exports = function getTargets(project) {
let targets = project.getFirstProject().firstProject.targets;
let nativeTargetSection = project.pbxNativeTargetSection();
return targets.map(function(target) {
let key = target.value;
let configurationListId = project.pbxNativeTargetSection()[key].buildConfigurationList;
let configurationList = project.pbxXCConfigurationList()[configurationListId];
let buildConfigurationId = configurationList.buildConfigurations[0].value;
let buildConfiguration = project.pbxXCBuildConfigurationSection()[buildConfigurationId];
return {
uuid: key,
target: nativeTargetSection[key],
name: nativeTargetSection[key].productReference_comment,
isTVOS: (buildConfiguration.buildSettings.SDKROOT && (buildConfiguration.buildSettings.SDKROOT.indexOf('appletv') !== -1)) || false
};
});
};

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given an array of libraries already imported and packageName that will be
* added, returns true or false depending on whether the library is already linked
* or not
*/
module.exports = function hasLibraryImported(libraries, packageName) {
return libraries.children
.filter(library => library.comment === packageName)
.length > 0;
};

View File

@@ -0,0 +1,9 @@
module.exports = function() {
return {
isInstalled: require('./common/isInstalled'),
register: require('./common/registerNativeModule'),
unregister: require('./common/unregisterNativeModule'),
copyAssets: require('./copyAssets'),
unlinkAssets: require('./unlinkAssets')
};
};

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const xcode = require('xcode');
const getGroup = require('./getGroup');
const hasLibraryImported = require('./hasLibraryImported');
/**
* Returns true if `xcodeproj` specified by dependencyConfig is present
* in a top level `libraryFolder`
*/
module.exports = function isInstalled(projectConfig, dependencyConfig) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const libraries = getGroup(project, projectConfig.libraryFolder);
if (!libraries) {
return false;
}
return hasLibraryImported(libraries, dependencyConfig.projectName);
};

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given Xcode project and path, iterate over all build configurations
* and execute func with HEADER_SEARCH_PATHS from current section
*
* We cannot use builtin addToHeaderSearchPaths method since react-native init does not
* use $(TARGET_NAME) for PRODUCT_NAME, but sets it manually so that method will skip
* that target.
*
* To workaround that issue and make it more bullet-proof for different names,
* we iterate over all configurations and look for `lc++` linker flag to detect
* React Native target.
*
* Important: That function mutates `buildSettings` and it's not pure thus you should
* not rely on its return value
*/
const defaultHeaderPaths = ['"$(inherited)"'];
module.exports = function headerSearchPathIter(project, func) {
const config = project.pbxXCBuildConfigurationSection();
Object
.keys(config)
.filter(ref => ref.indexOf('_comment') === -1)
.forEach(ref => {
const buildSettings = config[ref].buildSettings;
const shouldVisitBuildSettings = (
Array.isArray(buildSettings.OTHER_LDFLAGS) ?
buildSettings.OTHER_LDFLAGS :
[]
)
.indexOf('"-lc++"') >= 0;
if (shouldVisitBuildSettings) {
const searchPaths = buildSettings.HEADER_SEARCH_PATHS ?
[].concat(buildSettings.HEADER_SEARCH_PATHS) :
defaultHeaderPaths;
buildSettings.HEADER_SEARCH_PATHS = func(searchPaths);
}
});
};

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const xcode = require('xcode');
const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const addToHeaderSearchPaths = require('./addToHeaderSearchPaths');
const getHeadersInFolder = require('./getHeadersInFolder');
const getHeaderSearchPath = require('./getHeaderSearchPath');
const getProducts = require('./getProducts');
const getTargets = require('./getTargets');
const createGroupWithMessage = require('./createGroupWithMessage');
const addFileToProject = require('./addFileToProject');
const addProjectToLibraries = require('./addProjectToLibraries');
const addSharedLibraries = require('./addSharedLibraries');
const isEmpty = require('lodash').isEmpty;
const getGroup = require('./getGroup');
/**
* Register native module IOS adds given dependency to project by adding
* its xcodeproj to project libraries as well as attaching static library
* to the first target (the main one)
*
* If library is already linked, this action is a no-op.
*/
module.exports = function registerNativeModuleIOS(dependencyConfig, projectConfig) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const dependencyProject = xcode.project(dependencyConfig.pbxprojPath).parseSync();
const libraries = createGroupWithMessage(project, projectConfig.libraryFolder);
const file = addFileToProject(
project,
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
);
const targets = getTargets(project);
addProjectToLibraries(libraries, file);
getTargets(dependencyProject).forEach(product => {
var i;
if (!product.isTVOS) {
for (i = 0; i < targets.length; i++) {
if (!targets[i].isTVOS) {
project.addStaticLibrary(product.name, {
target: targets[i].uuid
});
}
}
}
if (product.isTVOS) {
for (i = 0; i < targets.length; i++) {
if (targets[i].isTVOS) {
project.addStaticLibrary(product.name, {
target: targets[i].uuid
});
}
}
}
});
addSharedLibraries(project, dependencyConfig.sharedLibraries);
const headers = getHeadersInFolder(dependencyConfig.folder);
if (!isEmpty(headers)) {
addToHeaderSearchPaths(
project,
getHeaderSearchPath(projectConfig.sourceDir, headers)
);
}
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
};

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const mapHeaderSearchPaths = require('./mapHeaderSearchPaths');
/**
* Given Xcode project and absolute path, it makes sure there are no headers referring to it
*/
module.exports = function addToHeaderSearchPaths(project, path) {
mapHeaderSearchPaths(project,
searchPaths => searchPaths.filter(searchPath => searchPath !== path)
);
};

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* For all files that are created and referenced from another `.xcodeproj` -
* a new PBXItemContainerProxy is created that contains `containerPortal` value
* which equals to xcodeproj file.uuid from PBXFileReference section.
*/
module.exports = function removeFromPbxItemContainerProxySection(project, file) {
const section = project.hash.project.objects.PBXContainerItemProxy;
for (var key of Object.keys(section)) {
if (section[key].containerPortal === file.uuid) {
delete section[key];
}
}
return;
};

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Every file added to the project from another project is attached to
* `PBXItemContainerProxy` through `PBXReferenceProxy`.
*/
module.exports = function removeFromPbxReferenceProxySection(project, file) {
const section = project.hash.project.objects.PBXReferenceProxy;
for (var key of Object.keys(section)) {
if (section[key].path === file.basename) {
delete section[key];
}
}
return;
};

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* For each file (.xcodeproj), there's an entry in `projectReferences` created
* that has two entries - `ProjectRef` - reference to a file.uuid and
* `ProductGroup` - uuid of a Products group.
*
* When projectReference is found - it's deleted and the removed value is returned
* so that ProductGroup in PBXGroup section can be removed as well.
*
* Otherwise returns null
*/
module.exports = function removeFromProjectReferences(project, file) {
const firstProject = project.getFirstProject().firstProject;
const projectRef = firstProject.projectReferences.find(item => item.ProjectRef === file.uuid);
if (!projectRef) {
return null;
}
firstProject.projectReferences.splice(
firstProject.projectReferences.indexOf(projectRef),
1
);
return projectRef;
};

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const PbxFile = require('xcode/lib/pbxFile');
const removeFromPbxReferenceProxySection = require('./removeFromPbxReferenceProxySection');
/**
* Removes file from static libraries
*
* Similar to `node-xcode` addStaticLibrary
*/
module.exports = function removeFromStaticLibraries(project, path, opts) {
const file = new PbxFile(path);
file.target = opts ? opts.target : undefined;
project.removeFromPbxFileReferenceSection(file);
project.removeFromPbxBuildFileSection(file);
project.removeFromPbxFrameworksBuildPhase(file);
project.removeFromLibrarySearchPaths(file);
removeFromPbxReferenceProxySection(project, file);
return file;
};

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = function removeProductGroup(project, productGroupId) {
const section = project.hash.project.objects.PBXGroup;
for (var key of Object.keys(section)) {
if (key === productGroupId) {
delete section[key];
}
}
return;
};

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Given an array of xcodeproj libraries and pbxFile,
* it removes it from that group by comparing basenames
*
* Important: That function mutates `libraries` and it's not pure.
* It's mainly due to limitations of `xcode` library.
*/
module.exports = function removeProjectFromLibraries(libraries, file) {
libraries.children = libraries.children.filter(library =>
library.comment !== file.basename
);
};

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const PbxFile = require('xcode/lib/pbxFile');
const removeFromPbxItemContainerProxySection = require('./removeFromPbxItemContainerProxySection');
const removeFromProjectReferences = require('./removeFromProjectReferences');
const removeProductGroup = require('./removeProductGroup');
/**
* Given xcodeproj and filePath, it creates new file
* from path provided and removes it. That operation is required since
* underlying method requires PbxFile instance to be passed (it does not
* have to have uuid or fileRef defined since it will do equality check
* by path)
*
* Returns removed file (that one will have UUID)
*/
module.exports = function removeProjectFromProject(project, filePath) {
const file = project.removeFromPbxFileReferenceSection(new PbxFile(filePath));
const projectRef = removeFromProjectReferences(project, file);
if (projectRef) {
removeProductGroup(project, projectRef.ProductGroup);
}
removeFromPbxItemContainerProxySection(project, file);
return file;
};

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = function removeSharedLibraries(project, libraries) {
if (!libraries.length) {
return;
}
const target = project.getFirstTarget().uuid;
for (var name of libraries) {
project.removeFramework(name, { target });
}
};

View File

@@ -0,0 +1,63 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs-extra');
const path = require('path');
const xcode = require('xcode');
const log = require('npmlog');
const groupFilesByType = require('../groupFilesByType');
const getPlist = require('./getPlist');
const writePlist = require('./writePlist');
const difference = require('lodash').difference;
/**
* Unlinks assets from iOS project. Removes references for fonts from `Info.plist`
* fonts provided by application and from `Resources` group
*/
module.exports = function unlinkAssetsIOS(files, projectConfig) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const assets = groupFilesByType(files);
const plist = getPlist(project, projectConfig.sourceDir);
if (!plist) {
return log.error(
'ERRPLIST',
'Could not locate Info.plist file. Check if your project has \'INFOPLIST_FILE\' set properly'
);
}
if (!project.pbxGroupByName('Resources')) {
return log.error(
'ERRGROUP',
'Group \'Resources\' does not exist in your Xcode project. There is nothing to unlink.'
);
}
const removeResourceFile = function (f) {
(f || [])
.map(asset =>
project.removeResourceFile(
path.relative(projectConfig.sourceDir, asset),
{ target: project.getFirstTarget().uuid }
)
)
.map(file => file.basename);
};
removeResourceFile(assets.image);
const fonts = removeResourceFile(assets.font);
plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts);
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
writePlist(project, projectConfig.sourceDir, plist);
};

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const xcode = require('xcode');
const path = require('path');
const fs = require('fs');
const difference = require('lodash').difference;
const isEmpty = require('lodash').isEmpty;
const getGroup = require('./getGroup');
const getProducts = require('./getProducts');
const getTargets = require('./getTargets');
const getHeadersInFolder = require('./getHeadersInFolder');
const getHeaderSearchPath = require('./getHeaderSearchPath');
const removeProjectFromProject = require('./removeProjectFromProject');
const removeProjectFromLibraries = require('./removeProjectFromLibraries');
const removeFromStaticLibraries = require('./removeFromStaticLibraries');
const removeFromHeaderSearchPaths = require('./removeFromHeaderSearchPaths');
const removeSharedLibraries = require('./removeSharedLibraries');
/**
* Unregister native module IOS
*
* If library is already unlinked, this action is a no-op.
*/
module.exports = function unregisterNativeModule(dependencyConfig, projectConfig, iOSDependencies) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const dependencyProject = xcode.project(dependencyConfig.pbxprojPath).parseSync();
const libraries = getGroup(project, projectConfig.libraryFolder);
const file = removeProjectFromProject(
project,
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
);
removeProjectFromLibraries(libraries, file);
getTargets(dependencyProject).forEach(target => {
removeFromStaticLibraries(project, target.name, {
target: project.getFirstTarget().uuid,
});
});
const sharedLibraries = difference(
dependencyConfig.sharedLibraries,
iOSDependencies.reduce(
(libs, dependency) => libs.concat(dependency.sharedLibraries),
projectConfig.sharedLibraries
)
);
removeSharedLibraries(project, sharedLibraries);
const headers = getHeadersInFolder(dependencyConfig.folder);
if (!isEmpty(headers)) {
removeFromHeaderSearchPaths(
project,
getHeaderSearchPath(projectConfig.sourceDir, headers)
);
}
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
};

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const plistParser = require('plist');
const getPlistPath = require('./getPlistPath');
const fs = require('fs');
/**
* Writes to Info.plist located in the iOS project
*
* Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
*/
module.exports = function writePlist(project, sourceDir, plist) {
const plistPath = getPlistPath(project, sourceDir);
if (!plistPath) {
return null;
}
// We start with an offset of -1, because Xcode maintains a custom
// indentation of the plist.
// Ref: https://github.com/facebook/react-native/issues/11668
return fs.writeFileSync(
plistPath,
plistParser.build(plist, { indent: '\t', offset: -1 }) + '\n'
);
};

162
node_modules/react-native/local-cli/link/link.js generated vendored Normal file
View File

@@ -0,0 +1,162 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const log = require('npmlog');
const path = require('path');
const uniqBy = require('lodash').uniqBy;
const flatten = require('lodash').flatten;
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const chalk = require('chalk');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const isEmpty = require('lodash').isEmpty;
const promiseWaterfall = require('./promiseWaterfall');
const getProjectDependencies = require('./getProjectDependencies');
const getDependencyConfig = require('./getDependencyConfig');
const pollParams = require('./pollParams');
const commandStub = require('./commandStub');
const promisify = require('./promisify');
const findReactNativeScripts = require('../util/findReactNativeScripts');
import type {RNConfig} from '../core';
log.heading = 'rnpm-link';
const dedupeAssets = (assets) => uniqBy(assets, asset => path.basename(asset));
const linkDependency = async (platforms, project, dependency) => {
const params = await pollParams(dependency.config.params);
Object.keys(platforms || {})
.forEach(platform => {
if (!project[platform] || !dependency.config[platform]) {
return null;
}
const linkConfig = platforms[platform] && platforms[platform].linkConfig && platforms[platform].linkConfig();
if (!linkConfig || !linkConfig.isInstalled || !linkConfig.register) {
return null;
}
const isInstalled = linkConfig.isInstalled(project[platform], dependency.name, dependency.config[platform]);
if (isInstalled) {
log.info(chalk.grey(`Platform '${platform}' module ${dependency.name} is already linked`));
return null;
}
log.info(`Linking ${dependency.name} ${platform} dependency`);
linkConfig.register(
dependency.name,
dependency.config[platform],
params,
project[platform]
);
log.info(`Platform '${platform}' module ${dependency.name} has been successfully linked`);
});
};
const linkAssets = (platforms, project, assets) => {
if (isEmpty(assets)) {
return;
}
Object.keys(platforms || {})
.forEach(platform => {
const linkConfig = platforms[platform] && platforms[platform].linkConfig && platforms[platform].linkConfig();
if (!linkConfig || !linkConfig.copyAssets) {
return;
}
log.info(`Linking assets to ${platform} project`);
linkConfig.copyAssets(assets, project[platform]);
});
log.info('Assets have been successfully linked to your project');
};
/**
* Updates project and links all dependencies to it.
*
* @param args If optional argument [packageName] is provided,
* only that package is processed.
* @param config CLI config, see local-cli/core/index.js
*/
function link(args: Array<string>, config: RNConfig) {
let project;
let platforms;
try {
project = config.getProjectConfig();
platforms = config.getPlatformConfig();
} catch (err) {
log.error(
'ERRPACKAGEJSON',
'No package found. Are you sure this is a React Native project?'
);
return Promise.reject(err);
}
const hasProjectConfig = Object.keys(platforms).reduce((acc, key) => acc || key in project, false);
if (!hasProjectConfig && findReactNativeScripts()) {
throw new Error(
'`react-native link` can not be used in Create React Native App projects. ' +
'If you need to include a library that relies on custom native code, ' +
'you might have to eject first. ' +
'See https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md ' +
'for more information.'
);
}
let packageName = args[0];
// Check if install package by specific version (eg. package@latest)
if (packageName !== undefined) {
packageName = packageName.split('@')[0];
}
const dependencies = getDependencyConfig(
config,
packageName ? [packageName] : getProjectDependencies()
);
const assets = dedupeAssets(dependencies.reduce(
(acc, dependency) => acc.concat(dependency.config.assets),
project.assets
));
const tasks = flatten(dependencies.map(dependency => [
() => promisify(dependency.config.commands.prelink || commandStub),
() => linkDependency(platforms, project, dependency),
() => promisify(dependency.config.commands.postlink || commandStub),
]));
tasks.push(() => linkAssets(platforms, project, assets));
return promiseWaterfall(tasks).catch(err => {
log.error(
`Something went wrong while linking. Error: ${err.message} \n` +
'Please file an issue here: https://github.com/facebook/react-native/issues'
);
throw err;
});
}
module.exports = {
func: link,
description: 'links all native dependencies (updates native build files)',
name: 'link [packageName]',
};

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = function addPodEntry(podLines, linesToAddEntry, podName, nodePath) {
const newEntry = `pod '${podName}', :path => '../node_modules/${nodePath}'\n`;
if (!linesToAddEntry) {
return;
} else if (Array.isArray(linesToAddEntry)) {
linesToAddEntry.map(({ line, indentation }, idx) =>
podLines.splice(line + idx, 0, getLineToAdd(newEntry, indentation))
);
} else {
const { line, indentation } = linesToAddEntry;
podLines.splice(line, 0, getLineToAdd(newEntry, indentation));
}
};
function getLineToAdd(newEntry, indentation) {
const spaces = Array(indentation + 1).join(' ');
return spaces + newEntry;
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = function findLineToAddPod(podLines, firstTargetLine) {
// match line with new target: target 'project_name' do (most likely target inside podfile main target)
const nextTarget = /target (\'|\")\w+(\'|\") do/g;
// match line that has only 'end' (if we don't catch new target or function, this would mean this is end of current target)
const endOfCurrentTarget = /^\s*end\s*$/g;
// match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target
const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g;
for (let i = firstTargetLine, len = podLines.length; i < len; i++) {
const matchNextConstruct = podLines[i].match(nextTarget) || podLines[i].match(functionDefinition);
const matchEnd = podLines[i].match(endOfCurrentTarget);
if (matchNextConstruct || matchEnd) {
const firstNonSpaceCharacter = podLines[i].search(/\S/);
return {
indentation: firstNonSpaceCharacter + (matchEnd ? 2 : 0),
line: i
};
}
}
return null;
};

Some files were not shown because too many files have changed in this diff Show More