mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 05:34:15 +00:00
Introduce default config
Reviewed By: frantic Differential Revision: D2561344 fb-gh-sync-id: 651b8a199069f78e1ace2897ba4c0352aab7e3ea
This commit is contained in:
parent
8e7cfcd053
commit
c6c97cbd9d
@ -11,6 +11,7 @@
|
||||
var bundle = require('../private-cli/src/bundle/bundle');
|
||||
var childProcess = require('child_process');
|
||||
var Config = require('../private-cli/src/util/Config');
|
||||
var defaultConfig = require('./default.config');
|
||||
var fs = require('fs');
|
||||
var generate = require('../private-cli/src/generate/generate');
|
||||
var library = require('../private-cli/src/library/library');
|
||||
@ -56,7 +57,7 @@ function run() {
|
||||
return;
|
||||
}
|
||||
|
||||
command[0](args, Config.get(__dirname)).done();
|
||||
command[0](args, Config.get(__dirname, defaultConfig)).done();
|
||||
}
|
||||
|
||||
function generateWrapper(args, config) {
|
||||
|
44
local-cli/default.config.js
Normal file
44
local-cli/default.config.js
Normal file
@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var blacklist = require('../packager/blacklist');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* Default configuration for the CLI.
|
||||
*
|
||||
* If you need to override any of this functions do so by defining the file
|
||||
* `rn-cli.config.js` on the root of your project with the functions you need
|
||||
* to tweak.
|
||||
*/
|
||||
var config = {
|
||||
getProjectRoots() {
|
||||
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli$/)) {
|
||||
// packager is running from node_modules of another project
|
||||
return [path.resolve(__dirname, '../../..')];
|
||||
} else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) {
|
||||
// packager is running from node_modules of another project
|
||||
return [path.resolve(__dirname, '../../..')];
|
||||
} else {
|
||||
return [path.resolve(__dirname, '..')];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Specify where to look for assets that are referenced using
|
||||
* `image!<image_name>`. Asset directories for images referenced using
|
||||
* `./<image.extension>` don't require any entry in here.
|
||||
*/
|
||||
getAssetRoots() {
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a regular expression for modules that should be ignored by the
|
||||
* packager on a given platform.
|
||||
*/
|
||||
getBlacklistRE(platform) {
|
||||
return blacklist(platform);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
@ -48,10 +48,6 @@ module.exports = yeoman.generators.NamedBase.extend({
|
||||
{ 'Libraries\/react-native\/react-native-interface.js' : 'node_modules/react-native/Libraries/react-native/react-native-interface.js' }
|
||||
);
|
||||
|
||||
this.fs.copy(
|
||||
this.templatePath('rn-cli.config.js'),
|
||||
this.destinationPath('rn-cli.config.js')
|
||||
);
|
||||
this.fs.copy(
|
||||
this.templatePath('_gitignore'),
|
||||
this.destinationPath('.gitignore')
|
||||
|
@ -1,20 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var blacklist = require('./node_modules/react-native/packager/blacklist');
|
||||
|
||||
var config = {
|
||||
getProjectRoots() {
|
||||
return [__dirname];
|
||||
},
|
||||
|
||||
getAssetRoots() {
|
||||
// speficy where to look for assets
|
||||
return [];
|
||||
},
|
||||
|
||||
getBlacklistRE(platform) {
|
||||
return blacklist(platform);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
@ -16,25 +16,33 @@ let cachedConfig = null;
|
||||
|
||||
/**
|
||||
* Module capable of getting the configuration that should be used for
|
||||
* the `rn-cli`. The configuration file is a JS file named `rn-cli.conf.js`.
|
||||
* the `rn-cli`. The configuration file is a JS file named `rn-cli.config.js`.
|
||||
* It has to be on any parent directory of the cli.
|
||||
*
|
||||
* The function will return all the default configuration functions overriden
|
||||
* by those found on `rn-cli.config.js`, if any. If no default config is
|
||||
* provided and no configuration can be found in the directory hierarchy an
|
||||
* error will be thrown.
|
||||
*/
|
||||
const Config = {
|
||||
get(pwd) {
|
||||
get(pwd, defaultConfig) {
|
||||
if (cachedConfig) {
|
||||
return cachedConfig;
|
||||
}
|
||||
|
||||
const parentDir = findParentDirectory(pwd, RN_CLI_CONFIG);
|
||||
|
||||
if (!parentDir) {
|
||||
if (!parentDir && !defaultConfig) {
|
||||
throw new Error(
|
||||
'Can\'t find "rn-cli.config.js" file in any parent folder of "' +
|
||||
__dirname + '"'
|
||||
);
|
||||
}
|
||||
|
||||
cachedConfig = require(path.join(parentDir, RN_CLI_CONFIG));
|
||||
const config = parentDir
|
||||
? require(path.join(parentDir, RN_CLI_CONFIG))
|
||||
: {};
|
||||
|
||||
cachedConfig = Object.assign({}, defaultConfig, config);
|
||||
return cachedConfig;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user