-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverted "Fixed running command-line interface on Unix because of CRL…
…F line ending" This reverts commit 60c0aac.
- Loading branch information
Anantachai Saothong (Manta)
committed
Apr 27, 2017
1 parent
e216fe1
commit e780139
Showing
7 changed files
with
1,397 additions
and
1,397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
class StringBuffer { | ||
constructor() { | ||
this.buffer = [] | ||
} | ||
|
||
append(text) { | ||
if (arguments.length > 1) { | ||
throw new Error('Found too many arguments of', Array.prototype.slice.call(arguments)) | ||
|
||
} else if (typeof text === 'object' && text !== null) { | ||
throw new Error('Found a non-string argument of', text) | ||
|
||
} else if (text !== '') { | ||
this.buffer.push(text) | ||
} | ||
|
||
return this | ||
} | ||
|
||
remove(text) { | ||
if (text === undefined) { | ||
this.buffer.pop() | ||
|
||
} else if (this.buffer.length > 0) { | ||
const last = this.buffer[this.buffer.length - 1] | ||
if (last === text) { | ||
this.buffer.pop() | ||
|
||
} else if (last.endsWith(text)) { | ||
this.buffer[this.buffer.length - 1] = last.substring(0, last.length - text.length) | ||
} | ||
} | ||
|
||
return this | ||
} | ||
|
||
toString() { | ||
return this.buffer.join('') | ||
} | ||
} | ||
|
||
class StringBuffer { | ||
constructor() { | ||
this.buffer = [] | ||
} | ||
|
||
append(text) { | ||
if (arguments.length > 1) { | ||
throw new Error('Found too many arguments of', Array.prototype.slice.call(arguments)) | ||
|
||
} else if (typeof text === 'object' && text !== null) { | ||
throw new Error('Found a non-string argument of', text) | ||
|
||
} else if (text !== '') { | ||
this.buffer.push(text) | ||
} | ||
|
||
return this | ||
} | ||
|
||
remove(text) { | ||
if (text === undefined) { | ||
this.buffer.pop() | ||
|
||
} else if (this.buffer.length > 0) { | ||
const last = this.buffer[this.buffer.length - 1] | ||
if (last === text) { | ||
this.buffer.pop() | ||
|
||
} else if (last.endsWith(text)) { | ||
this.buffer[this.buffer.length - 1] = last.substring(0, last.length - text.length) | ||
} | ||
} | ||
|
||
return this | ||
} | ||
|
||
toString() { | ||
return this.buffer.join('') | ||
} | ||
} | ||
|
||
module.exports = StringBuffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
#!/usr/bin/env node | ||
|
||
const ps = require('process') | ||
const fs = require('fs') | ||
const pt = require('path') | ||
const glob = require('glob') | ||
const _ = require('lodash') | ||
const format = require('./format') | ||
|
||
let inputFiles = [] | ||
let optionFilePath = '' | ||
let replaceOriginal = false | ||
let outputDirectory = '' | ||
let printVersion = false | ||
|
||
let paramIndex = -1 | ||
const paramArray = ps.argv.slice(2) | ||
while (++paramIndex < paramArray.length) { | ||
const param = paramArray[paramIndex] | ||
|
||
if (param === '--options' || param === '-p') { | ||
optionFilePath = paramArray[paramIndex + 1] | ||
paramIndex++ | ||
|
||
} else if (param === '--replace' || param === '-r') { | ||
replaceOriginal = true | ||
|
||
} else if (param === '--outDir' || param === '-o') { | ||
outputDirectory = paramArray[paramIndex + 1] | ||
paramIndex++ | ||
|
||
} else if (param === '--version' || param === '-v') { | ||
printVersion = true | ||
|
||
} else { | ||
inputFiles.push(param) | ||
} | ||
} | ||
|
||
if (printVersion) { | ||
console.log('v' + require('../package.json').version) | ||
|
||
} else if (inputFiles.length === 0) { | ||
throw new Error('No files specified.') | ||
|
||
} else { | ||
let formattingOptions = null | ||
if (optionFilePath) { | ||
formattingOptions = JSON.parse(fs.readFileSync(optionFilePath, 'utf8')) | ||
} | ||
|
||
const outputFiles = _.chain(inputFiles) | ||
.map(path => glob.sync(path)) | ||
.flatten() | ||
.map(path => Object.assign({ path }, format(fs.readFileSync(path, 'utf8'), formattingOptions))) | ||
.value() | ||
|
||
if (outputDirectory) { | ||
if (fs.existsSync(pt.resolve(outputDirectory)) === false) { | ||
fs.mkdirSync(pt.resolve(outputDirectory)) | ||
} | ||
outputFiles.forEach(file => { | ||
fs.writeFileSync(pt.resolve(outputDirectory, pt.basename(file.path)), file.text) | ||
}) | ||
|
||
} else if (replaceOriginal) { | ||
outputFiles.forEach(file => { | ||
fs.writeFileSync(file.path, file.text) | ||
}) | ||
|
||
} else { | ||
outputFiles.forEach(file => { | ||
console.log(file.text) | ||
}) | ||
} | ||
|
||
if (outputFiles.some(file => file.warnings.length > 0)) { | ||
outputFiles.forEach(file => { | ||
file.warnings.forEach(warn => { | ||
console.log(`WARN: ${warn.message} in ${file.path}`) | ||
if (warn.data !== undefined) { | ||
console.log(JSON.stringify(warn.data, null, '\t')) | ||
} | ||
}) | ||
}) | ||
const warningCount = _.sumBy(outputFiles, file => file.warnings.length) | ||
console.log(`Done with ${warningCount} warning${warningCount === 1 ? '' : 's'}.`) | ||
|
||
} else { | ||
console.log('Done without warnings.') | ||
} | ||
#!/usr/bin/env node | ||
|
||
const ps = require('process') | ||
const fs = require('fs') | ||
const pt = require('path') | ||
const glob = require('glob') | ||
const _ = require('lodash') | ||
const format = require('./format') | ||
|
||
let inputFiles = [] | ||
let optionFilePath = '' | ||
let replaceOriginal = false | ||
let outputDirectory = '' | ||
let printVersion = false | ||
|
||
let paramIndex = -1 | ||
const paramArray = ps.argv.slice(2) | ||
while (++paramIndex < paramArray.length) { | ||
const param = paramArray[paramIndex] | ||
|
||
if (param === '--options' || param === '-p') { | ||
optionFilePath = paramArray[paramIndex + 1] | ||
paramIndex++ | ||
|
||
} else if (param === '--replace' || param === '-r') { | ||
replaceOriginal = true | ||
|
||
} else if (param === '--outDir' || param === '-o') { | ||
outputDirectory = paramArray[paramIndex + 1] | ||
paramIndex++ | ||
|
||
} else if (param === '--version' || param === '-v') { | ||
printVersion = true | ||
|
||
} else { | ||
inputFiles.push(param) | ||
} | ||
} | ||
|
||
if (printVersion) { | ||
console.log('v' + require('../package.json').version) | ||
|
||
} else if (inputFiles.length === 0) { | ||
throw new Error('No files specified.') | ||
|
||
} else { | ||
let formattingOptions = null | ||
if (optionFilePath) { | ||
formattingOptions = JSON.parse(fs.readFileSync(optionFilePath, 'utf8')) | ||
} | ||
|
||
const outputFiles = _.chain(inputFiles) | ||
.map(path => glob.sync(path)) | ||
.flatten() | ||
.map(path => Object.assign({ path }, format(fs.readFileSync(path, 'utf8'), formattingOptions))) | ||
.value() | ||
|
||
if (outputDirectory) { | ||
if (fs.existsSync(pt.resolve(outputDirectory)) === false) { | ||
fs.mkdirSync(pt.resolve(outputDirectory)) | ||
} | ||
outputFiles.forEach(file => { | ||
fs.writeFileSync(pt.resolve(outputDirectory, pt.basename(file.path)), file.text) | ||
}) | ||
|
||
} else if (replaceOriginal) { | ||
outputFiles.forEach(file => { | ||
fs.writeFileSync(file.path, file.text) | ||
}) | ||
|
||
} else { | ||
outputFiles.forEach(file => { | ||
console.log(file.text) | ||
}) | ||
} | ||
|
||
if (outputFiles.some(file => file.warnings.length > 0)) { | ||
outputFiles.forEach(file => { | ||
file.warnings.forEach(warn => { | ||
console.log(`WARN: ${warn.message} in ${file.path}`) | ||
if (warn.data !== undefined) { | ||
console.log(JSON.stringify(warn.data, null, '\t')) | ||
} | ||
}) | ||
}) | ||
const warningCount = _.sumBy(outputFiles, file => file.warnings.length) | ||
console.log(`Done with ${warningCount} warning${warningCount === 1 ? '' : 's'}.`) | ||
|
||
} else { | ||
console.log('Done without warnings.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
const _ = require('lodash') | ||
|
||
const createAdapterForAlwaysNeverFalse = name => value => (value === 'always' || value === 'never') ? [name, value === 'always'] : [] | ||
|
||
const stylintOptionMap = { | ||
'blocks': createAdapterForAlwaysNeverFalse('alwaysUseAtBlock'), | ||
'brackets': createAdapterForAlwaysNeverFalse('insertBraces'), | ||
'colons': createAdapterForAlwaysNeverFalse('insertColons'), | ||
'commaSpace': createAdapterForAlwaysNeverFalse('insertSpaceAfterComma'), | ||
'commentSpace': createAdapterForAlwaysNeverFalse('insertSpaceAfterComment'), | ||
'efficient': createAdapterForAlwaysNeverFalse('reduceMarginAndPaddingValues'), | ||
'extendPref': value => ['alwaysUseExtends', value === '@extends'], | ||
'indentPref': value => value > 0 && ['tabStopChar', _.repeat(' ', value)], | ||
'leadingZero': createAdapterForAlwaysNeverFalse('insertLeadingZeroBeforeFraction'), | ||
'parenSpace': createAdapterForAlwaysNeverFalse('insertSpaceInsideParenthesis'), | ||
'quotePref': value => value === 'single' && ['quoteChar', '\''] || value === 'double' && ['quoteChar', '"'], | ||
'semicolons': createAdapterForAlwaysNeverFalse('insertSemicolons'), | ||
'sortOrder': value => ['sortProperties', value], | ||
'zeroUnits': value => value === false ? [] : ['alwaysUseZeroWithoutUnit', value === 'never'], | ||
} | ||
|
||
function createFormattingOptionsFromStylintOptions(stylintOptions = {}) { | ||
return _.chain(stylintOptions) | ||
.omitBy((item, name) => stylintOptionMap[name] === undefined) | ||
.reduce((temp, item, name) => { | ||
const value = _.isObject(item) && item.expect !== undefined ? item.expect : item | ||
|
||
const options = _.chunk(stylintOptionMap[name](value) || [], 2) | ||
options.forEach(pair => { | ||
if (pair[1] !== undefined) { | ||
temp[pair[0]] = pair[1] | ||
} | ||
}) | ||
|
||
return temp | ||
}, {}) | ||
.value() | ||
} | ||
|
||
const _ = require('lodash') | ||
|
||
const createAdapterForAlwaysNeverFalse = name => value => (value === 'always' || value === 'never') ? [name, value === 'always'] : [] | ||
|
||
const stylintOptionMap = { | ||
'blocks': createAdapterForAlwaysNeverFalse('alwaysUseAtBlock'), | ||
'brackets': createAdapterForAlwaysNeverFalse('insertBraces'), | ||
'colons': createAdapterForAlwaysNeverFalse('insertColons'), | ||
'commaSpace': createAdapterForAlwaysNeverFalse('insertSpaceAfterComma'), | ||
'commentSpace': createAdapterForAlwaysNeverFalse('insertSpaceAfterComment'), | ||
'efficient': createAdapterForAlwaysNeverFalse('reduceMarginAndPaddingValues'), | ||
'extendPref': value => ['alwaysUseExtends', value === '@extends'], | ||
'indentPref': value => value > 0 && ['tabStopChar', _.repeat(' ', value)], | ||
'leadingZero': createAdapterForAlwaysNeverFalse('insertLeadingZeroBeforeFraction'), | ||
'parenSpace': createAdapterForAlwaysNeverFalse('insertSpaceInsideParenthesis'), | ||
'quotePref': value => value === 'single' && ['quoteChar', '\''] || value === 'double' && ['quoteChar', '"'], | ||
'semicolons': createAdapterForAlwaysNeverFalse('insertSemicolons'), | ||
'sortOrder': value => ['sortProperties', value], | ||
'zeroUnits': value => value === false ? [] : ['alwaysUseZeroWithoutUnit', value === 'never'], | ||
} | ||
|
||
function createFormattingOptionsFromStylintOptions(stylintOptions = {}) { | ||
return _.chain(stylintOptions) | ||
.omitBy((item, name) => stylintOptionMap[name] === undefined) | ||
.reduce((temp, item, name) => { | ||
const value = _.isObject(item) && item.expect !== undefined ? item.expect : item | ||
|
||
const options = _.chunk(stylintOptionMap[name](value) || [], 2) | ||
options.forEach(pair => { | ||
if (pair[1] !== undefined) { | ||
temp[pair[0]] = pair[1] | ||
} | ||
}) | ||
|
||
return temp | ||
}, {}) | ||
.value() | ||
} | ||
|
||
module.exports = createFormattingOptionsFromStylintOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
{ | ||
"insertColons": true, | ||
"insertSemicolons": true, | ||
"insertBraces": true, | ||
"insertNewLineBetweenGroups": 1, | ||
"insertNewLineBetweenSelectors": false, | ||
"insertNewLineBeforeElse": false, | ||
"insertSpaceBeforeComment": true, | ||
"insertSpaceAfterComment": true, | ||
"insertSpaceAfterComma": true, | ||
"insertSpaceInsideParenthesis": false, | ||
"insertParenthesisAroundIfCondition": true, | ||
"insertLeadingZeroBeforeFraction": true, | ||
"tabStopChar": "\t", | ||
"newLineChar": "\n", | ||
"quoteChar": "'", | ||
"sortProperties": false, | ||
"alwaysUseImport": false, | ||
"alwaysUseNot": false, | ||
"alwaysUseAtBlock": false, | ||
"alwaysUseExtends": false, | ||
"alwaysUseZeroWithoutUnit": false, | ||
"reduceMarginAndPaddingValues": false | ||
{ | ||
"insertColons": true, | ||
"insertSemicolons": true, | ||
"insertBraces": true, | ||
"insertNewLineBetweenGroups": 1, | ||
"insertNewLineBetweenSelectors": false, | ||
"insertNewLineBeforeElse": false, | ||
"insertSpaceBeforeComment": true, | ||
"insertSpaceAfterComment": true, | ||
"insertSpaceAfterComma": true, | ||
"insertSpaceInsideParenthesis": false, | ||
"insertParenthesisAroundIfCondition": true, | ||
"insertLeadingZeroBeforeFraction": true, | ||
"tabStopChar": "\t", | ||
"newLineChar": "\n", | ||
"quoteChar": "'", | ||
"sortProperties": false, | ||
"alwaysUseImport": false, | ||
"alwaysUseNot": false, | ||
"alwaysUseAtBlock": false, | ||
"alwaysUseExtends": false, | ||
"alwaysUseZeroWithoutUnit": false, | ||
"reduceMarginAndPaddingValues": false | ||
} |
Oops, something went wrong.