forked from ryanbahniuk/scss-to-json
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jair Medeiros
committed
Apr 21, 2022
1 parent
73b9d0b
commit 2a33d7a
Showing
9 changed files
with
211 additions
and
197 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
|
||
var fs = require("fs"); | ||
var path = require("path"); | ||
var minimist = require("minimist"); | ||
|
||
var scssJson = require("../main"); | ||
var opts = minimist(process.argv.slice(2), { | ||
alias: { | ||
h: "help", | ||
v: "version", | ||
d: "dependencies", | ||
s: "scope", | ||
}, | ||
}); | ||
|
||
var file = opts._[0]; | ||
|
||
if (opts.version) { | ||
console.log(require("../package.json").version); | ||
} else if (!file || file === "help" || opts.help) { | ||
fs.createReadStream(path.resolve(__dirname, "usage.txt")) | ||
.pipe(process.stdout) | ||
.on("close", function () { | ||
throw Error("Error reading usage.txt"); | ||
}); | ||
} else { | ||
var options = {}; | ||
|
||
if (opts.dependencies) { | ||
options.dependencies = opts.dependencies | ||
.split(",") | ||
.map(function (dependency) { | ||
return { path: path.resolve(dependency) }; | ||
}); | ||
} | ||
|
||
if (opts.scope) { | ||
options.scope = opts.scope; | ||
} | ||
|
||
var result = JSON.stringify(scssJson(file, options), null, 2); | ||
console.log(result); | ||
} |
This file was deleted.
Oops, something went wrong.
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,4 +1,4 @@ | ||
Usage: node scss2json [options] [<file>] | ||
Usage: node scss-json [options] [<file>] | ||
|
||
Options: | ||
|
||
|
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,10 +1,10 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
var Processor = require('./src/processor'); | ||
var Processor = require("./src/processor"); | ||
|
||
function scss2Json(path, options) { | ||
function scssJson(path, options) { | ||
var processor = new Processor(path, options); | ||
return processor.object; | ||
} | ||
|
||
module.exports = scss2Json; | ||
module.exports = scssJson; |
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
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,74 +1,77 @@ | ||
/* eslint-env node, mocha */ | ||
'use strict'; | ||
"use strict"; | ||
|
||
var assert = require('assert'); | ||
var path = require('path'); | ||
var spawn = require('cross-spawn'); | ||
var cli = path.join(__dirname, '../bin/scss2json'); | ||
var PKG_VERSION = require('../package.json').version; | ||
var assert = require("assert"); | ||
var path = require("path"); | ||
var spawn = require("cross-spawn"); | ||
var cli = path.join(__dirname, "../bin/scss-json"); | ||
var PKG_VERSION = require("../package.json").version; | ||
|
||
function callAndExpectNoErrors(args, cb) { | ||
var bin = spawn(cli, args); | ||
bin.stdout.setEncoding('utf8'); | ||
bin.stderr.setEncoding('utf8'); | ||
bin.stdout.setEncoding("utf8"); | ||
bin.stderr.setEncoding("utf8"); | ||
|
||
bin.stderr.once('data', function(data) { | ||
bin.stderr.once("data", function (data) { | ||
throw new Error(data); | ||
}); | ||
|
||
bin.stdout.once('data', cb); | ||
bin.stdout.once("data", cb); | ||
} | ||
|
||
describe('cli', function() { | ||
it('returns help', function(done) { | ||
callAndExpectNoErrors(['-h'], function(data) { | ||
assert.equal(data.indexOf('Usage:'), 0); | ||
describe("cli", function () { | ||
it("returns help", function (done) { | ||
callAndExpectNoErrors(["-h"], function (data) { | ||
assert.equal(data.indexOf("Usage:"), 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('returns version number', function(done) { | ||
callAndExpectNoErrors(['-v'], function(data) { | ||
it("returns version number", function (done) { | ||
callAndExpectNoErrors(["-v"], function (data) { | ||
assert.equal(data.trim(), PKG_VERSION); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('compiles', function(done) { | ||
var file = path.resolve(__dirname, 'scss', 'test.scss'); | ||
callAndExpectNoErrors([file], function(data) { | ||
assert.ok(data.indexOf('$icon-font-size-lg') >= 0); | ||
it("compiles", function (done) { | ||
var file = path.resolve(__dirname, "scss", "test.scss"); | ||
callAndExpectNoErrors([file], function (data) { | ||
assert.ok(data.indexOf("$icon-font-size-lg") >= 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('compiles with scoping', function(done) { | ||
var file = path.resolve(__dirname, 'scss', 'scoped.scss'); | ||
callAndExpectNoErrors([file, '--scope', '%scoped'], function(data) { | ||
assert.ok(data.indexOf('$global-with-function') >= 0); | ||
it("compiles with scoping", function (done) { | ||
var file = path.resolve(__dirname, "scss", "scoped.scss"); | ||
callAndExpectNoErrors([file, "--scope", "%scoped"], function (data) { | ||
assert.ok(data.indexOf("$global-with-function") >= 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('compiles with dependencies', function(done) { | ||
var file = path.resolve(__dirname, 'scss', 'has-dependents.scss'); | ||
var dependency = path.resolve(__dirname, 'scss', 'dependency.scss'); | ||
it("compiles with dependencies", function (done) { | ||
var file = path.resolve(__dirname, "scss", "has-dependents.scss"); | ||
var dependency = path.resolve(__dirname, "scss", "dependency.scss"); | ||
var expectedLines = [ | ||
'{', | ||
"{", | ||
' "$first": "#00f",', | ||
' "$global-variable": "#f00",', | ||
' "$references": "#00f",', | ||
' "$scss-function-with-variable": "#e60000"', | ||
'}' | ||
"}", | ||
]; | ||
|
||
callAndExpectNoErrors([file, '--dependencies', dependency], function(data) { | ||
var lines = data.trim().replace(/\r\n/g, '\n').split('\n'); | ||
assert.equal(lines.length, expectedLines.length); | ||
lines.forEach(function(l, i) { | ||
assert.equal(l, expectedLines[i]); | ||
}); | ||
done(); | ||
}); | ||
callAndExpectNoErrors( | ||
[file, "--dependencies", dependency], | ||
function (data) { | ||
var lines = data.trim().replace(/\r\n/g, "\n").split("\n"); | ||
assert.equal(lines.length, expectedLines.length); | ||
lines.forEach(function (l, i) { | ||
assert.equal(l, expectedLines[i]); | ||
}); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); |
Oops, something went wrong.