Skip to content

Commit

Permalink
Merge pull request #152 from andrew-codes/spaced-group
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Dec 2, 2018
2 parents a94ace4 + 085c24a commit 646cf3d
Show file tree
Hide file tree
Showing 41 changed files with 2,209 additions and 142 deletions.
4 changes: 4 additions & 0 deletions .jestrc.js
@@ -0,0 +1,4 @@
module.exports = {
projects: ['<rootDir>/components/*', '<rootDir>/packages/*'],
testMatch: ['**/__tests__/**/*.js?(x)'],
};
10 changes: 9 additions & 1 deletion .travis.yml
Expand Up @@ -30,7 +30,15 @@ jobs:
install:
- ./scripts/bin/ci-install.sh
script:
- yarn test:ci
- yarn test:specs

- stage: 'Verify'
env:
- NODE_ENV: test
install:
- ./scripts/bin/ci-install.sh
script:
- yarn test:e2e:ci
- kill $(jobs -p) || true

- stage: 'Deploy Preview of Docs Site'
Expand Down
17 changes: 17 additions & 0 deletions babel.config.js
@@ -0,0 +1,17 @@
module.exports = {
babelrcRoots: ['.', 'packages/*', 'components/*'],
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-syntax-dynamic-import',
'babel-plugin-transform-react-fela-display-name',
[
'babel-plugin-transform-react-remove-prop-types',
{
mode: 'wrap',
ignoreFilenames: ['node_modules'],
},
],
'babel-plugin-dev-expression',
],
};
16 changes: 16 additions & 0 deletions build/component-package-generator/package.json
@@ -0,0 +1,16 @@
{
"private": true,
"name": "@andrew-codes/component-package-generator",
"version": "0.0.0",
"description": "Generate component packages for Verdigris.",
"license": "MIT",
"bin": {
"generate-component": "src/bin/generate-component.js"
},
"dependencies": {
"change-case": "^3.0.2",
"handlebars": "^4.0.12",
"shelljs": "^0.8.3",
"yargs": "^12.0.5"
}
}
78 changes: 78 additions & 0 deletions build/component-package-generator/src/bin/generate-component.js
@@ -0,0 +1,78 @@
#!/usr/bin/env node

const changeCase = require('change-case');
const fs = require('fs');
const handlebars = require('handlebars');
const path = require('path');
const shell = require('shelljs');
const { force, menu, name } = require('yargs').argv;

const packageName = changeCase.param(name);

const componentDirectory = path.join(
__dirname,
'..',
'..',
'..',
'..',
'components',
packageName,
);

if (fs.existsSync(componentDirectory) && !force) {
/* eslint-disable-next-line no-console */
console.log('Component already exists. Try using --force.');
return;
}

const docsDirectory = path.join(componentDirectory, 'docs');
const srcDirectory = path.join(componentDirectory, 'src');
const templateDir = path.join(__dirname, '..', 'template');

const pkgSource = fs.readFileSync(
path.join(templateDir, 'package.json.hbs'),
'utf8',
);
const mdxSource = fs.readFileSync(path.join(templateDir, 'mdx.hbs'), 'utf8');
const indexSource = fs.readFileSync(
path.join(templateDir, 'index.js.hbs'),
'utf8',
);
const componentSrcSource = fs.readFileSync(
path.join(templateDir, 'componentSrc.js.hbs'),
'utf8',
);

const pkgTemplate = handlebars.compile(pkgSource);
const mdxTemplate = handlebars.compile(mdxSource);
const indexTemplate = handlebars.compile(indexSource);
const componentSrcTemplate = handlebars.compile(componentSrcSource);

const pkgContents = pkgTemplate({ packageName });
const mdxContents = mdxTemplate({
ofName: `{${name}}`,
name,
menu: menu || 'Components',
packageName,
});
const indexContents = indexTemplate({ name });
const componentSrcContents = componentSrcTemplate({ name });

shell.mkdir('-p', componentDirectory);
shell.mkdir('-p', docsDirectory);
shell.mkdir('-p', srcDirectory);

fs.writeFileSync(
path.join(componentDirectory, 'package.json'),
pkgContents,
'utf8',
);
fs.writeFileSync(path.join(docsDirectory, `${name}.mdx`), mdxContents, 'utf8');
fs.writeFileSync(path.join(srcDirectory, 'index.js'), indexContents, 'utf8');
fs.writeFileSync(
path.join(srcDirectory, `${name}.js`),
componentSrcContents,
'utf8',
);

shell.exec('yarn bootstrap');
9 changes: 9 additions & 0 deletions build/component-package-generator/src/template/LICENSE
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2018 Andrew Smith

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions build/component-package-generator/src/template/componentSrc.js.hbs
@@ -0,0 +1,16 @@
import PropTypes from 'prop-types';
import React from 'react';

const {{name}} = () => {
throw new Error("Not implemented");
};
{{name}}.propTypes = {
};
{{name}}.defaultProps = {
};
{{name}}.themeDefinition = {
};
{{name}}.defaultThemeValues = {
};

export default {{name}};
3 changes: 3 additions & 0 deletions build/component-package-generator/src/template/index.js.hbs
@@ -0,0 +1,3 @@
import {{name}} from './{{name}}';

export default {{name}};
28 changes: 28 additions & 0 deletions build/component-package-generator/src/template/mdx.hbs
@@ -0,0 +1,28 @@
---
name: {{name}}
route: /packages/{{packageName}}/components/{{name}}
menu: {{menu}}
---

import {
Playground,
PropsTable,
ThemeDefinitionTable,
} from '@andrew-codes/verdigris-docz';
import {{name}} from '../src';

## Usage

## Examples

<Playground data-test="examples">

</Playground>

## Component API

<PropsTable of={{ofName}} />

## Theme API

<ThemeDefinitionTable of={{ofName}} />
28 changes: 28 additions & 0 deletions build/component-package-generator/src/template/package.json.hbs
@@ -0,0 +1,28 @@
{
"name": "@andrew-codes/verdigris-{{packageName}}",
"version": "0.0.0",
"description": "",
"license": "MIT",
"main": "./dist/index.js",
"main:src": "./src/index.js",
"files": [
"dist",
"LICENSE"
],
"scripts": {
"build": "babel --root-mode upward src --out-dir dist"
},
"dependencies": {
"@andrew-codes/verdigris-style-container": "^0.0.0",
"@andrew-codes/verdigris-style-provider": "^0.0.0"
},
"peerDependencies": {
"prop-types": "^15.6.2",
"react": "^16.4.1"
},
"devDependencies": {
"@andrew-codes/verdigris-docz": "^0.0.0",
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.5"
}
}
2 changes: 1 addition & 1 deletion build/custom-propType-handler/src/customPropTypeHandler.js
Expand Up @@ -2,7 +2,7 @@ const getPropType = require('react-docgen/dist/utils/getPropType');
const getPropertyName = require('react-docgen/dist/utils/getPropertyName');
const isReactModuleName = require('react-docgen/dist/utils/isReactModuleName');
const getMemberValuePath = require('react-docgen/dist/utils/getMemberValuePath');
const printValue = require('react-docgen/dist/utils/printValue');
const printValue = require('react-docgen/dist/utils/printValue').default;
const recast = require('recast');
const resolveToModule = require('react-docgen/dist/utils/resolveToModule');
const resolveToValue = require('react-docgen/dist/utils/resolveToValue');
Expand Down
31 changes: 19 additions & 12 deletions build/custom-propType-handler/src/defaultValuesHandler.js
@@ -1,6 +1,6 @@
const getPropertyName = require('react-docgen/dist/utils/getPropertyName');
const getMemberValuePath = require('react-docgen/dist/utils/getMemberValuePath');
const printValue = require('react-docgen/dist/utils/printValue');
const printValue = require('react-docgen/dist/utils/printValue').default;
const recast = require('recast');
const resolveFunctionDefinitionToReturnValue = require('react-docgen/dist/utils/resolveFunctionDefinitionToReturnValue');
const resolveToValue = require('react-docgen/dist/utils/resolveToValue');
Expand Down Expand Up @@ -74,7 +74,12 @@ function getDefaultPropsPath(propName, componentDefinition) {
return defaultThemeValues;
}

function getDefaultValuesFromProps(properties, documentation, isStateless) {
function getDefaultValuesFromProps(
propTypeName,
properties,
documentation,
isStateless,
) {
properties
.filter(propertyPath => types.Property.check(propertyPath.node))
// Don't evaluate property if component is functional and the node is not an AssignmentPattern
Expand All @@ -84,21 +89,21 @@ function getDefaultValuesFromProps(properties, documentation, isStateless) {
types.AssignmentPattern.check(propertyPath.get('value').node),
)
.forEach(propertyPath => {
const propDescriptor = documentation._data.get('themeDefinition')[
const propDescriptor = documentation._data.get(propTypeName)[
getPropertyName.default(propertyPath)
];
const defaultValue = getDefaultValue(
isStateless
? propertyPath.get('value', 'right')
: propertyPath.get('value'),
);
if (defaultValue) {
propDescriptor.defaultValue = defaultValue;
}
const defaultValue = getDefaultValue(
isStateless
? propertyPath.get('value', 'right')
: propertyPath.get('value'),
);
if (defaultValue) {
propDescriptor.defaultValue = defaultValue;
}
});
}

module.exports = function deafultValueHandler(propName) {
module.exports = function defaultValueHandler(propName, propTypeName) {
return function defaultThemeValuesHandler(
documentation,
componentDefinition,
Expand All @@ -112,6 +117,7 @@ module.exports = function deafultValueHandler(propName) {
// Do both statelessProps and defaultProps if both are available so defaultProps can override
if (statelessProps && types.ObjectPattern.check(statelessProps.node)) {
getDefaultValuesFromProps(
propTypeName,
statelessProps.get('properties'),
documentation,
true,
Expand All @@ -122,6 +128,7 @@ module.exports = function deafultValueHandler(propName) {
types.ObjectExpression.check(defaultPropsPath.node)
) {
getDefaultValuesFromProps(
propTypeName,
defaultPropsPath.get('properties'),
documentation,
false,
Expand Down
2 changes: 1 addition & 1 deletion build/custom-propType-handler/src/index.js
Expand Up @@ -5,7 +5,7 @@ module.exports = (propName, defaultValuePropName) => {
return [
customPropTypeHandler(propName),
defaultValuePropName
? defaultValuesHandler(defaultValuePropName)
? defaultValuesHandler(defaultValuePropName, propName)
: undefined,
].filter(Boolean);
};
1 change: 1 addition & 0 deletions build/docz/package.json
Expand Up @@ -9,6 +9,7 @@
"dist"
],
"dependencies": {
"@andrew-codes/verdigris-code": "^0.0.0",
"@andrew-codes/verdigris-style-container": "^0.0.0",
"@andrew-codes/verdigris-style-provider": "^0.0.0",
"@mdx-js/tag": "^0.16.1",
Expand Down
24 changes: 22 additions & 2 deletions build/docz/src/ThemeDefinitionTable.js
@@ -1,4 +1,5 @@
import capitalize from 'capitalize';
import { CodeBlock } from '@andrew-codes/verdigris-code';
import PropTypes from 'prop-types';
import React from 'react';
import StyleProvider from '@andrew-codes/verdigris-style-provider';
Expand All @@ -22,7 +23,20 @@ const getPropType = (prop, Tooltip) => {
return name;
}

return <Tooltip text={humanize(prop.type)}>{name}</Tooltip>;
return (
<Tooltip
text={humanize(prop.type)
.split('\\n')
.map((part, index) => (
/* eslint-disable-next-line react/no-array-index-key */
<span key={index} style={{ display: 'block' }}>
{part}
</span>
))}
>
{name}
</Tooltip>
);
};

const PropsTable = ({ of, components }) => {
Expand Down Expand Up @@ -68,7 +82,13 @@ const PropsTable = ({ of, components }) => {
<Tr key={key}>
<Td>{key}</Td>
<Td>{getPropType(value, Tooltip)}</Td>
<Td>{defaultValue}</Td>
<Td>
{defaultValue.split(/\n/).length > 1 ? (
<CodeBlock>{defaultValue}</CodeBlock>
) : (
defaultValue
)}
</Td>
<Td>
{value.deprecated ? (
<span>
Expand Down
3 changes: 1 addition & 2 deletions build/docz/src/humanize.js
Expand Up @@ -41,8 +41,7 @@ const getTypeStr = type => {
Object.keys(shape).forEach(key => {
rst[key] = getTypeStr(shape[key]);
});

return JSON.stringify(rst, null, 2);
return JSON.stringify(rst, null, 2).replace(/\\"/g, '"');
default:
return capitalize(type.name);
}
Expand Down
9 changes: 6 additions & 3 deletions components/analytics/package.json
Expand Up @@ -6,10 +6,11 @@
"main": "./dist/index.js",
"main:src": "./src/index.js",
"files": [
"dist"
"dist",
"LICENSE"
],
"scripts": {
"build": "babel src --out-dir dist"
"build": "babel --root-mode upward src --out-dir dist"
},
"verdigris": {
"name": "Analytics"
Expand All @@ -22,6 +23,8 @@
},
"devDependencies": {
"@andrew-codes/verdigris-chip": "^0.0.0",
"@andrew-codes/verdigris-docz": "^0.0.0"
"@andrew-codes/verdigris-docz": "^0.0.0",
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.5"
}
}

0 comments on commit 646cf3d

Please sign in to comment.