Skip to content

Instantly share code, notes, and snippets.

View eps1lon's full-sized avatar
:atom:
mt?!" “ .I.r '2 f

Sebastian "Sebbie" Silbermann eps1lon

:atom:
mt?!" “ .I.r '2 f
View GitHub Profile
@eps1lon
eps1lon / MarkdonwPAge.template.js
Created April 19, 2020 15:34
codemod docs markdown build time
import React from 'react';
import %%COMPONENT%% from 'docs/src/modules/components/%%COMPONENT%%';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';
const pageFilename = 'blog/%%MARKDOWN_FILENAME%%';
const requireRaw = require.context('!raw-loader!./', false, /%%MARKDOWN_FILENAME%%\.md$/);
// eslint-disable-next-line react/prop-types
export default function Page({ docs }) {
return <%%COMPONENT%% docs={docs} />;
@eps1lon
eps1lon / matchers.js
Created April 14, 2020 09:27
chai jest-like expect
import chai from 'chai';
chai.use((chaiAPI, utils) => {
chai.Assertion.addMethod('toHaveLength', function toHaveLength(length) {
new chai.Assertion(this._obj).to.have.length(length);
});
});
@eps1lon
eps1lon / index.ink.js
Created March 28, 2020 20:38
mocha-cli-jest
const ChildProcess = require('child_process');
const Ink = require('ink');
const Path = require('path');
const React = require('react');
const workspaceRoot = Path.resolve(__dirname, '../../');
console.clear();
Ink.render(<Main />);
@eps1lon
eps1lon / generateProptypes.ts
Created March 23, 2020 22:55
resolve prop types of overrideable component
import * as path from 'path';
import * as fse from 'fs-extra';
import * as ttp from 'typescript-to-proptypes';
import * as prettier from 'prettier';
import * as globCallback from 'glob';
import { promisify } from 'util';
import * as _ from 'lodash';
import * as yargs from 'yargs';
import { fixBabelGeneratorIssues, fixLineEndings } from '../docs/scripts/helpers';
@eps1lon
eps1lon / codemod-pages.js
Last active November 2, 2019 13:48
Material-UI mdx docs
// Press ctrl+space for code completion
export default function transformer(fileInfo, api) {
const j = api.jscodeshift;
const ast = j(fileInfo.source);
let reqPrefix = null;
ast.findVariableDeclarators("reqPrefix").forEach(path => {
if (reqPrefix !== null) {
throw new Error("only one reqPrefix allowed");
}
const childProcess = require('child_process');
const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
const { promisify } = require('util');
/**
* prepares `@material-ui/*` packages to be published under a single verison
* that is based on the commit SHA of `HEAD`
*/
MAIN -> Group:+ {% ([groups]) => groups %}
Group -> Name GroupPr:? ":\n\n" Demos:* {% ([group, pr, , demos]) => ({ group, demos, pr }) %}
Demos -> " " Name Pr:? "\n" {% ([, name, pr]) => ({ name, pr }) %}
Pr -> " #" [0-9]:+ {% ([, pr]) => pr.join("") %}
GroupPr -> " ":? "(":? "#" [0-9]:+ ")":? {% ([, , ,pr]) => pr.join("") %}
Name -> [\(\) \w\-/]:+ {% ([s]) => s.join('') %}
With #13229 we got the proper infrastructure to present our demos both in JavaScript and TypeScript. We want to continue this effort with the goal to have all demos available in TypeScript.
If you want to make contributions to this repository and know a bit of TypeScript we would appreciate you helping us.
## Getting started
TL;DR: Use #14739, #14485 or #14535 as example workflows.
0. Set up your fork (See ['getting started"](https://github.com/mui-org/material-ui/blob/next/CONTRIBUTING.md#getting-started) in the contributing guide).
1. Choose a demo you want to convert. For this example, we'll use: https://next.material-ui.com/demos/lists/#nested-list
2. go to `./docs/src/pages/demos/lists/lists.md` and find the section. You're looking for a `{{ "demo": "some-path" }}` block:
// Press ctrl+space for code completion
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.CallExpression)
.filter(path => {
return path.get("callee").get("name").value === "warning";
})
.forEach(path => {