mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Added react-native new-library command
This commit is contained in:
47
local-cli/generator-utils.js
Normal file
47
local-cli/generator-utils.js
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
function copyAndReplace(src, dest, replacements) {
|
||||
if (fs.lstatSync(src).isDirectory()) {
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest);
|
||||
}
|
||||
} else {
|
||||
var content = fs.readFileSync(src, 'utf8');
|
||||
Object.keys(replacements).forEach(function(regex) {
|
||||
content = content.replace(new RegExp(regex, 'g'), replacements[regex]);
|
||||
});
|
||||
fs.writeFileSync(dest, content);
|
||||
}
|
||||
}
|
||||
|
||||
function walk(current) {
|
||||
if (!fs.lstatSync(current).isDirectory()) {
|
||||
return [current];
|
||||
}
|
||||
|
||||
var files = fs.readdirSync(current).map(function(child) {
|
||||
child = path.join(current, child);
|
||||
return walk(child);
|
||||
});
|
||||
return [].concat.apply([current], files);
|
||||
}
|
||||
|
||||
function validatePackageName(name) {
|
||||
if (!name.match(/^[$A-Z_][0-9A-Z_$]*$/i)) {
|
||||
console.error(
|
||||
'"%s" is not a valid name for a project. Please use a valid identifier ' +
|
||||
'name (alphanumeric).',
|
||||
name
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
copyAndReplace: copyAndReplace,
|
||||
walk: walk,
|
||||
validatePackageName: validatePackageName
|
||||
};
|
||||
Reference in New Issue
Block a user