Skip to content

Commit

Permalink
Added linting and editorconfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Brown committed Jan 24, 2017
1 parent cfdc1f2 commit 42ba77d
Show file tree
Hide file tree
Showing 8 changed files with 902 additions and 95 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
@@ -0,0 +1,21 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab

[*.js]
indent_size = 4

[*.json]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2
10 changes: 10 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
'extends': [
'keystone-react',
],
'rules': {
'react/jsx-indent': 0,
'react/jsx-no-bind': 'off',
'react/jsx-boolean-value': 'off',
}
};
40 changes: 22 additions & 18 deletions index.js
@@ -1,22 +1,26 @@
#! /usr/bin/env node
const glob = require('glob');

const yargs = require("yargs");
const yargs = require('yargs');

var argv = yargs.usage("$0 command")
.command(
"fix-libraries",
"add any missing build configurations to all xcode projects in node_modules",
yargs => {
require('./src/fix-libraries')();
})
.command(
"fix-script",
"replace the react native ios bundler with our scheme aware one",
yargs => {
require('./src/fix-script')();
})
.demand(1, "must provide a valid command")
.help("h")
.alias("h", "help")
.argv
yargs
.usage('$0 command')
.command('all', 'run all bundled commands', yargs => {
const files = glob.sync('src/*.js');

for (const file of files) {
if (file.endsWith('utilities.js')) continue;

require(file)();
}
})
.command('fix-libraries', 'add any missing build configurations to all xcode projects in node_modules', yargs => {
require('./src/fix-libraries')();
})
.command('fix-script', 'replace the react native ios bundler with our scheme aware one', yargs => {
require('./src/fix-script')();
})
.demand(1, 'must provide a valid command')
.help('h')
.alias('h', 'help')
.argv;
9 changes: 8 additions & 1 deletion package.json
Expand Up @@ -7,7 +7,8 @@
"react-native-schemes-manager": "index.js"
},
"scripts": {
"postinstall": "react-native-schemes-manager fix-script && react-native-schemes-manager fix-libraries"
"lint": "eslint .",
"lint-fix": "eslint . --fix"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,5 +36,11 @@
"uuid": "^3.0.1",
"xcode": "^0.9.1",
"yargs": "^6.6.0"
},
"devDependencies": {
"eslint": "^3.11.0",
"eslint-config-keystone": "^3.0.0",
"eslint-config-keystone-react": "^1.0.0",
"eslint-plugin-react": "^6.9.0"
}
}
4 changes: 2 additions & 2 deletions src/fix-libraries.js
Expand Up @@ -63,11 +63,11 @@ function updateProject (project) {
return changed;
}

module.exports = function findAndFix() {
module.exports = function findAndFix () {
// Find all of the pbxproj files we care about.
const pattern = './node_modules/**/*.xcodeproj/project.pbxproj';

utilities.updateProjectsMatchingGlob(pattern, (err, project) => {
return updateProject(project);
});
}
};
42 changes: 21 additions & 21 deletions src/fix-script.js
Expand Up @@ -5,38 +5,38 @@ const utilities = require('./utilities');
function updateProject (project) {
console.log(path.dirname(path.relative(process.cwd(), project.filepath)));

const section = project.hash.project.objects['PBXShellScriptBuildPhase'];
const section = project.hash.project.objects.PBXShellScriptBuildPhase;

for (const key of Object.keys(section)) {
for (const key of Object.keys(section)) {
// Look for the React native script.
const step = section[key];
const step = section[key];

if (step && step.shellScript && step.shellScript.indexOf('react-native-xcode.sh') >= 0) {
if (step && step.shellScript && step.shellScript.indexOf('react-native-xcode.sh') >= 0) {
// Found it!
// Need to add our actual mappings to the project.
const configurations = utilities.getMappings().join('|');

const newScript = `"export NODE_BINARY=node\\nexport DEVELOPMENT_BUILD_CONFIGURATIONS=\\"${configurations}|Debug\\"\\n../node_modules/react-native-schemes-manager/lib/react-native-xcode.sh"`;
const configurations = utilities.getMappings().join('|');

if (step.shellScript === newScript) {
const newScript = `"export NODE_BINARY=node\\nexport DEVELOPMENT_BUILD_CONFIGURATIONS=\\"${configurations}|Debug\\"\\n../node_modules/react-native-schemes-manager/lib/react-native-xcode.sh"`;

if (step.shellScript === newScript) {
// It's already up to date.
console.log(' - [skipped] already done');
return false;
} else {
step.shellScript = newScript;

console.log(` ✔ [fixed]`);
return true;
}
}
}
console.log(' - [skipped] already done');
return false;
} else {
step.shellScript = newScript;

console.log(` ✔ [fixed]`);
return true;
}
}
}
}

module.exports = function findAndFix() {
module.exports = function findAndFix () {
// Find all of the pbxproj files we care about.
const pattern = './ios/*.xcodeproj/project.pbxproj';
const pattern = './ios/*.xcodeproj/project.pbxproj';

utilities.updateProjectsMatchingGlob(pattern, (err, project) => {
return updateProject(project);
});
}
};
94 changes: 47 additions & 47 deletions src/utilities.js
Expand Up @@ -5,65 +5,65 @@ const uuid = require('uuid');
const xcode = require('xcode');

module.exports = {
getClosestLikelyReactNativeProjectPath () {
let currentPath = process.cwd();
let nextPath;
getClosestLikelyReactNativeProjectPath () {
let currentPath = process.cwd();
let nextPath;

console.log(`searching in ${currentPath}`);
console.log(`searching in ${currentPath}`);

const pattern = 'ios/*.xcodeproj/project.pbxproj'
let files = glob.sync(path.join(currentPath, pattern));
const pattern = 'ios/*.xcodeproj/project.pbxproj';
let files = glob.sync(path.join(currentPath, pattern));

while (files.length === 0) {
nextPath = path.resolve(currentPath, '..');
while (files.length === 0) {
nextPath = path.resolve(currentPath, '..');

if (nextPath === currentPath) {
throw new Error('Could not locate a likely path.');
}
if (nextPath === currentPath) {
throw new Error('Could not locate a likely path.');
}

currentPath = nextPath;
currentPath = nextPath;

files = glob.sync(path.join(currentPath, pattern));
}
files = glob.sync(path.join(currentPath, pattern));
}

if (files.length > 0) {
return currentPath;
} else {
throw new Error('Could not locate a likely path.');
}
},
updateProjectsMatchingGlob (pattern, callback) {
if (files.length > 0) {
return currentPath;
} else {
throw new Error('Could not locate a likely path.');
}
},
updateProjectsMatchingGlob (pattern, callback) {
// Find all of the pbxproj files we care about.
const project = this.getClosestLikelyReactNativeProjectPath();
if (!project) return callback(new Error('Unable to find project path.'));
const project = this.getClosestLikelyReactNativeProjectPath();
if (!project) return callback(new Error('Unable to find project path.'));

glob(path.join(project, pattern), (err, files) => {
if (err) throw err;
glob(path.join(project, pattern), (err, files) => {
if (err) throw err;

// Go through each project.
for (const projectPath of files) {
const project = xcode.project(projectPath);
project.parseSync();
for (const projectPath of files) {
const project = xcode.project(projectPath);
project.parseSync();

// And fix it.
if (callback(null, project)) {
console.log('Saving project file.');
fs.writeFileSync(projectPath, project.writeSync());
}
}
});
},
generateUuid () {
return uuid.v4().replace(/-/g, '').substr(0, 24).toUpperCase();
},
getMappings () {
const project = this.getClosestLikelyReactNativeProjectPath();
const package = require(path.join(project, 'package.json'));
if (callback(null, project)) {
console.log('Saving project file.');
fs.writeFileSync(projectPath, project.writeSync());
}
}
});
},
generateUuid () {
return uuid.v4().replace(/-/g, '').substr(0, 24).toUpperCase();
},
getMappings () {
const project = this.getClosestLikelyReactNativeProjectPath();
const packageJson = require(path.join(project, 'package.json'));

if (!package.schemes || !package.schemes.Debug) {
throw new Error('Please configure schemes on your project. For more information, see https://github.com/Thinkmill/react-native-schemes-manager/blob/master/README.md');
}
if (!packageJson.xcodeSchemes || !packageJson.xcodeSchemes.Debug) {
throw new Error('Please configure schemes on your project. For more information, see https://github.com/Thinkmill/react-native-schemes-manager/blob/master/README.md');
}

return package.schemes.Debug;
},
}
return packageJson.xcodeSchemes.Debug;
},
};

0 comments on commit 42ba77d

Please sign in to comment.