Skip to content

Commit

Permalink
feat: initial (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Aug 17, 2018
1 parent 66f2e27 commit 33abf3c
Show file tree
Hide file tree
Showing 9 changed files with 6,196 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# OS
Thumbs.db
ehthumbs.db
Desktop.ini
.DS_Store
._*

# Editors
*~
*.swp
*.tmproj
*.tmproject
*.sublime-*
.idea/
.project/
.settings/
.vscode/

# Logs
logs
*.log
npm-debug.log*

# Dependency directories
node_modules/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo: false
dist: trusty
language: node_js
node_js:
- 'lts/*'
before_install:
- npm install -g greenkeeper-lockfile@1
before_script:
- greenkeeper-lockfile-update
after_script: greenkeeper-lockfile-upload

Empty file added CHANGELOG.md
Empty file.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright Brightcove, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,62 @@
# videojs-generate-postcss-config
videojs-generate-postcss-config

[![Build Status](https://travis-ci.org/videojs/videojs-generate-postcss-config.svg?branch=master)](https://travis-ci.org/videojs/videojs-generate-postcss-config)
[![Greenkeeper badge](https://badges.greenkeeper.io/videojs/videojs-generate-postcss-config.svg)](https://greenkeeper.io/)
[![Slack Status](http://slack.videojs.com/badge.svg)](http://slack.videojs.com)

[![NPM](https://nodei.co/npm/videojs-generate-postcss-config.png?downloads=true&downloadRank=true)](https://nodei.co/npm/videojs-generate-postcss-config/)

Currently our postcss configs are the same for most plugins, but when the default config changes a bit, every repository has
to be updated since it is a static file. This package will provide the standard config as a module, so that updates can be
deployed much easier.

Lead Maintainer: Brandon Casey [@brandonocasey](https://github.com/brandonocasey)

Maintenance Status: Stable


<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Installation](#installation)
- [Options](#options)
- [`browserslist`](#browserslist)
- [`banner`](#banner)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Installation

```
$ npm install --save-dev postcss-cli videojs-generate-postcss-config
```

Then in your postcss config do

```js
const generatePostcssConfig = require('videojs-generate-postcss-config');

module.exports = function(context) {
const options = {};

return generatePostcssConfig(context, options);
};
```

## Options
options that are passed as an object to the `generatePostcssConfig` function.

### `browserslist`

> Type: `string|Array`
> Default: ['defaults', 'ie 11']
What browser syntax should be supported in the browser/test dist files. Can also be specified in the package.json as a top level `browserslist` key/value. See the [browserslist repo](https://github.com/browserslist/browserslist) for more information.

### `banner`

> Type: `string`
> Default: `/*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */`
The banner that should be inserted to the top of all bundles. You probably should not change this from the default!
70 changes: 70 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const path = require('path');
const progress = require('postcss-progress');

const getSettings = function(options) {
const pkg = require(path.join(process.cwd(), 'package.json'));

const settings = {
banner: options.banner || `@name ${pkg.name} @version ${pkg.version} @license ${pkg.license}`,
browserslist: options.banner || pkg.browserslist || ['defaults', 'ie 11']
};

settings.plugins = [
// set the startTime so that we can print the end time
progress.start(),

// inlines local file imports
require('postcss-import')(),

// allows you to use newer css features, by converting
// them into something browsers can support now.
// see https://preset-env.cssdb.org/features
// by default we use stage 3+
require('postcss-preset-env')({
browsers: settings.browserslist,
stage: false,
features: {
// turn `var(xyz)` into the actual value
'custom-properties': {preserve: false, warnings: true},

// flatten nested rules
'nesting-rules': true
}
}),

// adds a banner to the top of the file
require('postcss-banner')({important: true, inline: true, banner: settings.banner}),

// add/remove vendor prefixes based on browser list
require('autoprefixer')(settings.browserslist),

// minify
require('cssnano')({
safe: true,
preset: ['default', {
autoprefixer: settings.browserslist
}]
}),

progress.stop()
];

if (options.plugins) {
settings.plugins = options.plugins(settings.plugins);
}

return settings;
};

module.exports = function(context, options) {
const settings = getSettings(options);

context.opts = {
to: `dist/${settings.distName}.css`,
from: settings.input
};

return {
plugins: settings.plugins
};
};
Loading

0 comments on commit 33abf3c

Please sign in to comment.