Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/add-v2-config-file
Browse files Browse the repository at this point in the history
  • Loading branch information
tancredi authored Oct 2, 2021
2 parents 813c3d8 + 9011def commit bc9fa74
Show file tree
Hide file tree
Showing 27 changed files with 1,929 additions and 3,033 deletions.
3,719 changes: 1,269 additions & 2,450 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@
"change-case": "^4.1.2",
"cli-color": "^2.0.0",
"commander": "^7.2.0",
"glob": "^7.1.6",
"glob": "^7.1.7",
"handlebars": "^4.7.7",
"slugify": "^1.5.3",
"svg2ttf": "^5.2.0",
"svgicons2svgfont": "^9.1.1",
"svg2ttf": "^6.0.2",
"svgicons2svgfont": "^10.0.3",
"ttf2eot": "^2.0.0",
"ttf2woff": "^2.0.2",
"ttf2woff2": "^4.0.2"
"ttf2woff2": "^4.0.4"
},
"devDependencies": {
"@types/cli-color": "^2.0.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.23",
"@types/node": "^15.0.3",
"@types/node": "^16.4.10",
"@types/svg2ttf": "^5.0.0",
"@types/svgicons2svgfont": "^9.1.0",
"@types/svgicons2svgfont": "^10.0.1",
"@types/ttf2eot": "^2.0.0",
"@types/ttf2woff": "^2.0.0",
"@types/ttf2woff2": "^2.0.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.2",
"semantic-release": "^17.4.4",
"ts-jest": "^26.5.6",
"typescript": "^4.2.4"
"typescript": "^4.3.5"
},
"jest": {
"preset": "ts-jest",
Expand Down
2 changes: 1 addition & 1 deletion src/core/__tests__/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseConfig } from '../config-parser';
import { checkPath } from '../../utils/fs-async';
import { DEFAULT_OPTIONS } from '../../constants';

const checkPathMock = (checkPath as any) as jest.Mock;
const checkPathMock = checkPath as any as jest.Mock;

jest.mock('../../utils/fs-async', () => ({ checkPath: jest.fn() }));

Expand Down
10 changes: 5 additions & 5 deletions src/core/__tests__/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { getGeneratorOptions } from '../../generators/generator-options';
import { parseConfig } from '../config-parser';
import { DEFAULT_OPTIONS } from '../../constants';

const generateAssetsMock = (generateAssets as any) as jest.Mock;
const parseConfigMock = (parseConfig as any) as jest.Mock;
const writeAssetsMock = (writeAssets as any) as jest.Mock;
const loadAssetsMock = (loadAssets as any) as jest.Mock;
const getGeneratorOptionsMock = (getGeneratorOptions as any) as jest.Mock;
const generateAssetsMock = generateAssets as any as jest.Mock;
const parseConfigMock = parseConfig as any as jest.Mock;
const writeAssetsMock = writeAssets as any as jest.Mock;
const loadAssetsMock = loadAssets as any as jest.Mock;
const getGeneratorOptionsMock = getGeneratorOptions as any as jest.Mock;

jest.mock('../../constants', () => ({
DEFAULT_OPTIONS: { hasDefaults: true, parsed: false }
Expand Down
2 changes: 1 addition & 1 deletion src/core/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ export const parseConfig = async (input: object = {}) => {
out[key] = val;
}

return (out as any) as RunnerOptions;
return out as any as RunnerOptions;
};
4 changes: 2 additions & 2 deletions src/generators/__tests__/generate-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jest.mock('../asset-types', () => {
};
});

const cast = <T>(val: any) => (val as unknown) as T;
const cast = <T>(val: any) => val as unknown as T;

const getGeneratorFn = (key: string) =>
generators[key as keyof typeof generators].generate;

describe('Generate assets', () => {
beforeEach(() => {
for (const gen of Object.values(generators)) {
((gen.generate as unknown) as jest.Mock).mockClear();
(gen.generate as unknown as jest.Mock).mockClear();
}
});

Expand Down
17 changes: 9 additions & 8 deletions src/generators/__tests__/generator-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { AssetsMap } from '../../utils/assets';
import { ASSET_TYPES, ASSET_TYPES_WITH_TEMPLATE } from '../../types/misc';
import { getCodepoints } from '../../utils/codepoints';

const getCodepointsMock = (getCodepoints as any) as jest.Mock;
const getCodepointsMock = getCodepoints as any as jest.Mock;

jest.mock('path');

jest.mock('../../constants', () => ({
...jest.requireActual('../../constants'),
TEMPLATES_DIR: '/foo/templates-dir'
}));
jest.mock('../../constants', () => {
const constants = jest.requireActual('../../constants');

return { ...constants, TEMPLATES_DIR: '/foo/templates-dir' };
});

jest.mock('../../types/misc', () => ({
FontAssetType: { TTF: 'TTF', EOT: 'eot' },
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('Font generator options', () => {
formatOptions,
pathOptions
} as any;
const assets = ({ __mock: 'runnerOptions__' } as unknown) as AssetsMap;
const assets = { __mock: 'runnerOptions__' } as unknown as AssetsMap;
const generatorOptions = getGeneratorOptions(options, assets);
expect(generatorOptions).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -99,7 +100,7 @@ describe('Font generator options', () => {
test('`getGeneratorOptions` calls `getCodepoints` with input assets and codepoints', () => {
const codepointsIn = { foo: 'bar' };
const options = { codepoints: codepointsIn } as any;
const assets = ({} as unknown) as AssetsMap;
const assets = {} as unknown as AssetsMap;

getGeneratorOptions(options, assets);

Expand All @@ -109,7 +110,7 @@ describe('Font generator options', () => {

test('`getGeneratorOptions` correctly processes templates option', () => {
const options = { templates: { html: 'user-template.hbs' } } as any;
const assets = ({} as unknown) as AssetsMap;
const assets = {} as unknown as AssetsMap;

expect(getGeneratorOptions(options, assets).templates.css).toMatch(
'/foo/templates-dir/css.hbs'
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cssGen from '../css';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test-font',
Expand Down
8 changes: 4 additions & 4 deletions src/generators/asset-types/__tests__/eot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import eotGen from '../eot';

const ttf2eot = (_ttf2eot as unknown) as jest.Mock<typeof _ttf2eot>;
const ttf2eot = _ttf2eot as unknown as jest.Mock<typeof _ttf2eot>;

jest.mock('ttf2eot', () =>
jest.fn(content => ({ buffer: `::eot(${content})::` }))
);

const mockOptions = (eotOptions = { __mock: 'options__' } as any) =>
(({} as unknown) as FontGeneratorOptions);
({} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`EOT` font generator', () => {
beforeEach(() => ttf2eot.mockClear());

test('resolves with the correctly processed return value of `ttf2eot`', async () => {
const result = await eotGen.generate(mockOptions(), ttf);
const ttfArr = new Uint8Array(('::ttf::' as unknown) as any[]);
const ttfArr = new Uint8Array('::ttf::' as unknown as any[]);

expect(ttf2eot).toHaveBeenCalledTimes(1);
expect(ttf2eot).toHaveBeenCalledWith(ttfArr);
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sassGen from '../sass';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test',
Expand Down
2 changes: 1 addition & 1 deletion src/generators/asset-types/__tests__/scss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scssGen from '../scss';
import { renderSrcAttribute } from '../../../utils/css';
import { resolve } from 'path';

const renderSrcMock = (renderSrcAttribute as any) as jest.Mock;
const renderSrcMock = renderSrcAttribute as any as jest.Mock;

const mockOptions = {
name: 'test',
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import svgGen from '../svg';

const SVGIcons2SVGFontStream = (_SVGIcons2SVGFontStream as unknown) as jest.Mock<
const SVGIcons2SVGFontStream = _SVGIcons2SVGFontStream as unknown as jest.Mock<
typeof _SVGIcons2SVGFontStream
>;

Expand Down Expand Up @@ -45,7 +45,7 @@ jest.mock('svgicons2svgfont', () => {
});

const mockOptions = (svgOptions = { __mock: 'options__' } as any) =>
(({
({
name: 'foo',
fontHeight: 1,
descent: 2,
Expand All @@ -56,7 +56,7 @@ const mockOptions = (svgOptions = { __mock: 'options__' } as any) =>
foo: { id: 'foo', absolutePath: '/root/foo.svg' },
bar: { id: 'bar', absolutePath: '/root/bar.svg' }
}
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

describe('`SVG` font generator', () => {
beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import ttfGen from '../ttf';

const svg2ttf = (_svg2ttf as unknown) as jest.Mock<typeof _svg2ttf>;
const svg2ttf = _svg2ttf as unknown as jest.Mock<typeof _svg2ttf>;

jest.mock('svg2ttf', () =>
jest.fn(content => ({ buffer: `::ttf(${content})::` }))
);

const mockOptions = (ttfOptions = { __mock: 'options__' } as any) =>
(({
({
formatOptions: { [FontAssetType.TTF]: ttfOptions }
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

const svg = '::svg::';

Expand Down
10 changes: 5 additions & 5 deletions src/generators/asset-types/__tests__/woff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import woffGen from '../woff';

const ttf2woff = (_ttf2woff as unknown) as jest.Mock<typeof _ttf2woff>;
const ttf2woff = _ttf2woff as unknown as jest.Mock<typeof _ttf2woff>;

jest.mock('ttf2woff', () =>
jest.fn(content => ({ buffer: `::woff(${content})::` }))
);

const mockOptions = (woffOptions = { __mock: 'options__' } as any) =>
(({
({
formatOptions: { [FontAssetType.WOFF]: woffOptions }
} as unknown) as FontGeneratorOptions);
} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`WOFF` font generator', () => {
beforeEach(() => {
Expand All @@ -23,7 +23,7 @@ describe('`WOFF` font generator', () => {

test('resolves with the correctly processed return value of `ttf2woff`', async () => {
const result = await woffGen.generate(mockOptions(), ttf);
const ttfArr = new Uint8Array(('::ttf::' as unknown) as any[]);
const ttfArr = new Uint8Array('::ttf::' as unknown as any[]);

expect(ttf2woff).toHaveBeenCalledTimes(1);
expect(ttf2woff).toHaveBeenCalledWith(ttfArr, { __mock: 'options__' });
Expand Down
6 changes: 3 additions & 3 deletions src/generators/asset-types/__tests__/woff2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import _ttf2woff2 from 'ttf2woff2';
import { FontGeneratorOptions } from '../../../types/generator';
import woff2Gen from '../woff2';

const ttf2woff2 = (_ttf2woff2 as unknown) as jest.Mock<typeof _ttf2woff2>;
const ttf2woff2 = _ttf2woff2 as unknown as jest.Mock<typeof _ttf2woff2>;

jest.mock('ttf2woff2', () =>
jest.fn(content => ({ buffer: `::woff2(${content})::` }))
);

const mockOptions = (woffOptions = { __mock: 'options__' } as any) =>
(({} as unknown) as FontGeneratorOptions);
({} as unknown as FontGeneratorOptions);

const ttf = ('::ttf::' as unknown) as Buffer;
const ttf = '::ttf::' as unknown as Buffer;

describe('`WOFF2` font generator', () => {
beforeEach(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/generators/asset-types/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ const generator: FontGenerator = {
formatOptions: { ts } = {}
}) => {
const quote = Boolean(ts?.singleQuotes) ? "'" : '"';
const generateKind: Record<string, boolean> = (Boolean(ts?.types?.length)
? ts.types
: ['enum', 'constant', 'literalId', 'literalKey']
const generateKind: Record<string, boolean> = (
Boolean(ts?.types?.length)
? ts.types
: ['enum', 'constant', 'literalId', 'literalKey']
)
.map(kind => ({ [kind]: true }))
.reduce((prev, curr) => Object.assign(prev, curr), {});
Expand Down
Loading

0 comments on commit bc9fa74

Please sign in to comment.