Skip to content

Commit

Permalink
Merge pull request #100 from marcomontalbano/use-native-mkdirSync
Browse files Browse the repository at this point in the history
Use native mkdirSync instead of make-dir library
  • Loading branch information
marcomontalbano committed Dec 14, 2021
2 parents 69e5443 + de8432e commit 99e8788
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 37 deletions.
1 change: 0 additions & 1 deletion packages/output-components-as-es6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"@figma-export/utils": "^4.0.0-alpha.0",
"make-dir": "~3.1.0",
"mini-svg-data-uri": "~1.4.3"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions packages/output-components-as-es6/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe('outputter as es6', () => {
let nockScope: nock.Scope;

beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);

clientFileImages = sinon.stub().returns(Promise.resolve({
data: {
images: {
Expand Down
3 changes: 1 addition & 2 deletions packages/output-components-as-es6/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import makeDir from 'make-dir';
import { camelCase } from '@figma-export/utils';

import * as FigmaExport from '@figma-export/types';
Expand All @@ -22,7 +21,7 @@ export = ({
useBase64 = false,
useDataUrl = false,
}: Options): FigmaExport.ComponentOutputter => {
makeDir.sync(output);
fs.mkdirSync(output, { recursive: true });
return async (pages): Promise<void> => {
pages.forEach((page) => {
const { name: pageName, components } = page;
Expand Down
3 changes: 1 addition & 2 deletions packages/output-components-as-svg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"access": "public"
},
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"make-dir": "~3.1.0"
"@figma-export/types": "^4.0.0-alpha.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/output-components-as-svg/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import fs = require('fs');
import outputter = require('./index');

describe('outputter as svg', () => {
beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
});

afterEach(() => {
sinon.restore();
});
Expand Down
5 changes: 3 additions & 2 deletions packages/output-components-as-svg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as FigmaExport from '@figma-export/types';

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

type Options = {
output: string;
Expand All @@ -24,7 +23,9 @@ export = ({
...figmaExport,
};

const filePath = makeDir.sync(path.resolve(output, getDirname(options)));
const filePath = path.resolve(output, getDirname(options));

fs.mkdirSync(filePath, { recursive: true });
fs.writeFileSync(path.resolve(filePath, getBasename(options)), svg);
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/output-components-as-svgr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"@figma-export/utils": "^4.0.0-alpha.0",
"@svgr/core": "~6.1.2",
"make-dir": "~3.1.0"
"@svgr/core": "~6.1.2"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/output-components-as-svgr/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as figmaDocument from '../../core/src/lib/_config.test';
import * as figma from '../../core/src/lib/figma';
import fs = require('fs');

import makeDir = require('make-dir');
import outputter = require('./index');

describe('outputter as svgr', () => {
Expand All @@ -21,7 +20,7 @@ describe('outputter as svgr', () => {
let svgrAsync;

beforeEach(() => {
sinon.stub(makeDir, 'sync').returnsArg(0);
sinon.stub(fs, 'mkdirSync').returnsArg(0);
writeFileSync = sinon.stub(fs, 'writeFileSync');
svgrAsync = sinon.stub(svgr.transform, 'sync').returns('# code for react component #');

Expand Down
7 changes: 4 additions & 3 deletions packages/output-components-as-svgr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { transform, Config, State } from '@svgr/core';

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

type Options = {
output: string;
Expand All @@ -30,7 +29,7 @@ export = ({
getFileExtension = (): string => '.jsx',
getSvgrConfig = (): Config => ({ }),
}: Options): FigmaExport.ComponentOutputter => {
makeDir.sync(output);
fs.mkdirSync(output, { recursive: true });
const indexJs: IndexJs = {};
return async (pages): Promise<void> => {
pages.forEach(({ name: pageName, components }) => {
Expand All @@ -43,7 +42,9 @@ export = ({

const reactComponentName = getComponentName(options);
const basename = `${reactComponentName}${getFileExtension(options)}`;
const filePath = makeDir.sync(path.resolve(output, getDirname(options)));
const filePath = path.resolve(output, getDirname(options));

fs.mkdirSync(filePath, { recursive: true });

indexJs[filePath] = indexJs[filePath] || [];
indexJs[filePath].push(`export { default as ${reactComponentName} } from './${basename}';`);
Expand Down
1 change: 0 additions & 1 deletion packages/output-components-as-svgstore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"make-dir": "~3.1.0",
"svgstore": "~3.0.1"
},
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions packages/output-components-as-svgstore/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import fs = require('fs');
import outputter = require('./index');

describe('outputter as svgstore', () => {
beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
});

afterEach(() => {
sinon.restore();
});
Expand Down
3 changes: 1 addition & 2 deletions packages/output-components-as-svgstore/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable import/order */

import makeDir from 'make-dir';
import svgstore from 'svgstore';

import * as FigmaExport from '@figma-export/types';
Expand All @@ -22,7 +21,7 @@ export = ({
getIconId = (options): string => `${options.pageName}/${options.componentName}`,
svgstoreConfig = {},
}: Options): FigmaExport.ComponentOutputter => {
makeDir.sync(output);
fs.mkdirSync(output, { recursive: true });
return async (pages): Promise<void> => {
pages.forEach(({ name: pageName, components }) => {
const sprites = svgstore(svgstoreConfig);
Expand Down
3 changes: 1 addition & 2 deletions packages/output-styles-as-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"access": "public"
},
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"make-dir": "~3.1.0"
"@figma-export/types": "^4.0.0-alpha.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/output-styles-as-css/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('style output as css', () => {
let writeFileSync;

beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
writeFileSync = sinon.stub(fs, 'writeFileSync');
});

Expand Down
5 changes: 3 additions & 2 deletions packages/output-styles-as-css/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { writeVariable, writeComment, sanitizeText } from './utils';

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

type Options = {
output: string;
Expand Down Expand Up @@ -79,7 +78,9 @@ export = ({
}
});

const filePath = makeDir.sync(path.resolve(output));
const filePath = path.resolve(output);

fs.mkdirSync(filePath, { recursive: true });
fs.writeFileSync(path.resolve(filePath, `${getFilename()}.css`), sanitizeText(`
:root {
${text}
Expand Down
3 changes: 1 addition & 2 deletions packages/output-styles-as-less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"access": "public"
},
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"make-dir": "~3.1.0"
"@figma-export/types": "^4.0.0-alpha.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/output-styles-as-less/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('style output as less', () => {
let writeFileSync;

beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
writeFileSync = sinon.stub(fs, 'writeFileSync');
});

Expand Down
5 changes: 3 additions & 2 deletions packages/output-styles-as-less/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { writeVariable, writeMap } from './utils';

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

type Options = {
output: string;
Expand Down Expand Up @@ -74,7 +73,9 @@ export = ({
}
});

const filePath = makeDir.sync(path.resolve(output));
const filePath = path.resolve(output);

fs.mkdirSync(filePath, { recursive: true });
fs.writeFileSync(path.resolve(filePath, `${getFilename()}.less`), text);
};
};
3 changes: 1 addition & 2 deletions packages/output-styles-as-sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"access": "public"
},
"dependencies": {
"@figma-export/types": "^4.0.0-alpha.0",
"make-dir": "~3.1.0"
"@figma-export/types": "^4.0.0-alpha.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/output-styles-as-sass/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('style output as scss', () => {
let writeFileSync;

beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
writeFileSync = sinon.stub(fs, 'writeFileSync');
});

Expand Down
5 changes: 3 additions & 2 deletions packages/output-styles-as-sass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Extension } from './types';

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

type Options = {
output: string;
Expand Down Expand Up @@ -79,7 +78,9 @@ export = ({
}
});

const filePath = makeDir.sync(path.resolve(output));
const filePath = path.resolve(output);

fs.mkdirSync(filePath, { recursive: true });
fs.writeFileSync(path.resolve(filePath, `${getFilename()}.${extension.toLowerCase()}`), text);
};
};
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ __metadata:
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
"@figma-export/utils": ^4.0.0-alpha.0
make-dir: ~3.1.0
mini-svg-data-uri: ~1.4.3
languageName: unknown
linkType: soft
Expand All @@ -665,7 +664,6 @@ __metadata:
resolution: "@figma-export/output-components-as-svg@workspace:packages/output-components-as-svg"
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
make-dir: ~3.1.0
languageName: unknown
linkType: soft

Expand All @@ -676,7 +674,6 @@ __metadata:
"@figma-export/types": ^4.0.0-alpha.0
"@figma-export/utils": ^4.0.0-alpha.0
"@svgr/core": ~6.1.2
make-dir: ~3.1.0
languageName: unknown
linkType: soft

Expand All @@ -685,7 +682,6 @@ __metadata:
resolution: "@figma-export/output-components-as-svgstore@workspace:packages/output-components-as-svgstore"
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
make-dir: ~3.1.0
svgstore: ~3.0.1
languageName: unknown
linkType: soft
Expand All @@ -695,7 +691,6 @@ __metadata:
resolution: "@figma-export/output-styles-as-css@workspace:packages/output-styles-as-css"
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
make-dir: ~3.1.0
languageName: unknown
linkType: soft

Expand All @@ -704,7 +699,6 @@ __metadata:
resolution: "@figma-export/output-styles-as-less@workspace:packages/output-styles-as-less"
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
make-dir: ~3.1.0
languageName: unknown
linkType: soft

Expand All @@ -713,7 +707,6 @@ __metadata:
resolution: "@figma-export/output-styles-as-sass@workspace:packages/output-styles-as-sass"
dependencies:
"@figma-export/types": ^4.0.0-alpha.0
make-dir: ~3.1.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -9427,7 +9420,7 @@ __metadata:
languageName: node
linkType: hard

"make-dir@npm:^3.0.0, make-dir@npm:^3.0.2, make-dir@npm:~3.1.0":
"make-dir@npm:^3.0.0, make-dir@npm:^3.0.2":
version: 3.1.0
resolution: "make-dir@npm:3.1.0"
dependencies:
Expand Down

0 comments on commit 99e8788

Please sign in to comment.