Git Product home page Git Product logo

sass-export's Introduction

Sass-Export

Sass-export takes SCSS files and export them to a JSON file you can use as data. This is perfect for generating your site documentation.

Build Status Total Downloads Donate via Patreon

Try it online: Playground (demo)

CLI

Install it from NPM

 npm install -g sass-export

Ready to export:

 sass-export scss/config/*.scss -o exported-sass-array.json -a

Here's a sample output

input: _variables.css

  $gray-medium: #757575;
  $base-value: 25px;
  $gray-dark: darken($gray-medium, 5%);
  $logo: url(logo.svg);
  $logo-quotes: url('logo.svg');
  $calculation: $base-value - 12px;
  $multiple-calculations: $base-value - floor(12.5px);

output: exported-sass-array.json

[
  { "name": "$gray-medium", "value": "#757575", "compiledValue": "#757575" },
  { "name": "$base-value", "value": "25px", "compiledValue": "25px" },
  { "name": "$gray-dark", "value": "darken($gray-medium, 5%)", "compiledValue" :"#686868" },
  { "name": "$logo", "value": "url(logo.svg)", "compiledValue": "url(logo.svg)" },
  { "name": "$logo-quotes", "value": "url('logo.svg')", "compiledValue": "url(\"logo.svg\")" },
  { "name": "$calculation", "value": "$base-value - 12px", "compiledValue": "13px" },
  { "name": "$multiple-calculations", "value": "$base-value - floor(12.5px)", "compiledValue": "13px" }
]

Section Groups Annotations

You can easily organize your variables into a Javascript object using sass-export annotations:

input: _annotations.scss

$black: #000;
$slate: #8ca5af;

/**
 * @sass-export-section="brand-colors"
 */
$brand-gray-light: #eceff1;
$brand-gray-medium: #d6d6d6;
$brand-gray: #b0bec5;
//@end-sass-export-section [optional]

/**
 * @sass-export-section="fonts"
 */
$font-size: 16px;
$font-color: $brand-gray-medium;
//@end-sass-export-section

$global-group: #FF0000;

Then we run sass-export:

 sass-export scss/_annotations.scss -o exported-grouped.json

output exported-grouped.json

{
    "variables": [
        { "name": "$black", "value": "#000", "compiledValue": "#000" },
        { "name": "$slate", "value": "#8ca5af", "compiledValue": "#8ca5af" },
        { "name": "$global-group", "value": "#ff0000", "compiledValue": "#ff0000" }
    ],
    "brand-colors": [
        { "name": "$brand-gray-light", "value": "#eceff1", "compiledValue":"#eceff1" },
        { "name": "$brand-gray-medium", "value": "#d6d6d6" ,"compiledValue":"#d6d6d6" },
        { "name": "$brand-gray", "value": "#b0bec5", "compiledValue": "#b0bec5" }
    ],
    "fonts": [
        { "name": "$font-size", "value": "16px", "compiledValue": "16px" },
        { "name": "$font-color", "value": "$brand-gray-medium", "compiledValue":"#d6d6d6" }
    ]
}

Include Paths for @import

In order to support @import we need to include --dependencies parameter with a comma separated list of the folder path to include:

sass-export scss/_fonts.scss -o=exported-dependencies.json  -d "src/sass/config/, src/sass/libs/"

in order to use:

@import "breakpoints";
@import "variables";

$imported-value: $bp-desktop;
$font-size: $global-font-size;

Map support

In case you wanted your sass Maps variable to be an array we included te mapValue property for variables identified as maps.

input: _breakpoints.scss

$breakpoints: (
  small: 767px,
  medium: 992px,
  large: 1200px
);

output: exported-maps.json

{
  "variables": [
    {
      "name": "$breakpoints",
      "value": "(small: 767px,  medium: 992px,  large: 1200px)",
      "mapValue": [
        { "name": "small", "value": "767px", "compiledValue": "767px" },
        { "name": "medium","value": "992px", "compiledValue": "992px" },
        { "name": "large", "value": "1200px", "compiledValue": "1200px" }
      ],
      "compiledValue": "(small:767px,medium:992px,large:1200px)"
    }
}

Mixin/Function support

For mixins and functions we've added a reserved 'mixins' group for it.

input: _mixins.scss

@mixin box($p1, $p2) {
  @content;
}

@function my-function($val) {
}

@mixin z($val: 10px, $p2: '#COFF33') {
  @content;
}

@mixin no-params() {
}

output: exported-mixins.json

{
  "mixins": [
    {
      "name": "box",
      "parameters": [ "$p1", "$p2" ]
    },
    {
      "name": "my-fucntion",
      "parameters": [ "$val" ]
    },
    {
      "name": "z",
      "parameters": [ "$val: 10px", "$p2: '#COFF33'" ]
    },
    {
      "name": "no-params",
      "parameters": []
    }
  ]
}

Import it in your Node App?

import syntax:

 import { exporter } from 'sass-export';

Require syntax:

const exporter = require('sass-export').exporter;

const exporterBuffer = require('sass-export').buffer;

Example

Written using ES5 syntax.

const exporter = require('sass-export').exporter;

//basic options
const options = {
  inputFiles: ['_variables.scss', '_fonts.scss'],
  includePaths: ['libs/'] // don't forget this is the folder path not the files
};

// you can get an object {variables:[], colors: []}
const asObject = exporter(options).getStructured();

console.log(asObject.variables);
console.log(asObject.colors);

// or get an array [{}, {}]
const asArray = exporter(options).getArray();

console.log(asArray)

Usage

Usage: sass-export [inputFiles] [options]

Options Type Description
-o, --output String File path where to save the JSON exported.
-a, --array Boolean If it is present, it will output an array file instead of a object structured.
-d, --dependencies String[] List of dependencies separated by comma, where Sass will try to find the @imports that your inputFiles need to work. Example: "libs/, config/, variables/".
-h, --help Boolean Shows up this help screen.

Other utilities based on this tool

Contributing

Please feel free to submit pull requests or open issues to improve this tool. Also keep checking issues section and grab some items to help!

Check our Contributing page for more information.

License


MIT

Supporting

This is an open source project and completely free to use.

However, the amount of effort needed to maintain and develop new features and products within the Plentycode ecosystem is not sustainable without proper financial backing. If you have the capability, please consider donating using the link below:

Donate via Patreon

sass-export's People

Contributors

chirag-jn avatar civan avatar civanm avatar cmatiello avatar cosmicwebservices avatar daksh avatar davidsmith2 avatar defusion avatar dependabot[bot] avatar g4brym avatar geoemm avatar gopuneet avatar lamextrahop avatar levdbas avatar nickcolley avatar plentycodedev avatar ryuran avatar serges avatar tehjwt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sass-export's Issues

Include Paths for @import doesn't seems to work with Bootstrap

I have a "_variables.scss" with two imports :
@import "~bootstrap/scss/functions"; @import "~bootstrap/scss/variables";

When i run
sass-export src/styles/common/_variables.scss -o src/exported-sass-variables.json -d "node_modules/bootstrap/scss/"

sass-export throw an error :
Error: File to import not found or unreadable: ~bootstrap/scss/functions.

even if I replace the ~ (shortcut to node_modules) by the relative path to node_modules

map.get not working

In sass, there is a module map built in,
@use 'sass:map';

And instead of using map-get or map-keys, it allows to use map.get, map.keys syntax. It would be great if these syntaxes can be supported

Also, nested map support would be awesome,
like $a: ( "a": ("b":red)) should be expected to become { "a": {"b": "red"}}

Wrong conversion of box-shadow with rgba value

Hello,

$map: (
    box-shadow: 0 2px 4px 0 rgba(#222, .08),
);

returns wrong compiled value "compiledValue": "0 2px 4px 0 rgba"

{
  "variables": [
    {
      "name": "$map",
      "value": "( box-shadow: 0 2px 4px 0 rgba(#222, .08), )",
      "mapValue": [
        {
          "name": "box-shadow",
          "value": "0 2px 4px 0 rgba",
          "compiledValue": "0 2px 4px 0 rgba"
        }
      ],
      "compiledValue": "(box-shadow: 0 2px 4px 0 rgba(34, 34, 34, 0.08))"
    }
  ]
}

Is there any workaround for it?

[REQUEST] support map-merge

I'm doing this:

$one: (
  background: #FFF
);

$two: map-merge($one, (
  color: #F00
));

I expect $two to have everything in $one and its additional entry. But the output is just:

{
  "name": "$two",
  "value": "map-merge($one, (color: #F00));",
  "mapValue": [ { "name": "color", "value": "#F00", "compiledValue": "#F00" } ]
}

Nothing from $one is in $two's "mapValue" array.

Suppress parsing errors, or send them to a file?

Is there a way to either discard parse errors or send them to a file with, say, a -e option (similarly to the -o option)?

My use case is that I'm using sass-export in "prebuild" and "preserve" NPM scripts in my package.json:

  "scripts": {
    ...
    "preserve": "sass-export ./src/styles/variables.scss -o ./src/styles/sassvariables.json",
    "serve": "vue-cli-service serve",
    "prebuild": "sass-export ./src/styles/variables.scss -o ./public/assets/sassvariables.json",
    "build": "vue-cli-service build",
    ...
  }

sass-export generates a perfectly find sassvariables.json file for me, but also spits out many parsing errors to the console. While I can safely ignore these messages for my purposes, I don't know of a way to suppress them from the console to clean up the build and serve steps.

New angular version not working any more

After updating from angular 13 to angular 14 we are having trouble with using this with angular material.

One of the material files had this in version 13

@use '../../../cdk/a11y';
@use './list-common';
@use './layout-common';

Which has since been replaced with

@use '@angular/cdk';

@use './list-common';
@use './layout-common';

It always fails on the new cdk import.
I have tried to add that into the include files but nothing seems to work. Below is our options

Original version working with angular 13

var options = {
    inputFiles: ['src/app/css/export_variables.scss'],
    includePaths: ['src/app/css/', 'node_modules/@angular/material', ]
};

What I have tried

var options = {
    inputFiles: ['src/app/css/export_variables.scss'],
    includePaths: ['node_modules/@angular/cdk/', 'src/app/css/', 'node_modules/@angular/material', ]
};

Do you have any idea why the cdk path does not work?

I have tried manually changing it to ../../../cdk in the scss file, which does fix it but obviously cant be used as a solution.

Add the ability to get the json variables as 'object'

Currently when we export using:

sass-export test/scss/_annotations.scss -o exported.json 

You should get this output

We are aiming to have this JSON output:
(this is also related to Issues: #23, #20)

{
    "variables": {
   	"black": { "name": "$black", "value": "#000", "compiledValue": "#000" },
        "slate": { "name": "$slate", "value": "#8ca5af", "compiledValue": "#8ca5af" },
        "other-name": { "name": "$other-name", "value": "#ff0000", "compiledValue": "#ff0000" }
   }
}

For this specifically request we want the variables: [] to be a keyed object variables: {}

Don't forget to update:

  • source code
  • unit tests
  • documentation
  • examples

[REQUEST] Export annoted only

Sometimes you don't want to split your variables file but you neither don't need to export all of them in a json file.

So, it would be nice if we could export only annoted sections/groups.

Exclude annotations

It would be cool if this can have some annotation like:

// @sass-export-exclude-section
 $color1: #cccccc;
 $color2: #aaaaaa;
//@end-sass-export-section 

then this section is ignored when exporting.

[feature] error-logging add file name

add the file name when error is occur;

since I got an error :

Error: Expected expression.
    ╷
127 │ #sass-export-id.deprecations--message{content:"#{}";}
    │                                                ^^
    ╵
  stdin 127:48  root stylesheet
    at Object._newRenderError (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:13231:19)
    at Object._wrapException (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:13059:16)
    at StaticClosure._renderSync (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:13037:18)
    at Object.Primitives_applyFunction (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:1136:30)
    at Object.Function_apply (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:5903:16)
    at _callDartFunctionFast (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:7605:16)
    at Object.renderSync (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass\sass.dart.js:7583:18)
    at Converter.renderPropertyValue (f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass-export\dist\app\converter\converter.js:88:33)
    at f:\Gitrepo\CDT\cdt-fp-component\node_modules\sass-export\dist\app\converter\converter.js:49:50
    at Array.map (<anonymous>) {
  formatted: 'Error: Expected expression.\n' +
    '    ╷\n' +
    '127 │ #sass-export-id.deprecations--message{content:"#{}";}\n' +
    '    │                                                ^^\n' +
    '    ╵\n' +
    '  stdin 127:48  root stylesheet',
  line: 127,
  column: 48,
  file: 'stdin',
  status: 1
}

Rename "globals" to "variables" when the variables are not grouped

We support Grouped section using annotations when the variables not grouped within any group they're added to globals property (example).

we want to group them in variables key:

{
    "variables": [
        { "variable": "$black", "value": "#000", "compiledValue": "#000" },
        { "variable": "$slate", "value": "#8ca5af", "compiledValue": "#8ca5af" },
        { "variable": "$global-group", "value": "#ff0000", "compiledValue": "#ff0000" }
    ],
    "brand-colors": [
        { "variable": "$brand-gray-light", "value": "#eceff1", "compiledValue":"#eceff1" },
        { "variable": "$brand-gray-medium", "value": "#d6d6d6" ,"compiledValue":"#d6d6d6" },
        { "variable": "$brand-gray", "value": "#b0bec5", "compiledValue": "#b0bec5" }
    ],
    "fonts": [
        { "variable": "$font-size", "value": "16px", "compiledValue": "16px" },
        { "variable": "$font-color", "value": "$brand-gray-medium", "compiledValue":"#d6d6d6" }
    ]
}

Don't forget to update:

Rename "variable" to "name"

Currently in the exported json the variable name is called variable please rename it to "name"

{
  "fonts": [
        { "variable": "$font-size", "value": "16px", "compiledValue": "16px" },
        { "variable": "$font-color", "value": "$brand-gray-medium", "compiledValue":"#d6d6d6" }
    ]
}

We want it to be:

{
  "fonts": [
        { "name": "$font-size", "value": "16px", "compiledValue": "16px" },
        { "name": "$font-color", "value": "$brand-gray-medium", "compiledValue":"#d6d6d6" }
    ]
}

Don't forget to update:

Broken exporting of font-family values (values with commas)

sass-export doesn't work with exporting variables that includes commas, like font-family: Arial, Helvetica, sans-serif;. It results with an error:

Error: Only 1 argument allowed, but 3 were passed.
  ┌──> stdin
2 │ #sass-export-id.some-font-family{content:"#{inspect(Arial, Helvetica, sans-serif)}";}
  │                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation
  ╵
  ┌──> sass:meta
1 │ @function inspect($value) {
  │           ━━━━━━━━━━━━━━━ declaration
  ╵
...
formatted: 'Error: Only 1 argument allowed, but 3 were passed.\n' +
    '  ┌──> stdin\n' +
    '2 │ #sass-export-id.some-font-family{content:"#{inspect(Arial, Helvetica, sans-serif)}";}\n' +
    '  │                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invocation\n' +
    '  ╵\n' +
    '  ┌──> sass:meta\n' +
    '1 │ @function inspect($value) {\n' +
    '  │           ━━━━━━━━━━━━━━━ declaration\n' +
    '  ╵\n' +
    '  stdin 2:45  root stylesheet',
  line: 2,
  column: 45,
  file: 'stdin',
  status: 1

Basically it looks like Sass's inspect function doesn't accept values with commas, at least without wrapping them in quotes. This might actually be a resolution for this issue.

Cannot use `map-get` within a map

I'm using maps to configure multiple variables as part of a theming system, and trying to use map-get within a map causes errors with sass-export.

Given the following SASS:

$base: (
    foo: 'value'
);

$target: (
    bar: map-get($base, foo)
);

You get the following error:

Invalid CSS after "...#{map-get($base": expected expression (e.g. 1px, bold), was \'}";}\'

Errors reporting that maps aren't valid CSS values

I have a file with nothing but variables that I'm trying to export. The file compiles to CSS with no errors, but when I try to sass-export the file, I get errors that a couple maps I've defined aren't valid CSS values - even though I've not tried to treat them as CSS values at all.

SASS file

@use "sass:map";

@import "variables.scss";
@import "../node_modules/bootstrap/scss/_functions";
@import "../node_modules/bootstrap/scss/_variables";

$levels: (100: 80%,
          200: 60%,
          300: 40%,
          400: 20%,
          500: 0,
          600: 20%,
          700: 40%,
          800: 60%,
          900: 80%);

 /**
 * @sass-export-section="palette"
 */
$palette: (grays:$grays);

@each $label, $base in $theme-colors {
    $steps: ();
    @each $step, $amount in $levels{
        $adjusted: if($step < 500, tint-color($base,$amount), shade-color($base,$amount));
        $text: color-contrast($adjusted);
        $step-colors:("background": $adjusted, "text": $text);
        $steps: map.merge($steps,($step:$step-colors));
    }
    $palette: map.merge($palette, ($label:$steps));
}
//@end-sass-export-section

Shell command

sass-export scss/_dv-palette-export.scss -o docs-source/data/palette.json -d "scss/"

Errors

Error: (100: 80%, 200: 60%, 300: 40%, 400: 20%, 500: 0, 600: 20%, 700: 40%, 800: 60%, 900: 80%) isn't a valid CSS value.
   ╷
38 │ #sass-export-id.levels{content:"#{(100: 80%, 200: 60%, 300: 40%, 400: 20%, 500: 0, 600: 20%, 700: 40%, 800: 60%, 900: 80%)}";}
   │                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  stdin 38:35  root stylesheet
    at Object.wrapException (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:1246:17)
    at _SerializeVisitor0.visitMap$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:90447:17)
    at SassMap0.accept$1$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:85858:22)
    at SassMap0.accept$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:85861:19)
    at Object.serializeValue0 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:21614:13)
    at _EvaluateVisitor__serialize_closure1.call$0 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:81900:16)
    at _EvaluateVisitor1._evaluate0$_addExceptionSpan$1$2 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80347:23)
    at _EvaluateVisitor1._evaluate0$_addExceptionSpan$2 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80368:19)
    at _EvaluateVisitor1._evaluate0$_serialize$3$quote (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80180:19)
    at _EvaluateVisitor_visitStringExpression_closure1.call$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:81752:75) {
  formatted: "Error: (100: 80%, 200: 60%, 300: 40%, 400: 20%, 500: 0, 600: 20%, 700: 40%, 800: 60%, 900: 80%) isn't a valid CSS value.\n" +
    '   ╷\n' +
    '38 │ #sass-export-id.levels{content:"#{(100: 80%, 200: 60%, 300: 40%, 400: 20%, 500: 0, 600: 20%, 700: 40%, 800: 60%, 900: 80%)}";}\n' +
    '   │                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
    '   ╵\n' +
    '  stdin 38:35  root stylesheet',
  line: 38,
  column: 35,
  file: 'stdin',
  status: 1
}
Error: () isn't a valid CSS value.
   ╷
38 │ #sass-export-id.steps{content:"#{()}";}
   │                                  ^^
   ╵
  stdin 38:34  root stylesheet
    at Object.wrapException (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:1246:17)
    at _SerializeVisitor0.visitList$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:90383:19)
    at SassList0.accept$1$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:85340:22)
    at SassList0.accept$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:85343:19)
    at Object.serializeValue0 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:21614:13)
    at _EvaluateVisitor__serialize_closure1.call$0 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:81900:16)
    at _EvaluateVisitor1._evaluate0$_addExceptionSpan$1$2 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80347:23)
    at _EvaluateVisitor1._evaluate0$_addExceptionSpan$2 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80368:19)
    at _EvaluateVisitor1._evaluate0$_serialize$3$quote (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:80180:19)
    at _EvaluateVisitor_visitStringExpression_closure1.call$1 (/home/myusername/.nvm/versions/node/v17.4.0/lib/node_modules/sass-export/node_modules/sass/sass.dart.js:81752:75) {
  formatted: "Error: () isn't a valid CSS value.\n" +
    '   ╷\n' +
    '38 │ #sass-export-id.steps{content:"#{()}";}\n' +
    '   │                                  ^^\n' +
    '   ╵\n' +
    '  stdin 38:34  root stylesheet',
  line: 38,
  column: 34,
  file: 'stdin',
  status: 1
}

Generated JSON

{
  "variables": [
    {
      "name": "$levels",
      "value": "(100: 80%, 200: 60%, 300: 40%, 400: 20%, 500: 0, 600: 20%, 700: 40%, 800: 60%, 900: 80%)",
      "compiledValue": ""
    }
  ],
  "palette": [
    {
      "name": "$palette",
      "value": "(grays:$grays)",
      "mapValue": [
        {
          "name": "grays",
          "value": "$grays",
          "compiledValue": "(\"100\": #f8f9fa, \"200\": #e9ecef, \"300\": #dee2e6, \"400\": #ced4da, \"500\": #adb5bd, \"600\": #6c757d, \"700\": #495057, \"800\": #343a40, \"900\": #212529)"
        }
      ],
      "compiledValue": "(grays: (\"100\": #f8f9fa, \"200\": #e9ecef, \"300\": #dee2e6, \"400\": #ced4da, \"500\": #adb5bd, \"600\": #6c757d, \"700\": #495057, \"800\": #343a40, \"900\": #212529))"
    },
    {
      "name": "$steps",
      "value": "()",
      "compiledValue": "()"
    }
  ]
}

Possibly related, but you can see that pallete > grays does not have a mapValue element.

Use file name instead of 'variables' as DEFAULT_SECTION

Currently if there are no comments in the SASS/SCSS files for sections, each section gets DEFAULT_SECTION as section name, which is set to variables.

It would be nice to use a file name as the section fallback name.

Thank you!
This tool came very handy in my project to import SASS/SCSS variables into TailwindCSS config.

[REQUEST] Ignore comments & annotations

Commented variables should not be parsed / ignored

Input:

$black: #000;
// $white: #fff;

Output:

{
  "variables": [
    {
      "name": "$black",
      "value": "#000",
      "compiledValue": "#000"
    },
    {
      "name": "$white",
      "value": "#fff",
      "compiledValue": "#fff"
    }
  ]
}

Expected:

{
  "variables": [
    {
      "name": "$black",
      "value": "#000",
      "compiledValue": "#000"
    }
  ]
}

Ignore variables with annotations (analogue to sections).
Proposal:

  • ignore single line: // @sass-export-ignore
  • ignore multiple lines (section):
// @sass-export-ignore="internals"
...
// @end-sass-export-ignore [optional]

RGBA() Comma Bug

hey there
somehow there is a little bug in the parse process when you want to use a sass-map and the rgba-attribut.
the problem is the comma and breaks the code.

$shadows: (
shadow: 0px 2px 30px 0px rgba(0,0,0, 0.5),
shadow--type-alpha: 0px 2px 40px 0px rgba(0,0,0,0.5)
);

i could put in in a variable ... but not really elegant. :)
any suggestions?

thx!

Issue when using comments in Sass Map

Hi,

I've noticed when trying to run the sass-export against our typography variables, I'm getting an error as our Sass maps include comments which give the expected pixel values based on the browsers default font-size.

Example Input:

// Default font-size - 16px
$font-size: (
    small: 0.5rem, // 8px
    medium: 1rem, // 16px
    large: 1.5rem // 24px
);

Output:
Error: Invalid CSS after "...(small: 0.5rem,": expected expression (e.g. 1px, bold), was "// 8pxmedium: 1rem,"

It looks like it's possibly including the comments when parsing the values rather than ignoring them?

It's not a huge deal as I can move the comments to a different location but it would be nice if we could still have them inline.

Thanks for the package, it's been a great help!

A few questions/requets

Hello,

I have the following questions/requests:

  • I need support for Sass syntax (older syntax version).
  • I would like to get the json output as an object instead of an array; using keys instead of array indexes makes it easier to read and use.
  • It's confusing to have the same key "mixins" for both functions and mixins; please consider assigning keys accordingly in the generated json file.
  • Is there any callback that I can use to append some additional data to the generated json file? for instance I might want to add the source file path or the file GitHub repository URL.
  • It would be great if you could provide the option of naming the output keys as any user sees fit; for example I would like to change the following keys:
    • globals -> variables
    • variable -> name
  • Currently, if a mixin or a function doesn't have parentheses it's ignored by the parser; they shouldn't be ignored as it's perfectly normal to have some of them without parameters and parentheses.

I really like you're approach and I think this package is way better than many others out there; it has all the essential elements to make a very useful one.

Thanks for your efforts

[HELP] @include relative file

Hi,

I'm having a little trouble with this.
I have a file in ./src/base/components/css-vars.scss, which has a few variable definitions.
This file ends with @import '../../content/css-vars.scss', with the goal of including the content of ./src/content/css-vars.scss.

Unfortunately this doesn't resolve, so I'm not sure if I'm missing something?

Change CLI to export Object-Structured JSON by default not Array

Currently when we use:

 sass-export test/scss/config/*.scss -o exported.json

the default output is an array (example).

we also have an structured option -s or --structured to export as an object.

 sass-export test/scss/config/*.scss -o exported.json -s
  • We would like to change this behaviour so the default option exports as structured not an array.
  • Also add the option to the CLI for array output. suggested -a --array

Please update:

  • source code
  • unit tests
  • documentation
  • examples

thanks!

Export Mixins and Functions separately

Currently mixins and `functions' are being bundle up in a mixins property.

We need them to have their own property.

mixins: []
functions: []

Don't forget to update:

  • source code
  • unit tests
  • documentation
  • examples

[REQUEST] Support for nested maps

Hello,

I am using sass-export for design-systems to have the sass-variables as "single source of truth" and use the data to render styleguides.

An issue I came across is that nested maps are not supported.
Is it possible to get support? : )

Input:

// @sass-export-section="brandColors"
$color-red: #f00;
$color-green: #0f0;
// @end-sass-export-section

// @sass-export-section="semanticColors"
$color-primary: $color-red;
$color-secondary: $color-green;

$color-black: #000;
$color-white: #fff;
// @end-sass-export-section

$colors: (
    primary: (
        base:   $color-primary,
        light:  lighten($color-primary, 10%),
        dark:   darken($color-primary, 10%)
    ),
    secondary: (
        base:   $color-secondary,
        light:  lighten($color-secondary, 10%),
        dark:   darken($color-secondary, 10%)
    black: (
        base:   $color-black,
        light:  lighten($color-black, 10%)
    ),
    white: (
        base:   $color-white
    )
);

Output:

{
  "variables": [
    {
      "name": "$colors",
      "value": "(primary: (base:   $color-primary,light:  lighten($color-primary, 10%),dark:   darken($color-primary, 10%)),secondary: (base:   $color-secondary,light:  lighten($color-secondary, 10%),dark:   darken($color-secondary, 10%)black: (base:   $color-black,light:  lighten($color-black, 10%)),white: (base:   $color-white))",
      "mapValue": [
        {
          "name": "primary",
          "value": "(base:   $color-primary",
          "compiledValue": ""
        },
        {
          "name": "light",
          "value": "lighten($color-primary",
          "compiledValue": ""
        },
        {
          "name": "dark",
          "value": "darken($color-primary",
          "compiledValue": ""
        },
        {
          "name": "secondary",
          "value": "(base:   $color-secondary",
          "compiledValue": ""
        },
        {
          "name": "light",
          "value": "lighten($color-secondary",
          "compiledValue": ""
        },
        {
          "name": "dark",
          "value": "darken($color-secondary",
          "compiledValue": ""
        },
        {
          "name": "black",
          "value": "(base:   $color-black",
          "compiledValue": ""
        },
        {
          "name": "light",
          "value": "lighten($color-black",
          "compiledValue": ""
        },
        {
          "name": "white",
          "value": "(base:   $color-white",
          "compiledValue": ""
        }
      ],
      "compiledValue": ""
    }
  ],
  "brandColors": [
    {
      "name": "$color-red",
      "value": "#f00",
      "compiledValue": ""
    },
    {
      "name": "$color-green",
      "value": "#0f0",
      "compiledValue": ""
    }
  ],
  "semanticColors": [
    {
      "name": "$color-primary",
      "value": "$color-red",
      "compiledValue": ""
    },
    {
      "name": "$color-secondary",
      "value": "$color-green",
      "compiledValue": ""
    },
    {
      "name": "$color-black",
      "value": "#000",
      "compiledValue": ""
    },
    {
      "name": "$color-white",
      "value": "#fff",
      "compiledValue": ""
    }
  ]
}

Error:

{ Error: unclosed parenthesis
    at Object.module.exports.renderSync (PROJECT\node_modules\node-sass\lib\index.js:439:16)
    at Converter.renderPropertyValue (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:79:33)
    at declaration.mapValue.map (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:44:61)
    at Array.map (native)
    at structuredDeclaration.(anonymous function).map (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:43:42)
    at Array.map (native)
    at groups.forEach (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:39:62)
    at Array.forEach (native)
    at Converter.compileStructure (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:37:16)
    at Converter.getStructured (PROJECT\node_modules\sass-export\dist\app\converter\converter.js:32:38)
  status: 1,
  file: 'stdin',
  line: 60,
  column: 38,
  message: 'unclosed parenthesis',
  formatted: 'Error: unclosed parenthesis\n        on line 60 of stdin\n>> #sass-export-id.nested{content:"#{(one: 1}";}\n   -------------------------------------^\n' }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.