mirror of
https://github.com/primer/css.git
synced 2024-11-10 16:07:25 +03:00
Merge pull request #475 from primer/import-primer-module-build
Import primer-module-build to the monorepo
This commit is contained in:
commit
90964d2f9c
@ -12,7 +12,6 @@ env:
|
||||
- secure: "KcGydAqL7ryDh2rTJJB4wU8NE5BRtnrRXDEcPBScSscO3zFsHXHBDvvO04B/9hFVatXzGYXmkn+FZ0P9QikhvebzdwwyqUG2SKFiHhMvbX0m0WtAhn5NqDuKU1r5qy5YQ18r/tiLfC9GSAlEpfLAH58pwpcn8srV3Mn/yKvlrfs="
|
||||
|
||||
script:
|
||||
- cd meta/scoreboard; npm install; npm test
|
||||
- npm test
|
||||
|
||||
after_success:
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"lerna": "2.4.0",
|
||||
"packages": [
|
||||
"meta/*",
|
||||
"modules/*",
|
||||
"tools/*"
|
||||
],
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "primer-scorecard",
|
||||
"scripts": {
|
||||
"test": "node index.js"
|
||||
},
|
||||
|
11
package.json
11
package.json
@ -20,6 +20,10 @@
|
||||
"test": "npm run test-all-modules && lerna run test",
|
||||
"test-all-modules": "ava --verbose tests/test-*.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"primer-module-build": "file:tools/primer-module-build",
|
||||
"stylelint-config-primer": "file:tools/stylelint-config-primer"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@storybook/addon-options": "^3.2.6",
|
||||
"@storybook/react": "^3.2.12",
|
||||
@ -30,7 +34,7 @@
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"commit-status": "^4.1.0",
|
||||
"css-loader": "^0.28.4",
|
||||
"execa": "^0.8.0",
|
||||
"execa": "^0.10.0",
|
||||
"fs-extra": "^4.0.2",
|
||||
"gh-pages": "^1.0.0",
|
||||
"glob": "^7.1.2",
|
||||
@ -40,12 +44,12 @@
|
||||
"lerna": "2.4.0",
|
||||
"lerna-changelog": "^0.7.0",
|
||||
"minimatch": "^3.0.4",
|
||||
"node-sass": "^4.5.3",
|
||||
"node-sass": "^4.9.0",
|
||||
"npm-run-all": "^4.0.2",
|
||||
"npx": "^10.2.0",
|
||||
"octicons": "^6.0.1",
|
||||
"parse-pairs": "^0.2.2",
|
||||
"postcss-loader": "^2.0.6",
|
||||
"primer-module-build": "^1.0.2",
|
||||
"raw-loader": "^0.5.1",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
@ -55,7 +59,6 @@
|
||||
"semver": "^5.3.0",
|
||||
"style-loader": "^0.18.2",
|
||||
"stylelint": "^7.13.0",
|
||||
"stylelint-config-primer": "^2.0.0",
|
||||
"unist-util-find-before": "^2.0.1",
|
||||
"unist-util-parents": "^1.0.0",
|
||||
"unist-util-select": "^1.5.0",
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
$(dirname $0)/npm-run stylelint --quiet --syntax scss **/*.scss
|
||||
npx stylelint --quiet --syntax scss **/*.scss
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
$(dirname $0)/npm-run npm-run-all --serial --silent "$@"
|
||||
npx npm-run-all --serial --silent "$@"
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
$(dirname $0)/npm-run ava --verbose $(dirname $0)/../tests/modules/test-document-styles.js "$@"
|
||||
npx ava --verbose $(dirname $0)/../tests/modules/test-document-styles.js "$@"
|
14
tools/primer-module-build/.eslintrc.json
Normal file
14
tools/primer-module-build/.eslintrc.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"plugins": [
|
||||
"eslint-plugin-github"
|
||||
],
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"plugin:github/recommended",
|
||||
"plugin:github/es6"
|
||||
]
|
||||
}
|
||||
|
21
tools/primer-module-build/LICENSE
Normal file
21
tools/primer-module-build/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 GitHub Inc.
|
||||
|
||||
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.
|
29
tools/primer-module-build/cli.js
Executable file
29
tools/primer-module-build/cli.js
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
/* eslint-disable no-console */
|
||||
const meow = require('meow')
|
||||
const build = require('./')
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ primer-module-build [file]
|
||||
|
||||
File
|
||||
File. This is required. The file input is the .scss file that
|
||||
will be built into .css. The build automatically looks in the
|
||||
node_modules/ directory for any inputs.
|
||||
|
||||
Example
|
||||
$ primer-module-build index.scss
|
||||
`)
|
||||
|
||||
build(cli)
|
||||
.then(files => {
|
||||
console.warn('YES! wrote %d files:', files.length)
|
||||
for (const file of files) console.warn(file)
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('NO:', err)
|
||||
process.exit(1)
|
||||
})
|
19
tools/primer-module-build/index.js
Normal file
19
tools/primer-module-build/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
const build = require('./lib/build')
|
||||
|
||||
function InputException(message) {
|
||||
this.message = message
|
||||
this.name = "InputException"
|
||||
}
|
||||
|
||||
module.exports = ({input, flags}) => {
|
||||
if (!input || input.length === 0) {
|
||||
throw new InputException("You must supply a file to build")
|
||||
}
|
||||
|
||||
const [file] = input
|
||||
if (!file.match(/\.scss$/)) {
|
||||
throw new InputException("We are only able to handle .scss files")
|
||||
}
|
||||
|
||||
return build(file, flags)
|
||||
}
|
6
tools/primer-module-build/lib/.postcss.json
Normal file
6
tools/primer-module-build/lib/.postcss.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"use": ["autoprefixer"],
|
||||
"autoprefixer": {
|
||||
"browsers": "> 5%, last 2 firefox versions, last 2 chrome versions, last 2 safari versions, last 2 edge versions, ie 11"
|
||||
}
|
||||
}
|
69
tools/primer-module-build/lib/build.js
Normal file
69
tools/primer-module-build/lib/build.js
Normal file
@ -0,0 +1,69 @@
|
||||
const {isAbsolute} = require('path')
|
||||
const cssstats = require('cssstats')
|
||||
const fse = require('fs-extra')
|
||||
const nodeSassImport = require('node-sass-import')
|
||||
const postcss = require('postcss')
|
||||
const promisify = require('pify')
|
||||
const sass = require('node-sass')
|
||||
|
||||
const sassRender = promisify(sass.render)
|
||||
|
||||
function arrayify(value) {
|
||||
return Array.isArray(value) ? value : [value]
|
||||
}
|
||||
|
||||
module.exports = (src, flags = {}) => {
|
||||
|
||||
const cwd = process.cwd()
|
||||
const sourceFile = isAbsolute(src) ? src : `${cwd}/${src}`
|
||||
const outputDir = flags.outputDir || `${cwd}/build`
|
||||
const outputFile = flags.output || `${outputDir}/build.css`
|
||||
const outputJSFile = flags.outputJS || `${outputDir}/index.js`
|
||||
const outputDataFile = flags.outputData || `${outputDir}/data.json`
|
||||
|
||||
const sassOptions = {
|
||||
file: sourceFile,
|
||||
outputStyle: flags.outputStyle || 'compressed',
|
||||
importer: nodeSassImport,
|
||||
includePaths: arrayify(flags.include)
|
||||
}
|
||||
|
||||
// console.warn('sass options:', sassOptions)
|
||||
|
||||
return fse.mkdirp(outputDir)
|
||||
.then(() => sassRender(sassOptions))
|
||||
.then(({css}) => {
|
||||
function postcssPlugins() {
|
||||
const postcssrc = (() => {
|
||||
if (flags.postcssconfig && fse.existsSync(`${cwd}/${flags.postcssconfig}`)) {
|
||||
return require(`${cwd}/${flags.postcssconfig}`)
|
||||
} else if (fse.existsSync(`${cwd}/.postcss.json`)) {
|
||||
return require(`${cwd}/.postcss.json`)
|
||||
} else {
|
||||
return require('./.postcss.json')
|
||||
}
|
||||
})()
|
||||
return postcssrc.use.map(name => {
|
||||
return require(name)(postcssrc[name])
|
||||
})
|
||||
}
|
||||
return postcss(postcssPlugins())
|
||||
.process(css, {
|
||||
from: sourceFile,
|
||||
to: outputFile
|
||||
})
|
||||
})
|
||||
.then(result => {
|
||||
const data = {
|
||||
cssstats: cssstats(result.css)
|
||||
}
|
||||
const json = JSON.stringify(data)
|
||||
|
||||
return Promise.all([
|
||||
fse.writeFile(outputFile, result.css),
|
||||
fse.writeFile(outputJSFile, `module.exports = ${json}`),
|
||||
fse.writeFile(outputDataFile, json)
|
||||
])
|
||||
.then(() => [outputFile, outputJSFile, outputDataFile])
|
||||
})
|
||||
}
|
49
tools/primer-module-build/package.json
Normal file
49
tools/primer-module-build/package.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"version": "1.0.2",
|
||||
"name": "primer-module-build",
|
||||
"description": "Scripts to build primer SCSS modules into CSS and stats",
|
||||
"homepage": "http://primercss.io/",
|
||||
"author": "GitHub, Inc.",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js",
|
||||
"cli.js",
|
||||
"lib"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/primer/primer-module-build.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/primer/primer-module-build/issues"
|
||||
},
|
||||
"bin": "cli.js",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"ava": "../../script/npm-run ava --verbose \"tests/**/*.js\"",
|
||||
"lint": "../../script/npm-run eslint lib/**/*.js *.js tests/**/*.js",
|
||||
"test": "../../script/npm-run-all lint ava"
|
||||
},
|
||||
"keywords": [
|
||||
"primer",
|
||||
"build",
|
||||
"css",
|
||||
"postcss",
|
||||
"node-sass"
|
||||
],
|
||||
"dependencies": {
|
||||
"autoprefixer": "^6.7.7",
|
||||
"cssstats": "^3.2.0",
|
||||
"meow": "^3.7.0",
|
||||
"node-sass": "^4.9.0",
|
||||
"node-sass-import": "^2.0.0",
|
||||
"pify": "^3.0.0",
|
||||
"postcss": "^5.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"primer-utilities": "4.9.0",
|
||||
"tempy": "^0.2.1"
|
||||
}
|
||||
}
|
1
tools/primer-module-build/tests/fixtures/primer-package.scss
vendored
Normal file
1
tools/primer-module-build/tests/fixtures/primer-package.scss
vendored
Normal file
@ -0,0 +1 @@
|
||||
@import "primer-utilities/index.scss";
|
1
tools/primer-module-build/tests/fixtures/relative.scss
vendored
Normal file
1
tools/primer-module-build/tests/fixtures/relative.scss
vendored
Normal file
@ -0,0 +1 @@
|
||||
@import "./primer-package.scss"
|
33
tools/primer-module-build/tests/index.js
Normal file
33
tools/primer-module-build/tests/index.js
Normal file
@ -0,0 +1,33 @@
|
||||
const build = require('../lib/build.js')
|
||||
const test = require('ava')
|
||||
const tempy = require('tempy')
|
||||
const {exists} = require('fs-extra')
|
||||
const {join} = require('path')
|
||||
|
||||
function fixture(...path) {
|
||||
return join(__dirname, 'fixtures', ...path)
|
||||
}
|
||||
|
||||
function assertExists(t, filename) {
|
||||
return exists(filename)
|
||||
.then(exists => {
|
||||
exists ? t.pass() : t.fail(`No such file: ${filename}`)
|
||||
})
|
||||
}
|
||||
|
||||
test('resolves npm-installed primer package', t => {
|
||||
return build(fixture('primer-package.scss'), {})
|
||||
.then(() => t.pass())
|
||||
})
|
||||
|
||||
test('resolves relative paths', t => {
|
||||
return build(fixture('relative.scss'), {})
|
||||
.then(() => t.pass())
|
||||
})
|
||||
|
||||
test('writes build.css by default', t => {
|
||||
const outputDir = tempy.directory()
|
||||
const outputFile = join(outputDir, 'build.css')
|
||||
return build(fixture('primer-package.scss'), {outputDir})
|
||||
.then(() => assertExists(t, outputFile))
|
||||
})
|
Loading…
Reference in New Issue
Block a user