Skip to content

Commit 710cc7c

Browse files
author
Emily
committed
Merge branch 'dev' into task/add-pagination-component
2 parents 6511252 + 90964d2 commit 710cc7c

File tree

28 files changed

+633
-149
lines changed

28 files changed

+633
-149
lines changed

.storybook/lib/storiesFromMarkdown.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ const railsOcticonToReact = (html) => {
1919
return html
2020
}
2121

22-
const nodeToStory = (node, file) => {
23-
const html = railsOcticonToReact(node.value)
24-
const element = htmlParser.parse(html)
22+
const parseBlockAttrs = (node, file) => {
2523
const pairs = node.lang.replace(/^html\s*/, '')
2624
const attrs = pairs.length ? parsePairs(pairs) : {}
27-
const title = attrs.title || getPreviousHeading(node) ||
28-
`story @ ${file}:${node.position.start.line}`
25+
attrs.title = attrs.title
26+
|| getPreviousHeading(node)
27+
|| `story @ ${file}:${node.position.start.line}`
28+
node.block = attrs
29+
return node
30+
}
31+
32+
const nodeToStory = (node, file) => {
33+
const html = railsOcticonToReact(node.value)
34+
const {title} = node.block
2935
return {
3036
title,
31-
story: () => element,
32-
attrs,
37+
story: () => htmlParser.parse(html),
3338
html,
3439
file,
3540
node,
@@ -44,14 +49,17 @@ const getPreviousHeading = node => {
4449
}
4550

4651
export default req => {
47-
return req.keys().reduce((stories, file) => {
48-
const content = req(file)
49-
const ast = parents(remark.parse(content))
50-
const path = file.replace(/^\.\//, '')
51-
return stories.concat(
52-
select(ast, 'code[lang^=html]')
53-
.map(node => nodeToStory(node, path))
54-
.filter(({attrs}) => attrs.story !== "false")
55-
)
56-
}, [])
52+
return req.keys()
53+
.filter(file => !file.match(/node_modules/))
54+
.reduce((stories, file) => {
55+
const content = req(file)
56+
const ast = parents(remark.parse(content))
57+
const path = file.replace(/^\.\//, '')
58+
return stories.concat(
59+
select(ast, 'code[lang^=html]')
60+
.map(parseBlockAttrs)
61+
.filter(({block}) => block.story !== "false")
62+
.map(node => nodeToStory(node, path))
63+
)
64+
}, [])
5765
}

.storybook/webpack.config.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const path = require("path");
1+
const path = require('path');
22

3-
const modulesPath = path.resolve(__dirname, "../modules")
3+
const modulesPath = path.resolve(__dirname, '../modules')
44

55
module.exports = (config, env) => {
66

@@ -9,26 +9,34 @@ module.exports = (config, env) => {
99
.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin')
1010
}
1111

12-
config.module.rules.push(
13-
{
14-
test: /\.md$/,
15-
use: "raw-loader",
16-
},
12+
const rules = config.module.rules
13+
14+
rules.forEach((rule, index) => {
15+
if ('README.md'.match(rule.test)) {
16+
// console.warn('replacing MD rule:', rule)
17+
rules.splice(index, 1, {
18+
test: /\.md$/,
19+
loader: 'raw-loader',
20+
})
21+
}
22+
})
23+
24+
rules.push(
1725
{
1826
test: /\.scss$/,
1927
loaders: [
20-
"style-loader",
21-
"css-loader",
28+
'style-loader',
29+
'css-loader',
2230
{
23-
loader: "postcss-loader",
31+
loader: 'postcss-loader',
2432
options: {
2533
config: {
26-
path: require.resolve("./postcss.config.js"),
34+
path: require.resolve('./postcss.config.js'),
2735
},
2836
},
2937
},
3038
{
31-
loader: "sass-loader",
39+
loader: 'sass-loader',
3240
options: {
3341
includePaths: [
3442
modulesPath,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Then, you would import the module with:
4646
@import "primer-navigation/index.scss";
4747
```
4848

49-
Or, while you're figuring out which modules you need, you can import them directly from the `primer` [`packages` directory](./packages) like so:
49+
Or, while you're figuring out which modules you need, you can import them directly from the `primer` [`modules` directory](./modules) like so:
5050

5151
```scss
5252
@import "primer/modules/primer-navigation/index.css";

lerna.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"lerna": "2.4.0",
33
"packages": [
4+
"meta/*",
45
"modules/*",
56
"tools/*"
67
],

meta/scoreboard/index.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const {basename, join, resolve} = require('path')
2+
const PromiseQueue = require('p-queue')
3+
const execa = require('execa')
4+
const globby = require('globby')
5+
const rootDir = resolve(__dirname, '../..')
6+
const lernaConfig = require(join(rootDir, 'lerna.json'))
7+
const modulesDir = join(rootDir, 'modules')
8+
require('console.table')
9+
10+
const unique = list => Array.from(new Set(list)).sort()
11+
12+
const matchAll = (pattern, text) => {
13+
const matches = []
14+
let match
15+
while (match = pattern.exec(text)) {
16+
matches.push(match)
17+
}
18+
return matches
19+
}
20+
21+
const checks = {
22+
'has stories': (module, key) => {
23+
return globby(join(module.path, '**/stories.js'))
24+
.then(files => ({
25+
[key]: files.length > 0 ? 'yes' : 'no'
26+
}))
27+
},
28+
'docs test': (module, key) => {
29+
return execa(join(rootDir, 'script/test-docs'), {
30+
cwd: module.path
31+
})
32+
.then(result => ({[key]: 'pass'}))
33+
.catch(({stderr}) => {
34+
const pattern = /("\.[-\w]+") is not documented/g
35+
const matches = matchAll(pattern, stderr)
36+
.map(match => match[1])
37+
let missing = matches ? Array.from(matches) : []
38+
const max = 5
39+
if (missing.length > max) {
40+
const more = missing.length - max
41+
missing = missing.slice(0, max).concat(`and ${more} more...`)
42+
}
43+
return {
44+
[key]: 'FAIL',
45+
'missing docs': unique(missing).join(', ')
46+
}
47+
})
48+
}
49+
}
50+
51+
const args = process.argv.slice(2)
52+
53+
const modules = args.length
54+
? Promise.resolve(args)
55+
: globby(join(modulesDir, 'primer-*'))
56+
57+
modules
58+
.then(moduleDirs => {
59+
console.log('Found %d module directories', moduleDirs.length)
60+
return moduleDirs
61+
.map(path => ({
62+
path,
63+
name: basename(path),
64+
pkg: require(join(path, 'package.json'))
65+
}))
66+
.filter(({pkg}) => pkg.primer.module_type !== 'meta')
67+
})
68+
.then(modules => {
69+
console.log('Filtered to %d modules (excluding meta-packages)', modules.length)
70+
71+
const queue = new PromiseQueue({concurrency: 3})
72+
73+
for (const module of modules) {
74+
module.checks = {}
75+
for (const [name, check] of Object.entries(checks)) {
76+
queue.add(() => {
77+
// console.warn(`? check: ${module.name} ${name}`)
78+
return check(module, name)
79+
.then(result => {
80+
Object.assign(module.checks, result)
81+
})
82+
})
83+
}
84+
}
85+
86+
console.warn(`Running ${queue.size} checks...`)
87+
return queue.onIdle().then(() => modules)
88+
})
89+
.then(modules => {
90+
console.warn('ran tests on %d modules', modules.length)
91+
const rows = modules.map(({name, checks}) => {
92+
return Object.assign({'package': name}, checks)
93+
})
94+
console.table(rows)
95+
})
96+

meta/scoreboard/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "primer-scorecard",
4+
"scripts": {
5+
"test": "node index.js"
6+
},
7+
"devDependencies": {
8+
"console.table": "^0.10.0",
9+
"execa": "^0.10.0",
10+
"globby": "^6.1.0",
11+
"p-queue": "^2.4.2"
12+
}
13+
}

modules/primer-alerts/lib/flash.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
border-radius: 0;
7373
}
7474

75+
// FIXME deprecate this
7576
.warning {
7677
padding: $em-spacer-5;
7778
margin-bottom: 0.8em;

modules/primer-alerts/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"main": "build/index.js",
1111
"primer": {
1212
"category": "product",
13-
"module_type": "components"
13+
"module_type": "components",
14+
"class_whitelist": [
15+
"warning"
16+
]
1417
},
1518
"files": [
1619
"index.scss",

modules/primer-base/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"main": "build/index.js",
1111
"primer": {
1212
"category": "core",
13-
"module_type": "support"
13+
"module_type": "support",
14+
"class_whitelist": [
15+
"octicon",
16+
"rule"
17+
]
1418
},
1519
"files": [
1620
"index.scss",

modules/primer-marketing-utilities/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"main": "build/index.js",
1111
"primer": {
1212
"category": "marketing",
13-
"module_type": "utilities"
13+
"module_type": "utilities",
14+
"class_whitelist": [
15+
"border-??-*",
16+
"position-??-*"
17+
]
1418
},
1519
"files": [
1620
"index.scss",

0 commit comments

Comments
 (0)