mirror of
https://github.com/primer/css.git
synced 2024-11-28 04:43:05 +03:00
stub out site directory
This commit is contained in:
parent
9990e6ff19
commit
3dfb929839
2
site/.gitignore
vendored
Normal file
2
site/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.next/
|
||||
pages/**/*.md
|
31
site/lib/add-package-meta.js
Normal file
31
site/lib/add-package-meta.js
Normal file
@ -0,0 +1,31 @@
|
||||
const each = require('./each')
|
||||
const {existsSync} = require('fs')
|
||||
const {dirname, join, resolve} = require('path')
|
||||
|
||||
const cache = {}
|
||||
|
||||
module.exports = function addPackageMeta(options) {
|
||||
return (files, metal, done) => {
|
||||
const root = metal.source()
|
||||
for (const [path, file] of Object.entries(files)) {
|
||||
file.package = getPackageRelativeTo(path, root)
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
function getPackageRelativeTo(path, root) {
|
||||
const pathDir = join(root, dirname(path))
|
||||
if (pathDir in cache) {
|
||||
return cache[pathDir]
|
||||
}
|
||||
let dir = pathDir
|
||||
while (dir !== root) {
|
||||
const pkgPath = join(dir, 'package.json')
|
||||
if (existsSync(pkgPath)) {
|
||||
return cache[dir] = require(pkgPath)
|
||||
}
|
||||
dir = resolve(dir, '..')
|
||||
}
|
||||
console.warn('no package.json found:', dir)
|
||||
}
|
9
site/lib/each.js
Normal file
9
site/lib/each.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = function each(fn) {
|
||||
return (files, metal, done) => {
|
||||
for (const [path, file] of Object.entries(files)) {
|
||||
fn(path, file, files, metal)
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
28
site/lib/parse-doc-comments.js
Normal file
28
site/lib/parse-doc-comments.js
Normal file
@ -0,0 +1,28 @@
|
||||
const each = require('./each')
|
||||
|
||||
const START = /<\!-- *%docs *\n/
|
||||
const SPLIT = /\n *-->/
|
||||
const END = /<\!-- *%enddocs *-->/
|
||||
|
||||
module.exports = function parseDocComments() {
|
||||
return each((path, file) => {
|
||||
const str = String(file.contents)
|
||||
let parts = str.split(START)
|
||||
if (parts.length > 1) {
|
||||
// FIXME metadata should either be in frontmatter or %docs comment
|
||||
if (str.match(/^---/)) {
|
||||
throw new Error(`Whoops, can't parse doc comments *and* frontmatter!`)
|
||||
}
|
||||
|
||||
// take the part between the start and end
|
||||
const middle = parts[1].split(END)[0]
|
||||
// split *that* on the split "marker"
|
||||
parts = middle.split(SPLIT)
|
||||
// the part before that is the "frontmatter"
|
||||
// and everything after that is the actual docs
|
||||
const [meta, docs] = parts
|
||||
file.contents = Buffer.from(`---\n${meta}\n---\n${docs}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
48
site/lib/rename.js
Normal file
48
site/lib/rename.js
Normal file
@ -0,0 +1,48 @@
|
||||
const minimatch = require('minimatch')
|
||||
|
||||
module.exports = function rename(patterns, debug) {
|
||||
const ops = Object.keys(patterns).map(pattern => {
|
||||
const match = path => minimatch(path, pattern)
|
||||
const getPath = compile(patterns[pattern], pattern)
|
||||
return (path, file, files) => {
|
||||
if (!match(path)) return
|
||||
|
||||
const newPath = getPath(path, file, pattern)
|
||||
if (newPath === false) {
|
||||
delete files[path]
|
||||
return
|
||||
} else if (newPath === path) {
|
||||
return
|
||||
}
|
||||
|
||||
// debug && console.warn('-', path)
|
||||
delete files[path]
|
||||
if (newPath) {
|
||||
debug && console.warn('*', path, '->', newPath)
|
||||
files[newPath] = file
|
||||
file.path = newPath
|
||||
}
|
||||
}
|
||||
})
|
||||
return (files, metal, done) => {
|
||||
for (const op of ops) {
|
||||
for (const [path, file] of Object.entries(files)) {
|
||||
op(path, file, files)
|
||||
}
|
||||
}
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
const noop = () => undefined
|
||||
|
||||
function compile(filename, pattern) {
|
||||
switch (typeof filename) {
|
||||
case 'function':
|
||||
return filename
|
||||
case 'string':
|
||||
return () => filename
|
||||
default:
|
||||
return noop
|
||||
}
|
||||
}
|
26
site/map.js
Normal file
26
site/map.js
Normal file
@ -0,0 +1,26 @@
|
||||
const {basename} = require('path')
|
||||
|
||||
module.exports = {
|
||||
'primer/README.md': 'packages/primer.md',
|
||||
'primer-base/README.md': false, // FIXME: 'support/base.md'?
|
||||
'primer-core/README.md': 'packages/primer-core.md',
|
||||
'primer-layout/README.md': 'objects/layout.md',
|
||||
'primer-layout/docs/*.md': path => `objects/${basename(path)}`,
|
||||
'primer-marketing-support/README.md': 'support/marketing-variables.md',
|
||||
'primer-marketing-type/README.md': 'utilities/marketing-type.md',
|
||||
'primer-marketing-utilities/README.md': false,
|
||||
'primer-marketing-utilities/docs/*.md': path => `utilities/marketing-${basename(path)}`,
|
||||
'primer-marketing/README.md': 'packages/primer-marketing.md',
|
||||
'primer-product/README.md': 'packages/primer-product.md',
|
||||
'primer-support/README.md': false, // 'support/index.md',
|
||||
'primer-support/docs/*.md': path => `support/${basename(path)}`,
|
||||
'primer-table-object/README.md': 'objects/table-object.md',
|
||||
'primer-utilities/README.md': false, // 'utilities/index.md',
|
||||
'primer-utilities/docs/*.md': path => `utilities/${basename(path)}`,
|
||||
// this is a catch-all rule that needs to go last so that it doesn't override others
|
||||
'primer-*/README.md': path => `components/${shortName(path)}.md`,
|
||||
}
|
||||
|
||||
function shortName(path) {
|
||||
return path.match(/primer-([-\w]+)/)[1]
|
||||
}
|
56
site/metalsmith.js
Normal file
56
site/metalsmith.js
Normal file
@ -0,0 +1,56 @@
|
||||
const Metalsmith = require('metalsmith')
|
||||
const filter = require('metalsmith-filter')
|
||||
const watch = require('metalsmith-watch')
|
||||
const frontmatter = require('metalsmith-matters')
|
||||
const {basename, join, resolve} = require('path')
|
||||
const each = require('./lib/each')
|
||||
const parseDocComments = require('./lib/parse-doc-comments')
|
||||
const rename = require('./lib/rename')
|
||||
const addPackageMeta = require('./lib/add-package-meta')
|
||||
const fileMap = require('./map')
|
||||
|
||||
Metalsmith(__dirname)
|
||||
.source('../modules')
|
||||
.destination('pages')
|
||||
// disable Metalsmith's built-in frontmatter parser
|
||||
.frontmatter(false)
|
||||
.clean(true)
|
||||
// only match these patterns
|
||||
.use(filter([
|
||||
'*/README.md',
|
||||
'*/docs/*.md'
|
||||
]))
|
||||
// strip content before <!-- %docs {meta} --> and after <!-- %enddocs -->,
|
||||
// then rewrite the file contents with the {meta} bit as YAML frontmatter
|
||||
.use(parseDocComments())
|
||||
// then parse frontmatter into each file's .page
|
||||
.use(frontmatter({
|
||||
namespace: 'page'
|
||||
}))
|
||||
// find the closest package.json and set its contents as the 'package'
|
||||
// key on each file
|
||||
.use(addPackageMeta())
|
||||
.use(each((path, file) => {
|
||||
const pkg = file.package
|
||||
const module = pkg.name
|
||||
const shortName = module.replace(/^primer-/, '')
|
||||
file.page = Object.assign({
|
||||
title: titleCase(shortName),
|
||||
name: shortName,
|
||||
description: pkg.description,
|
||||
source: `https://github.com/primer/primer/tree/master/${path}`
|
||||
}, file.page)
|
||||
}))
|
||||
.use(rename(fileMap))
|
||||
.build(error => {
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
})
|
||||
|
||||
function titleCase(str) {
|
||||
return str.split('-')
|
||||
.map(word => word.charAt(0).toUpperCase() + word.substr(1))
|
||||
.join(' ')
|
||||
}
|
||||
|
11
site/next.config.js
Normal file
11
site/next.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
|
||||
exportPathMap(defaultPathMap) {
|
||||
return Object.assign(defaultPathMap, {
|
||||
})
|
||||
},
|
||||
|
||||
webpack(config, {dev, isServer}) {
|
||||
return config
|
||||
},
|
||||
}
|
6683
site/package-lock.json
generated
Normal file
6683
site/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
site/package.json
Normal file
22
site/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"predev": "npm run prebuild",
|
||||
"dev": "next dev",
|
||||
"prebuild": "node metalsmith.js",
|
||||
"build": "next build",
|
||||
"start": "next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@primer/components": "^4.0.0-beta",
|
||||
"metalsmith": "^2.3.0",
|
||||
"metalsmith-filter": "^1.0.2",
|
||||
"metalsmith-matters": "^1.2.0",
|
||||
"metalsmith-watch": "^1.0.3",
|
||||
"minimatch": "^3.0.4",
|
||||
"next": "^7.0.2",
|
||||
"react": "^16.5.2",
|
||||
"react-dom": "^16.5.2",
|
||||
"recompose": "^0.30.0"
|
||||
}
|
||||
}
|
6
site/pages/_app.js
Normal file
6
site/pages/_app.js
Normal file
@ -0,0 +1,6 @@
|
||||
import React from 'react'
|
||||
import App from 'next/app'
|
||||
import {nest} from 'recompose'
|
||||
import {BaseStyles} from '@primer/components'
|
||||
|
||||
export default nest(App, BaseStyles)
|
8
site/pages/index.js
Normal file
8
site/pages/index.js
Normal file
@ -0,0 +1,8 @@
|
||||
import React from 'react'
|
||||
import {Box} from '@primer/components'
|
||||
|
||||
export default () => (
|
||||
<Box p={4}>
|
||||
Hello, world!
|
||||
</Box>
|
||||
)
|
Loading…
Reference in New Issue
Block a user