Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadYounes committed Dec 10, 2020
1 parent bd4c099 commit cd0e5cd
Show file tree
Hide file tree
Showing 31 changed files with 3,618 additions and 2,390 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
- "14"
- "12"
- "10"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.0.0 - 10 Dec. 2020
* Upgrade to [POSTCSS] 8.
* Dropped **Node.js 6.x, 8.x, 11.x, and 13.x** versions.

## 2.6.2 - 01 Dec. 2020
* Set input source to same file in raw directive ([#180](https://github.com/MohammadYounes/rtlcss/issues/180)).

Expand Down Expand Up @@ -222,3 +226,5 @@ Options and config settings have changed. However, you need not to worry about y

### 0.1.1 - 4 Mar. 2014
* Initial commit.

[POSTCSS]: https://postcss.org/
50 changes: 25 additions & 25 deletions bin/rtlcss.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node

var path = require('path')
var fs = require('fs')
var chalk = require('chalk')
var mkdirp = require('mkdirp')
var postcss = require('postcss')
var rtlcss = require('../lib/rtlcss')
var configLoader = require('../lib/config-loader')
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')
const mkdirp = require('mkdirp')
const postcss = require('postcss')
const rtlcss = require('../lib/rtlcss')
const configLoader = require('../lib/config-loader')

var input, output, directory, ext, config, currentErrorcode, arg
var args = process.argv.slice(2)
var shouldBreak = false
let input, output, directory, ext, config, currentErrorcode, arg
const args = process.argv.slice(2)
let shouldBreak = false

process.on('exit', function () { process.reallyExit(currentErrorcode) })

Expand All @@ -30,7 +30,7 @@ function printHelp () {
console.log('Usage: rtlcss [option option=parameter ...] [source] [destination]')
console.log('')
/*eslint-disable*/
var options = [
const options = [
'Option ' , 'Description ',
'--------------', '----------------------------------------------',
'-h,--help' , 'Print help (this message) and exit.',
Expand All @@ -41,8 +41,8 @@ function printHelp () {
'-e,--ext' , 'Used with -d option to set the output files extension.\n\t\t Default: ".rtl.css".',
'-s,--silent' , 'Silent mode, no warnings or errors are printed.'
]
/*eslint-enable */
for (var x = 0; x < options.length; x++) {
/* eslint-enable */
for (let x = 0; x < options.length; x++) {
console.log(options[x++], '\t', options[x])
}
console.log('')
Expand Down Expand Up @@ -114,7 +114,7 @@ if (!shouldBreak) {
}
if (!config && input !== '-') {
try {
var cwd = input
let cwd = input
if (directory !== true) {
cwd = path.dirname(input)
}
Expand All @@ -136,13 +136,13 @@ if (!shouldBreak) {
}
}

var processCSSFile = function (e, data, outputName) {
const processCSSFile = function (e, data, outputName) {
if (e) {
printError('rtlcss: ' + e.message)
return
}
var result
var opt = { map: false }
let result
const opt = { map: false }
if (input !== '-') {
opt.from = input
opt.to = output
Expand All @@ -158,7 +158,7 @@ if (!shouldBreak) {
}

if (output) {
var savePath = outputName
let savePath = outputName
if (directory !== true) {
savePath = output
}
Expand All @@ -172,14 +172,14 @@ if (!shouldBreak) {
}
}

var walk = function (dir, done) {
const walk = function (dir, done) {
fs.readdir(dir, function (error, list) {
if (error) {
return done(error)
}
var i = 0
let i = 0
;(function next () {
var file = list[i++]
let file = list[i++]
if (!file) {
return done(null)
}
Expand All @@ -199,15 +199,15 @@ if (!shouldBreak) {
// process only *.css
if (/\.(css)$/.test(file)) {
// compute output directory
var relativePath = path.relative(input, file).split(path.sep)
const relativePath = path.relative(input, file).split(path.sep)
relativePath.pop()
relativePath.push(path.basename(file).replace('.css', ext || '.rtl.css'))

// set rtl file name
var rtlFile = path.join(output, relativePath.join(path.sep))
const rtlFile = path.join(output, relativePath.join(path.sep))

// create output directory if it does not exist
var dirName = path.dirname(rtlFile)
const dirName = path.dirname(rtlFile)
if (!fs.existsSync(dirName)) {
mkdirp.sync(dirName)
}
Expand Down Expand Up @@ -258,7 +258,7 @@ if (!shouldBreak) {
process.stdin.resume()
process.stdin.setEncoding('utf8')

var buffer = ''
let buffer = ''
process.stdin.on('data', function (data) {
buffer += data
})
Expand Down
28 changes: 14 additions & 14 deletions lib/config-loader.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global process */
'use strict'
var fs = require('fs')
var path = require('path')
var findup = require('@choojs/findup')
var stripJSONComments = require('strip-json-comments')
var config = {}
var configSources = ['package.json', '.rtlcssrc', '.rtlcss.json']
const fs = require('fs')
const path = require('path')
const findup = require('find-up')
const stripJSONComments = require('strip-json-comments')
let config = {}
const configSources = ['package.json', '.rtlcssrc', '.rtlcss.json']

module.exports.load = function (configFilePath, cwd, overrides) {
if (configFilePath) {
Expand All @@ -15,11 +15,11 @@ module.exports.load = function (configFilePath, cwd, overrides) {
fs.readFileSync(configFilePath, 'utf-8').trim())), overrides)
}

var directory = cwd || process.cwd()
const directory = cwd || process.cwd()
config = loadConfig(directory)
if (!config) {
var evns = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME]
for (var x = 0; x < evns.length; x++) {
const evns = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME]
for (let x = 0; x < evns.length; x++) {
if (!evns[x]) {
continue
}
Expand All @@ -37,17 +37,17 @@ module.exports.load = function (configFilePath, cwd, overrides) {
}

function loadConfig (dir) {
for (var x = 0; x < configSources.length; x++) {
var found
var source = configSources[x]
for (let x = 0; x < configSources.length; x++) {
let found
const source = configSources[x]
try {
found = findup.sync(dir, source)
} catch (e) {
continue
}

if (found) {
var configFilePath = path.normalize(path.join(found, source))
const configFilePath = path.normalize(path.join(found, source))
try {
config = JSON.parse(
stripJSONComments(
Expand All @@ -69,7 +69,7 @@ function loadConfig (dir) {

function override (to, from) {
if (to && from) {
for (var p in from) {
for (const p in from) {
if (typeof to[p] === 'object') {
override(to[p], from[p])
} else {
Expand Down
36 changes: 18 additions & 18 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
var options
var config = {}
var corePlugin = require('./plugin.js')
let options
const config = {}
const corePlugin = require('./plugin.js')

function optionOrDefault (option, def) {
return option in options ? options[option] : def
Expand All @@ -25,9 +25,9 @@ function main (opts, plugins, hooks) {

// default strings map
if (Array.isArray(config.stringMap)) {
var hasLeftRight, hasLtrRtl
for (var x = 0; x < config.stringMap.length; x++) {
var map = config.stringMap[x]
let hasLeftRight, hasLtrRtl
for (let x = 0; x < config.stringMap.length; x++) {
const map = config.stringMap[x]
if (hasLeftRight && hasLtrRtl) {
break
} else if (map.name === 'left-right') {
Expand All @@ -38,22 +38,22 @@ function main (opts, plugins, hooks) {
}
if (!hasLeftRight) {
config.stringMap.push({
'name': 'left-right',
'priority': 100,
'exclusive': false,
'search': ['left', 'Left', 'LEFT'],
'replace': ['right', 'Right', 'RIGHT'],
'options': { 'scope': '*', 'ignoreCase': false }
name: 'left-right',
priority: 100,
exclusive: false,
search: ['left', 'Left', 'LEFT'],
replace: ['right', 'Right', 'RIGHT'],
options: { scope: '*', ignoreCase: false }
})
}
if (!hasLtrRtl) {
config.stringMap.push({
'name': 'ltr-rtl',
'priority': 100,
'exclusive': false,
'search': ['ltr', 'Ltr', 'LTR'],
'replace': ['rtl', 'Rtl', 'RTL'],
'options': { 'scope': '*', 'ignoreCase': false }
name: 'ltr-rtl',
priority: 100,
exclusive: false,
search: ['ltr', 'Ltr', 'LTR'],
replace: ['rtl', 'Rtl', 'RTL'],
options: { scope: '*', ignoreCase: false }
})
}
config.stringMap.sort(function (a, b) { return a.priority - b.priority })
Expand Down
22 changes: 11 additions & 11 deletions lib/directive-parser.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module.exports = function (comment) {
var pos = 0
var value = comment.text
var match = value.match(/^\s*!?\s*rtl:/)
var meta
let pos = 0
let value = comment.text
const match = value.match(/^\s*!?\s*rtl:/)
let meta

if (match) {
meta = {
'source': comment,
'name': '',
'param': '',
'begin': true,
'end': true,
'blacklist': false,
'preserve': false
source: comment,
name: '',
param: '',
begin: true,
end: true,
blacklist: false,
preserve: false
}
value = value.slice(match[0].length)
pos = value.indexOf(':')
Expand Down
Loading

0 comments on commit cd0e5cd

Please sign in to comment.