Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/app/converter/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Utils } from '../utils';
describe('Converter class', () => {
let options = { inputFiles: [''], format: 'JSON' };

it('should return an instance of Converer', () => {
it('should return an instance of Converter', () => {
let converter = new Converter(options);
expect(converter).to.be.instanceof(Converter);
});
Expand All @@ -24,7 +24,7 @@ describe('Converter class', () => {
});


describe('JSON exported extructure', () => {
describe('JSON exported structure', () => {
Comment thread
gopuneet marked this conversation as resolved.
let opts = { inputFiles: [path.resolve('./test/scss/_variables.scss')], format: 'JSON' };
let converter = null;
let results = null;
Expand All @@ -42,13 +42,13 @@ describe('Converter class', () => {
});

it('should have the correct object structure', () => {
expect(results[0]).to.have.property('variable');
expect(results[0]).to.have.property('name');
expect(results[0]).to.have.property('value');
expect(results[0]).to.have.property('compiledValue');
});

it('should have the variable the same as the sass file', () => {
expect(results[0].variable).to.equal('$white');
expect(results[0].name).to.equal('$white');
expect(results[0].value).to.equal('#fff');
expect(results[0].compiledValue).to.equal('#fff');
});
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Converter class', () => {
let structured = converter.getStructured();

expect(structured.icons[0]).to.have.property('mapValue');
expect(structured.icons[0].mapValue[0].variable).to.be.equal('glass');
expect(structured.icons[0].mapValue[0].name).to.be.equal('glass');
expect(structured.icons[0].mapValue[0].value).to.be.equal('value');
expect(structured.icons[0].mapValue[0].compiledValue).to.be.equal('value');
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Converter {

return parsedDeclarations.map((declaration) => {
declaration.compiledValue = this.renderPropertyValue(content, declaration);
declaration.variable = `$${declaration.variable}`;
declaration.name = `$${declaration.name}`;

if (declaration.mapValue) {
declaration.mapValue.map((mapDeclaration) => {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class Converter {

let compiledGroup = structuredDeclaration[group].map((declaration) => {
declaration.compiledValue = this.renderPropertyValue(content, declaration);
declaration.variable = `$${declaration.variable}`;
declaration.name = `$${declaration.name}`;

if (declaration.mapValue) {
declaration.mapValue.map((mapDeclaration) => {
Expand Down
12 changes: 6 additions & 6 deletions src/app/parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Parser class', () => {

expect(validParser.parse()).that.is.an('array');
expect(validParser.parse()).to.have.lengthOf(1);
expect(validParser.parse()[0].variable).to.be.equal('slate-dark');
expect(validParser.parse()[0].name).to.be.equal('slate-dark');
expect(validParser.parse()[0].value).to.be.equal('#4f6f7b');
});

Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Parser class', () => {
expect(structured).to.have.property('theme-colors');
expect(structured.globals.length).be.equal(2);
expect(structured['theme-colors'].length).be.equal(3);
expect(structured['theme-colors'][1].variable).to.be.equal('brand-gray-medium');
expect(structured['theme-colors'][1].name).to.be.equal('brand-gray-medium');
});

it('should group in globals if end-section is present', () => {
Expand All @@ -91,7 +91,7 @@ describe('Parser class', () => {
expect(structured).to.have.property('light');
expect(structured.globals.length).be.equal(4);
expect(structured.light.length).be.equal(1);
expect(structured.light[0].variable).be.equal('brand-gray-light');
expect(structured.light[0].name).be.equal('brand-gray-light');
});

it('should ignore the section if the name is invalid', () => {
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Parser class', () => {
let structured = parser.parseStructured();

expect(structured.first.length).be.equal(3);
expect(structured.first[2].variable).be.equal('brand-gray-3');
expect(structured.first[2].name).be.equal('brand-gray-3');
});
});

Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Parser class', () => {
let parser = new Parser(content);
let structured = parser.parseStructured();

expect(structured.globals[0].mapValue[0].variable).be.equal('small');
expect(structured.globals[0].mapValue[0].name).be.equal('small');
expect(structured.globals[0].mapValue[0].value).be.equal('767px');

expect(structured.globals[0].mapValue[1].value).be.equal('$bp-medium');
Expand All @@ -180,7 +180,7 @@ describe('Parser class', () => {
let parser = new Parser(content);
let parsedArray = parser.parse();

expect(parsedArray[0].mapValue[0].variable).be.equal('small');
expect(parsedArray[0].mapValue[0].name).be.equal('small');
expect(parsedArray[0].mapValue[0].value).be.equal('767px');

expect(parsedArray[0].mapValue[1].value).be.equal('$bp-medium');
Expand Down
4 changes: 2 additions & 2 deletions src/app/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export class Parser {
return;
}

let variable = matches[1].trim().replace('_', '-');
let name = matches[1].trim().replace('_', '-');
let value = matches[2].trim().replace(/\s*\n+\s*|\"/g, '');

return { variable, value } as IDeclaration;
return { name, value } as IDeclaration;
}


Expand Down
8 changes: 4 additions & 4 deletions src/app/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ describe('Utils class', () => {

let declarations = [
// tslint:disable:object-literal-key-quotes
{ "variable": "$brand-blue-gray", "value": "#647b86", "compiledValue": "#647b86" },
{ "variable": "$brand-blue-gray-dark", "value": "#546E7A", "compiledValue": "#546E7A" },
{ "variable": "$brand-solitude", "value": "#ebeff2", "compiledValue": "#ebeff2" }
{ "name": "$brand-blue-gray", "value": "#647b86", "compiledValue": "#647b86" },
{ "name": "$brand-blue-gray-dark", "value": "#546E7A", "compiledValue": "#546E7A" },
{ "name": "$brand-solitude", "value": "#ebeff2", "compiledValue": "#ebeff2" }
];

it('should have a public helper getDeclaration', () => {
Expand All @@ -32,7 +32,7 @@ describe('Utils class', () => {
});

it('should wrap a variable', () => {
let declaration = { variable: 'var', value: '$the-value', compiledValue: '' };
let declaration = { name: 'var', value: '$the-value', compiledValue: '' };
let expectedResult = '#sass-export-id.var{content:"#{$the-value}";}';
let wrapped = Utils.wrapCss(declaration);

Expand Down
4 changes: 2 additions & 2 deletions src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const UNWRAPPER_PATTERN = `${WRAPPER_CSS_ID}\\.(.+)\\s*\\{\\s*content:\\s*["'](.
export class Utils {

public static getDeclarationByName(declarations: IDeclaration[] = [], name: string): IDeclaration {
let filtered = declarations.filter((declaration) => declaration.variable === name);
let filtered = declarations.filter((declaration) => declaration.name === name);

return filtered[0];
}


public static wrapCss(cssDeclaration: IDeclaration): string {
return `${WRAPPER_CSS_ID}.${cssDeclaration.variable}{content:"#{${cssDeclaration.value}}";}`;
return `${WRAPPER_CSS_ID}.${cssDeclaration.name}{content:"#{${cssDeclaration.value}}";}`;
}


Expand Down
2 changes: 1 addition & 1 deletion src/libs/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface IOptions {
}

interface IDeclaration {
variable: string,
name: string,
value: string,
mapValue?: Array<any>,
compiledValue: string
Expand Down