mirror of
https://github.com/primer/css.git
synced 2024-11-27 17:52:45 +03:00
wrap up script/copy w/ --watch flag, add watching to next.config.js
This commit is contained in:
parent
29ef33801a
commit
8132c0c330
@ -6,11 +6,36 @@ const {basename, dirname, join} = require('path')
|
||||
const {copySync, ensureDirSync, removeSync, writeFileSync} = require('fs-extra')
|
||||
const {getIgnored, setIgnored} = require('./ignore')
|
||||
|
||||
const sourceDir = join(__dirname, '../../modules')
|
||||
const destDir = join(__dirname, '../pages/css')
|
||||
const ignoreFile = join(destDir, '.gitignore')
|
||||
|
||||
const map = {
|
||||
'../CHANGELOG.md': 'whats-new/changelog.md',
|
||||
'primer/README.md': false, // 'packages/primer.md',
|
||||
'primer-base/README.md': false, // 'support/base.md',
|
||||
'primer-core/README.md': false, // '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, // 'utilities/marketing.md',
|
||||
'primer-marketing-utilities/docs/*.md': path => `utilities/marketing-${basename(path)}`,
|
||||
'primer-marketing/README.md': false, // 'packages/primer-marketing.md',
|
||||
'primer-product/README.md': false, // '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`,
|
||||
}
|
||||
|
||||
module.exports = {sync, watch}
|
||||
|
||||
function sync({sourceDir, destDir, map, debug = false}) {
|
||||
function sync({debug = false}) {
|
||||
const log = debug ? console.warn : noop
|
||||
const ignoreFile = join(destDir, '.gitignore')
|
||||
const ignored = getIgnored(ignoreFile)
|
||||
for (const file of ignored) {
|
||||
log(`${yellow('x')} removing: ${file}`)
|
||||
@ -26,19 +51,24 @@ function sync({sourceDir, destDir, map, debug = false}) {
|
||||
}
|
||||
|
||||
function watch(options) {
|
||||
const globs = Object.keys(map).map(path => join(sourceDir, path))
|
||||
const {debug = false} = options
|
||||
const keys = Object.keys(map)
|
||||
const globs = keys.map(path => join(sourceDir, path))
|
||||
const log = debug ? console.warn : noop
|
||||
let timeout
|
||||
const update = path => {
|
||||
if (timeout) return
|
||||
timeout = setTimeout(() => {
|
||||
copySync(options)
|
||||
log(`${yellow('changed')} ${path}`)
|
||||
sync(options)
|
||||
clearTimeout(timeout)
|
||||
timeout = null
|
||||
}, 50)
|
||||
}
|
||||
console.warn(`watching: ${globs.map(g => yellow(g)).join(', ')}`)
|
||||
sync(options)
|
||||
log(`watching in ${yellow(sourceDir)}: ${keys.join(', ')}`)
|
||||
return chokidar.watch(globs)
|
||||
.on('add', update)
|
||||
// .on('add', update)
|
||||
.on('change', update)
|
||||
.on('unlink', update)
|
||||
}
|
||||
@ -104,5 +134,9 @@ function getLinks(sourceDir, destDir, map) {
|
||||
}))
|
||||
}
|
||||
|
||||
function shortName(path) {
|
||||
return path.match(/primer-([-\w]+)/)[1]
|
||||
}
|
||||
|
||||
function noop() {
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
// this runs synchronously
|
||||
// require('./copy')
|
||||
|
||||
const {join, resolve} = require('path')
|
||||
const withPlugins = require('next-compose-plugins')
|
||||
const configure = require('./lib/config')
|
||||
const css = require('@zeit/next-css')
|
||||
const sass = require('@zeit/next-sass')
|
||||
const configure = require('./lib/config')
|
||||
|
||||
const {NODE_ENV, NOW_URL} = process.env
|
||||
|
||||
if (!NOW_URL) {
|
||||
const {watch} = require('./lib/sync')
|
||||
const watcher = watch({debug: true})
|
||||
process.on('exit', () => watcher.close())
|
||||
}
|
||||
|
||||
const assetPrefix = NOW_URL || ''
|
||||
|
||||
module.exports = withPlugins([
|
||||
|
@ -6,7 +6,8 @@
|
||||
"lint": "eslint pages src",
|
||||
"test": "./test.sh",
|
||||
"dev": "next",
|
||||
"copy": "node copy.js",
|
||||
"copy": "script/copy",
|
||||
"watch": "script/copy --watch",
|
||||
"prebuild": "rm -rf .next",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
@ -19,6 +20,7 @@
|
||||
"@zeit/next-css": "^1.0.1",
|
||||
"@zeit/next-sass": "^1.0.1",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"chokidar": "^2.0.4",
|
||||
"chroma-js": "^1.4.1",
|
||||
"colorette": "^1.0.7",
|
||||
"emotion": "9.2.8",
|
||||
|
@ -3,34 +3,8 @@ const {basename, join} = require('path')
|
||||
const {sync, watch} = require('../lib/sync')
|
||||
const args = process.argv.slice(2)
|
||||
|
||||
const sourceDir = join(__dirname, '../../modules')
|
||||
const destDir = join(__dirname, '../pages/css')
|
||||
|
||||
const options = {
|
||||
sourceDir,
|
||||
destDir,
|
||||
debug: !args.includes('--quiet'),
|
||||
map: {
|
||||
'../CHANGELOG.md': 'whats-new/changelog.md',
|
||||
'primer/README.md': false, // 'packages/primer.md',
|
||||
'primer-base/README.md': false, // 'support/base.md',
|
||||
'primer-core/README.md': false, // '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, // 'utilities/marketing.md',
|
||||
'primer-marketing-utilities/docs/*.md': path => `utilities/marketing-${basename(path)}`,
|
||||
'primer-marketing/README.md': false, // 'packages/primer-marketing.md',
|
||||
'primer-product/README.md': false, // '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`,
|
||||
}
|
||||
debug: !args.includes('--quiet')
|
||||
}
|
||||
|
||||
if (args.includes('--watch')) {
|
||||
@ -39,7 +13,3 @@ if (args.includes('--watch')) {
|
||||
} else {
|
||||
sync(options)
|
||||
}
|
||||
|
||||
function shortName(path) {
|
||||
return path.match(/primer-([-\w]+)/)[1]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user