Skip to content

Commit

Permalink
Rename package to 'output-styles-as-sass' (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Sep 3, 2020
1 parent c1bdf0a commit b7151a9
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @figma-export/output-styles-as-scss
# @figma-export/output-styles-as-sass

> Styles Outputter for [@figma-export](https://github.com/marcomontalbano/figma-export) that exports styles to SCSS.
> Styles Outputter for [@figma-export](https://github.com/marcomontalbano/figma-export) that exports styles to SASS and SCSS.
With this outputter you can export all the styles as variables inside a `.scss` or `.sass` file.
With this outputter you can export all the styles as variables inside a `.sass` or `.scss` file.

This is a sample of the output:

Expand All @@ -24,7 +24,7 @@ module.exports = {
fileId: 'RSzpKJcnb6uBRQ3rOfLIyUs5',
onlyFromPages: ['figma-styles'],
outputters: [
require('@figma-export/output-styles-as-scss')({
require('@figma-export/output-styles-as-sass')({
output: './output'
})
]
Expand All @@ -38,7 +38,7 @@ module.exports = {
`getExtension` and `getFilename` are **optional**.

```js
require('@figma-export/output-styles-as-scss')({
require('@figma-export/output-styles-as-sass')({
output: './output',
getExtension: () => 'SCSS',
getFilename: () => '_variables',
Expand All @@ -52,11 +52,11 @@ require('@figma-export/output-styles-as-scss')({
Using npm:

```sh
npm install --save-dev @figma-export/output-styles-as-scss
npm install --save-dev @figma-export/output-styles-as-sass
```

or using yarn:

```sh
yarn add @figma-export/output-styles-as-scss --dev
yarn add @figma-export/output-styles-as-sass --dev
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@figma-export/output-styles-as-scss",
"name": "@figma-export/output-styles-as-sass",
"version": "3.0.0-alpha.1",
"description": "Outputter for @figma-export that exports styles to SASS and SCSS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/marcomontalbano/figma-exporter.git",
"directory": "packages/output-styles-as-scss"
"directory": "packages/output-styles-as-sass"
},
"author": "Marco Montalbano <me@marcomontalbano.com>",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as FigmaExport from '@figma-export/types';
import { writeVariable } from './utils';
import { VariableType } from './types';
import { Extension } from './types';

import fs = require('fs');
import path = require('path');
import makeDir = require('make-dir');

type Options = {
output: string;
getExtension?: () => VariableType;
getExtension?: () => Extension;
getFilename?: () => string;
}

Expand Down
1 change: 1 addition & 0 deletions packages/output-styles-as-sass/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Extension = 'SASS' | 'SCSS';
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { writeVariable } from './utils';
describe('utils', () => {
describe('writeVariable', () => {
describe('SCSS', () => {
const variableType = 'SCSS';
const extension = 'SCSS';

it('should be able to print-out simple variable', () => {
const text = writeVariable(
'This is a comment',
'variable-name', '#fff',
variableType,
extension,
);

expect(text).to.eql(
Expand All @@ -25,15 +25,15 @@ describe('utils', () => {
});

it('should be able to print-out simple variable with an empty comment', () => {
const text = writeVariable('', 'variable-name', '#fff', variableType);
const text = writeVariable('', 'variable-name', '#fff', extension);
expect(text).to.eql('\n\n$variable-name: #fff;\n');
});

it('should be able to print-out a comment in multiline', () => {
const text = writeVariable(
'This is a comment\nin two lines',
'variable-name', '#fff',
variableType,
extension,
);

expect(text).to.eql(
Expand All @@ -51,7 +51,7 @@ describe('utils', () => {
const text = writeVariable(
'This is a comment\nin two lines',
'variable-name', '(\n"color-1": #fff,\n"color-2": #000\n)',
variableType,
extension,
);

expect(text).to.eql(
Expand All @@ -70,13 +70,13 @@ describe('utils', () => {
});

describe('SASS', () => {
const variableType = 'SASS';
const extension = 'SASS';

it('should be able to print-out simple variable', () => {
const text = writeVariable(
'This is a comment',
'variable-name', '#fff',
variableType,
extension,
);

expect(text).to.eql(
Expand All @@ -90,15 +90,15 @@ describe('utils', () => {
});

it('should be able to print-out simple variable with an empty comment', () => {
const text = writeVariable('', 'variable-name', '#fff', variableType);
const text = writeVariable('', 'variable-name', '#fff', extension);
expect(text).to.eql('\n\n$variable-name: #fff\n');
});

it('should be able to print-out a comment in multiline', () => {
const text = writeVariable(
'This is a comment\nin two lines',
'variable-name', '#fff',
variableType,
extension,
);

expect(text).to.eql(
Expand All @@ -116,7 +116,7 @@ describe('utils', () => {
const text = writeVariable(
'This is a comment\nin two lines',
'variable-name', '(\n"color-1": #fff,\n"color-2": #000\n)',
variableType,
extension,
);

expect(text).to.eql(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VariableType } from './types';
import { Extension } from './types';

const sanitizeText = (text: string): string => {
return text
Expand All @@ -14,21 +14,21 @@ const writeComment = (message: string): string => {
};

// eslint-disable-next-line consistent-return
const createVariable = (name: string, value: string, type: VariableType): string => {
const createVariable = (name: string, value: string, extension: Extension): string => {
// eslint-disable-next-line default-case
switch (type) {
switch (extension) {
case 'SCSS':
return `$${name}: ${value};`;
case 'SASS':
return `$${name}: ${value.replace(/\n/g, ' ').replace(/\s\s+/g, ' ')}`;
}
};

export const writeVariable = (comment: string, name: string, value: string, type: VariableType): string => {
export const writeVariable = (comment: string, name: string, value: string, extension: Extension): string => {
if (value) {
return sanitizeText(`
${writeComment(comment)}
${createVariable(name, value, type)}
${createVariable(name, value, extension)}
`);
}

Expand Down
1 change: 0 additions & 1 deletion packages/output-styles-as-scss/src/types.ts

This file was deleted.

0 comments on commit b7151a9

Please sign in to comment.