Skip to content

Commit

Permalink
Merge pull request #112 from UXPin/11940-jsx-presets
Browse files Browse the repository at this point in the history
11940 jsx presets
  • Loading branch information
jaroslawsawicki authored Jan 29, 2019
2 parents 7c04cd1 + 691bade commit afed75c
Show file tree
Hide file tree
Showing 102 changed files with 9,297 additions and 10,053 deletions.
10 changes: 9 additions & 1 deletion packages/uxpin-merge-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uxpin/merge-cli",
"version": "0.0.20",
"version": "1.0.0",
"description": "Command-line tool integrating Design System repository with http://code.uxpin.com",
"main": "src/index.js",
"bin": {
Expand Down Expand Up @@ -53,6 +53,7 @@
"@types/node": "^8.0.26",
"@types/opn": "^5.1.0",
"@types/p-any": "^1.1.1",
"@types/p-map": "^1.1.0",
"@types/p-map-series": "^1.0.1",
"@types/p-reduce": "^1.0.0",
"@types/react": "^16.0.12",
Expand Down Expand Up @@ -84,6 +85,11 @@
"webpack-cli": "^2.1.3"
},
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.5",
"babel-standalone": "^6.26.0",
"chokidar": "^2.0.4",
"clean-stacktrace": "^1.1.0",
Expand All @@ -94,11 +100,13 @@
"globby": "^8.0.1",
"http-server": "^0.10.0",
"http-status-codes": "^1.3.0",
"ignore-loader": "^0.1.2",
"locate-path": "^2.0.0",
"lodash": "^4.17.4",
"markdown-to-ast": "^4.0.0",
"opn": "^5.4.0",
"p-any": "^1.1.0",
"p-map": "^2.0.0",
"p-map-series": "^1.0.0",
"p-reduce": "^1.0.0",
"path-sort": "^0.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test-resources: ../../test/resources/repos/nordnet-ui-kit ../../test/resources/r
&& git clone [email protected]:UXPin/mineral-ui.git \
&& cd mineral-ui \
&& git remote add official https://github.com/mineral-ui/mineral-ui.git \
&& git checkout b825842aeb4244e56977af1a4afc3559caed94f3 \
&& git checkout 6a18faefe3d8339b066c92f1a10b27872f15729b \
&& mkdir ./npm-cache \
&& npm install --cache=./npm-cache \
&& rm -rf ./npm-cache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { thunkFillSourcePath } from './thunkFillSourcePath';
import { WarningDetails } from './WarningDetails';

export function joinWarningLists(warningLists:WarningDetails[][], componentPath?:string):WarningDetails[] {
Expand All @@ -10,7 +11,3 @@ export function joinWarningLists(warningLists:WarningDetails[][], componentPath?
return warningList;
}, [] as WarningDetails[]);
}

function thunkFillSourcePath(sourcePath:string):(warning:WarningDetails) => WarningDetails {
return (warning:WarningDetails) => ({ sourcePath, ...warning });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { WarningDetails } from './WarningDetails';

export function thunkFillSourcePath(sourcePath:string):(warning:WarningDetails) => WarningDetails {
return (warning:WarningDetails) => ({ sourcePath, ...warning });
}
2 changes: 1 addition & 1 deletion packages/uxpin-merge-cli/src/program/runProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function executeCommandSteps(programArgs:ProgramArgs, steps:Step[]):Promis
.map((step) => tapPromise(step.exec));
const infos:ComponentCategoryInfo[] = await getComponentCategoryInfos(paths);
const name:string = getLibraryName(paths);
const designSystem:DSMetadata = await getDesignSystemMetadata(infos, name);
const designSystem:DSMetadata = await getDesignSystemMetadata(programArgs, infos, name);
await pMapSeries(stepFunctions, (step) => step(designSystem));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BuildOptions } from '../BuildOptions';
import { getConfig } from '../config/getConfig';
import { Compiler } from './Compiler';
import { WebpackCompiler } from './webpack/WebpackCompiler';

export function getCompiler(options:BuildOptions):Compiler {
return new WebpackCompiler(options);
return new WebpackCompiler(getConfig(options));
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import * as webpack from 'webpack';
import { formatWebpackErrorMessages } from '../../../../utils/webpack/formatWebpackErrorMessages';
import { BuildOptions } from '../../BuildOptions';
import { getConfig } from '../../config/getConfig';
import { Compiler } from '../Compiler';

export class WebpackCompiler implements Compiler {
private readonly config:webpack.Configuration;
private compiler:webpack.Compiler;

constructor(options:BuildOptions) {
this.config = getConfig(options);
constructor(private readonly config:webpack.Configuration) {
this.compiler = webpack(this.config);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentImplementationInfo } from '../../../discovery/component/ComponentInfo';
import { ComponentDefinition } from '../../../serialization/component/ComponentDefinition';
import { getFileString } from '../getFileString';
import { getLibraryBundleSource } from '../getLibraryBundleSource';

describe('getFileString', () => {
describe('getLibraryBundleSource', () => {

const commonImplementation:ComponentImplementationInfo = { path: '', framework: 'reactjs', lang: 'javascript' };
const commonProps:Pick<ComponentDefinition, 'properties' | 'documentation' | 'presets'> = {
Expand Down Expand Up @@ -49,7 +49,7 @@ export {
};`;

// when
const result:string = getFileString(components);
const result:string = getLibraryBundleSource(components);

// then
expect(result).toEqual(expectedFileString);
Expand Down Expand Up @@ -97,7 +97,7 @@ export {
};`;

// when
const result:string = getFileString(components, wrapperPath);
const result:string = getLibraryBundleSource(components, wrapperPath);

// then
expect(result).toEqual(expectedFileString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { writeToFile } from '../../../utils/fs/writeToFile';
import { ComponentDefinition } from '../../serialization/component/ComponentDefinition';
import { BuildOptions } from '../BuildOptions';
import { getComponentLibraryInputPath } from './getComponentLibraryInputPath';
import { getFileString } from './getFileString';
import { getLibraryBundleSource } from './getLibraryBundleSource';

export async function createComponentsLibrary(
componentInfos:ComponentDefinition[],
{ uxpinDirPath, wrapperPath }:BuildOptions,
):Promise<void> {
await ensureDir(uxpinDirPath);
await writeToFile(getComponentLibraryInputPath(uxpinDirPath), getFileString(componentInfos, wrapperPath));
await writeToFile(getComponentLibraryInputPath(uxpinDirPath), getLibraryBundleSource(componentInfos, wrapperPath));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TEMP_DIR_PATH } from '../config/getConfig';

const CLASS_NAME_WRAPPER:string = 'Wrapper';

export function getFileString(components:ComponentDefinition[], wrapperPath?:string):string {
export function getLibraryBundleSource(components:ComponentDefinition[], wrapperPath?:string):string {
const libImports:string[] = [
'import * as React from \'react\';',
'import * as ReactDOM from \'react-dom\';',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ describe('filterPresets', () => {
// having
const paths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/notPresetDir',
'./test/resources/directories/directoryWithPresets/presets/0-default.json',
'./test/resources/directories/directoryWithPresets/presets/1-basic.json',
'./test/resources/directories/directoryWithPresets/presets/2-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/3-notPreset1.json',
'./test/resources/directories/directoryWithPresets/presets/9notPreset2.json',
'./test/resources/directories/directoryWithPresets/presets/0-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/1-basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/2-advanced.jsx',
'./test/resources/directories/directoryWithPresets/presets/3-notPreset1.jsx',
'./test/resources/directories/directoryWithPresets/presets/4-notPreset1.json',
'./test/resources/directories/directoryWithPresets/presets/9notPreset2.jsx',
'./test/resources/directories/directoryWithPresets/presets/notPreset2.txt',
];

const expectedPaths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/0-default.json',
'./test/resources/directories/directoryWithPresets/presets/1-basic.json',
'./test/resources/directories/directoryWithPresets/presets/2-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/3-notPreset1.json',
'./test/resources/directories/directoryWithPresets/presets/0-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/1-basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/2-advanced.jsx',
'./test/resources/directories/directoryWithPresets/presets/3-notPreset1.jsx',
];

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ describe('sortPresets', () => {
it('should return sorted paths according to index prefix', () => {
// having
const paths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/0002-default.json',
'./test/resources/directories/directoryWithPresets/presets/10-default.json',
'./test/resources/directories/directoryWithPresets/presets/5-basic.json',
'./test/resources/directories/directoryWithPresets/presets/2005-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/0-default.json',
'./test/resources/directories/directoryWithPresets/presets/15-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/0002-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/10-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/5-basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/2005-advanced.jsx',
'./test/resources/directories/directoryWithPresets/presets/0-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/15-advanced.jsx',
];

const expectedPaths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/0-default.json',
'./test/resources/directories/directoryWithPresets/presets/0002-default.json',
'./test/resources/directories/directoryWithPresets/presets/5-basic.json',
'./test/resources/directories/directoryWithPresets/presets/10-default.json',
'./test/resources/directories/directoryWithPresets/presets/15-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/2005-advanced.json',
'./test/resources/directories/directoryWithPresets/presets/0-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/0002-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/5-basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/10-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/15-advanced.jsx',
'./test/resources/directories/directoryWithPresets/presets/2005-advanced.jsx',
];

// when
Expand All @@ -31,17 +31,17 @@ describe('sortPresets', () => {
it('should return paths with no index prefix at the end of the list', () => {
// having
const paths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/minimal.json',
'./test/resources/directories/directoryWithPresets/presets/10-default.json',
'./test/resources/directories/directoryWithPresets/presets/advanced.json',
'./test/resources/directories/directoryWithPresets/presets/5-basic.json',
'./test/resources/directories/directoryWithPresets/presets/minimal.jsx',
'./test/resources/directories/directoryWithPresets/presets/10-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/advanced.jsx',
'./test/resources/directories/directoryWithPresets/presets/5-basic.jsx',
];

const expectedPaths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/5-basic.json',
'./test/resources/directories/directoryWithPresets/presets/10-default.json',
'./test/resources/directories/directoryWithPresets/presets/minimal.json',
'./test/resources/directories/directoryWithPresets/presets/advanced.json',
'./test/resources/directories/directoryWithPresets/presets/5-basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/10-default.jsx',
'./test/resources/directories/directoryWithPresets/presets/minimal.jsx',
'./test/resources/directories/directoryWithPresets/presets/advanced.jsx',
];

// when
Expand All @@ -54,15 +54,15 @@ describe('sortPresets', () => {
it('should return unsorted paths if index prefix is not present', () => {
// having
const paths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/default.json',
'./test/resources/directories/directoryWithPresets/presets/basic.json',
'./test/resources/directories/directoryWithPresets/presets/advanced.json',
'./test/resources/directories/directoryWithPresets/presets/default.jsx',
'./test/resources/directories/directoryWithPresets/presets/basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/advanced.jsx',
];

const expectedPaths:string[] = [
'./test/resources/directories/directoryWithPresets/presets/default.json',
'./test/resources/directories/directoryWithPresets/presets/basic.json',
'./test/resources/directories/directoryWithPresets/presets/advanced.json',
'./test/resources/directories/directoryWithPresets/presets/default.jsx',
'./test/resources/directories/directoryWithPresets/presets/basic.jsx',
'./test/resources/directories/directoryWithPresets/presets/advanced.jsx',
];

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { basename } from 'path';

const PRESET_FILENAME_REGEX:RegExp = /^(\d+)-(.+)\.json$/i;
const PRESET_FILENAME_REGEX:RegExp = /^(\d+)-(.+)\.jsx$/i;
const PRESET_NAME_INDEX_IN_MATCH_RESULT:number = 2;

export function getPresetName(path:string):string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { ComponentPresetElementProps } from '../ComponentPreset';
import { PartialProps } from '../jsx/JSXSerializationResult';
import { replaceElementsWithReferencesInProps } from '../replaceElementsWithReferencesInProps';

describe('replaceElementsWithReferencesInProps', () => {
it('should replace single element with reference', () => {
// given
const props:PartialProps = {
icon: {
name: 'Button',
props: {
uxpId: '1',
},
uxpinPresetElementType: 'CodeComponent',
},
};
const expectedProps:ComponentPresetElementProps = {
icon: { uxpinPresetElementId: '1' },
};

// when
const result:ComponentPresetElementProps = replaceElementsWithReferencesInProps(props);

// then
expect(result).toEqual(expectedProps);
});

it('should remove a few elements in array', () => {
// given
const props:PartialProps = {
icon: [
{
name: 'Button',
props: {
uxpId: '1',
},
uxpinPresetElementType: 'CodeComponent',
},
{
name: 'Button',
props: {
uxpId: '2',
},
uxpinPresetElementType: 'CodeComponent',
},
],
};
const expectedProps:ComponentPresetElementProps = {
icon: [],
};

// when
const result:ComponentPresetElementProps = replaceElementsWithReferencesInProps(props);

// then
expect(result).toEqual(expectedProps);
});

it('should remove deeply nested elements', () => {
// given
const props:PartialProps = {
data: [
{
subtitle: [
'some text',
{
name: 'Icon',
props: {
uxpId: '1',
},
uxpinPresetElementType: 'CodeComponent',
},
],
title: 'some title',
},
{
subtitle: {
name: 'Icon',
props: {
uxpId: '1',
},
uxpinPresetElementType: 'CodeComponent',
},
title: 'some title',
},
{
subtitle: 'some subtitle',
title: 'some title',
},
],
};
const expectedProps:ComponentPresetElementProps = {
data: [
{ subtitle: ['some text'], title: 'some title' },
{ title: 'some title' },
{ subtitle: 'some subtitle', title: 'some title' },
],
};

// when
const result:ComponentPresetElementProps = replaceElementsWithReferencesInProps(props);

// then
expect(result).toEqual(expectedProps);
});

it('should return empty object', () => {
// given
const props:PartialProps = {};
const expectedProps:ComponentPresetElementProps = {};

// when
const result:ComponentPresetElementProps = replaceElementsWithReferencesInProps(props);

// then
expect(result).toEqual(expectedProps);
});
});
Loading

0 comments on commit afed75c

Please sign in to comment.