Comparing version 1.0.0 to 2.0.0
135
index.js
@@ -6,3 +6,6 @@ 'use strict'; | ||
var detab = require('detab'); | ||
var getDirName = require('path').dirname; | ||
var path = require('path'); | ||
var getDirName = path.dirname; | ||
var join = path.join; | ||
var deepAssign = require('deep-extend'); | ||
var Q = require('q'); | ||
@@ -13,23 +16,59 @@ var mkdirp = Q.denodeify(require('mkdirp')); | ||
var templatesDir = 'templates/'; | ||
var stylesDir = 'styles/'; | ||
var scriptsDir = 'scripts/'; | ||
var templatesDir = 'templates'; | ||
var defaults = { | ||
html: { | ||
file: 'index', | ||
type: 'html', // or 'jade' | ||
}, | ||
styles: { | ||
folder: 'styles', | ||
file: 'main', | ||
type: 'css', // or 'scss', 'sass', 'less', 'styl' | ||
}, | ||
scripts: { | ||
folder: 'scripts', | ||
file: 'main', | ||
type: 'js', // or 'babel', 'coffee' | ||
}, | ||
babelPolyfill: false, | ||
normalizeCss: false, | ||
whitespaceFormatting: 'tabs', | ||
} | ||
var fileMap = { | ||
html: { | ||
html: 'index.html', | ||
jade: 'index.jade', | ||
html: function(name) { return (name || defaults.html.file) + '.html' }, | ||
jade: function(name) { return (name || defaults.html.file) + '.jade' }, | ||
}, | ||
styles: { | ||
css: stylesDir + 'main.css', | ||
less: stylesDir + 'main.less', | ||
sass: stylesDir + 'main.sass', | ||
scss: stylesDir + 'main.scss', | ||
styl: stylesDir + 'main.styl', | ||
css: function(name, dir) { | ||
return join((dir || defaults.styles.folder), (name || defaults.styles.file) + '.css'); | ||
}, | ||
less: function(name, dir) { | ||
return join((dir || defaults.styles.folder), (name || defaults.styles.file) + '.less'); | ||
}, | ||
sass: function(name, dir) { | ||
return join((dir || defaults.styles.folder), (name || defaults.styles.file) + '.sass'); | ||
}, | ||
scss: function(name, dir) { | ||
return join((dir || defaults.styles.folder), (name || defaults.styles.file) + '.scss'); | ||
}, | ||
styl: function(name, dir) { | ||
return join((dir || defaults.styles.folder), (name || defaults.styles.file) + '.styl'); | ||
}, | ||
}, | ||
scripts: { | ||
js: scriptsDir + 'main.js', | ||
babel: scriptsDir + 'main.babel.js', | ||
coffee: scriptsDir + 'main.coffee', | ||
ts: scriptsDir + 'main.ts' | ||
js: function(name, dir) { | ||
return join((dir || defaults.scripts.folder), (name || defaults.scripts.file) + '.js') | ||
}, | ||
babel: function(name, dir) { | ||
return join((dir || defaults.scripts.folder), (name || defaults.scripts.file) + '.babel.js') | ||
}, | ||
coffee: function(name, dir) { | ||
return join((dir || defaults.scripts.folder), (name || defaults.scripts.file) + '.coffee') | ||
}, | ||
ts: function(name, dir) { | ||
return join((dir || defaults.scripts.folder), (name || defaults.scripts.file) + '.ts') | ||
}, | ||
}, | ||
@@ -43,17 +82,27 @@ babelPolyfill: 'babel-polyfill/dist/polyfill.js', | ||
* @param {string} projectDir Directory to scaffold the generated project to | ||
* @param {Object} options { | ||
* html: 'html', // Languages to use for html: 'html', 'jade' | ||
* styles: 'css', // Languages to use for styles: 'css', 'scss', 'sass', 'less', 'styl' | ||
* scripts: 'js', // Languages to use for scripts: 'js', 'babel', 'coffee' | ||
* babelPolyfill: undefined, // Boolean | ||
* normalizeCss: undefined, // Boolean, | ||
* whitespaceFormatting: 'tabs', // Pass in a number (e.g. 2) to use spaces for whitespace, otherwise tabs will be used | ||
* } | ||
* @param {Object} options | ||
* { | ||
* html: { | ||
* file: 'index', | ||
* type: 'html', // or 'jade' | ||
* }, | ||
* styles: { | ||
* folder: 'styles', | ||
* file: 'main', | ||
* type: 'css', // or 'scss', 'sass', 'less', 'styl' | ||
* }, | ||
* scripts: { | ||
* folder: 'scripts', | ||
* file: 'main', | ||
* type: 'js', // or 'babel', 'coffee' | ||
* }, | ||
* babelPolyfill: true/false, // include babel polyfill? | ||
* normalizeCss: true/false, // include CSS normalizer file? | ||
* whitespaceFormatting: 'tabs', // Pass in a number (e.g. 2) to use spaces for whitespace, otherwise tabs will be used | ||
* } | ||
* | ||
* @return {Promise<Array[string]>} Files created during scaffolding | ||
*/ | ||
module.exports = function barnyard(projectDir, options) { | ||
options = typeof options === 'object' ? options : {}; | ||
options.html = options.html || 'html'; | ||
options.styles = options.styles || 'css'; | ||
options.scripts = options.scripts || 'js'; | ||
options = deepAssign({}, defaults, options); | ||
@@ -81,23 +130,27 @@ function formatOutputObject(inputFile, outputFilename, requiresTemplating) { | ||
function getTemplateFile(filename, requiresTemplating) { | ||
var inputFile = readFile(templatesDir + filename, 'utf8'); | ||
return formatOutputObject(inputFile, filename, requiresTemplating); | ||
function getTemplateFile(inputFilename, outputFilename, requiresTemplating) { | ||
var inputFile = readFile(join(templatesDir, inputFilename), 'utf8'); | ||
return formatOutputObject(inputFile, outputFilename, requiresTemplating); | ||
} | ||
function prepareHtml() { | ||
var htmlLang = options.html; | ||
var filename = fileMap.html[htmlLang]; | ||
return getTemplateFile(filename, true); // HTML files require templating through marked.js | ||
var htmlLang = options.html.type; | ||
var inputFilename = fileMap.html[htmlLang](); | ||
var outputFilename = fileMap.html[htmlLang](options.html.file); | ||
// HTML files require templating through marked.js so add `true` param | ||
return getTemplateFile(inputFilename, outputFilename, true); | ||
} | ||
function prepareStyles() { | ||
var cssLang = options.styles; | ||
var filename = fileMap.styles[cssLang]; | ||
return getTemplateFile(filename); | ||
var cssLang = options.styles.type; | ||
var inputFilename = fileMap.styles[cssLang](); | ||
var outputFilename = fileMap.styles[cssLang](options.styles.file, options.styles.folder); | ||
return getTemplateFile(inputFilename, outputFilename); | ||
} | ||
function prepareScripts() { | ||
var scriptsLang = options.scripts; | ||
var filename = fileMap.scripts[scriptsLang]; | ||
return getTemplateFile(filename); | ||
var scriptsLang = options.scripts.type; | ||
var inputFilename = fileMap.scripts[scriptsLang](); | ||
var outputFilename = fileMap.scripts[scriptsLang](options.scripts.file, options.scripts.folder); | ||
return getTemplateFile(inputFilename, outputFilename); | ||
} | ||
@@ -111,6 +164,6 @@ | ||
if (options.babelPolyfill) { | ||
files.push(copyModuleFileAs(fileMap.babelPolyfill, scriptsDir + 'polyfill.js')); | ||
files.push(copyModuleFileAs(fileMap.babelPolyfill, join(options.scripts.folder, 'polyfill.js'))); | ||
} | ||
if (options.normalizeCss) { | ||
files.push(copyModuleFileAs(fileMap.normalizeCss, stylesDir + 'normalize.css')); | ||
files.push(copyModuleFileAs(fileMap.normalizeCss, join(options.styles.folder, 'normalize.css'))); | ||
} | ||
@@ -117,0 +170,0 @@ |
{ | ||
"name": "barnyard", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Bootstrap/Scaffold a project for use with Piggy in the Middle and Baconize", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", | ||
"travis": "npm run coverage" | ||
}, | ||
@@ -21,2 +23,3 @@ "repository": { | ||
"babel-polyfill": "^6.3.14", | ||
"deep-extend": "^0.4.1", | ||
"detab": "^1.0.2", | ||
@@ -29,3 +32,6 @@ "markup-js": "^1.5.21", | ||
"devDependencies": { | ||
"coveralls": "^2.11.6", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.3.4", | ||
"mocha-lcov-reporter": "^1.0.0", | ||
"rimraf": "^2.5.0", | ||
@@ -32,0 +38,0 @@ "unexpected": "^10.5.1" |
@@ -6,2 +6,3 @@ Barnyard | ||
[![Build Status](https://travis-ci.org/davej/barnyard.svg?branch=master)](https://travis-ci.org/davej/barnyard) | ||
[![Coverage Status](https://img.shields.io/coveralls/davej/barnyard.svg)](https://coveralls.io/r/davej/barnyard?branch=master) | ||
@@ -11,2 +12,5 @@ Bootstrap/Scaffold a project for use with [Piggy in the Middle](https://github.com/davej/piggy-in-the-middle) and [Baconize](https://github.com/davej/baconize). | ||
Getting Started | ||
--------------- | ||
To install: | ||
@@ -20,9 +24,8 @@ ```sh | ||
```javascript | ||
var barnyard = require('baconize'); | ||
var barnyard = require('barnyard'); | ||
var scaffoldDir = '/path/to/dir'; | ||
var options = { | ||
html: 'html', | ||
styles: 'scss', | ||
scripts: 'babel', | ||
styles: { type: 'scss' }, | ||
scripts: { type: 'babel' }, | ||
whitespaceFormatting: 2, | ||
@@ -71,8 +74,24 @@ babelPolyfill: true, | ||
- **html** (String, default = 'html'): Which languages to use for html documents. Possibilities: 'html', 'jade'. | ||
- **html** | ||
- **styles** (String, default = 'css'): Which languages to use for stylesheets. Possibilities: 'css', 'scss', 'sass', 'less', 'styl'. | ||
- **type** (String, default = 'html'): Which languages to use for html documents. Possibilities: 'html', 'jade'. | ||
- **scripts** (String, default = 'js'): Which languages to use for javascript. Possibilities: 'js', 'babel', 'coffee'. | ||
- **file** (String, default = 'index'): Filename (without extension) for main html document. | ||
- **styles** | ||
- **type** (String, default = 'css'): Which languages to use for stylesheets. Possibilities: 'css', 'scss', 'sass', 'less', 'styl'. | ||
- **file** (String, default = 'main'): Filename (without extension) for main style file. | ||
- **folder** (String, default = 'styles'): folder where style files are stored. | ||
- **scripts** | ||
- **type** (String, default = 'js'): Which languages to use for javascript. Possibilities: 'js', 'babel', 'coffee'. | ||
- **file** (String, default = 'main'): Filename (without extension) for main script files. | ||
- **folder** (String, default = 'styles'): folder where script files are stored. | ||
- **babelPolyfill** (Boolean): Include and reference the [babel polyfill](https://babeljs.io/docs/usage/polyfill/). | ||
@@ -82,2 +101,26 @@ | ||
- **whitespaceFormatting** (Number, default = 'tabs'): Formatting for whitespace. If not specified then tabs will be used, otherwise you can pass a number (e.g. 2, 4, 8) and the corresponding number of spaces will be used | ||
- **whitespaceFormatting** (Number/String, default = 'tabs'): Formatting for whitespace. If not specified then tabs will be used, otherwise you can pass a number (e.g. 2, 4, 8) and the corresponding number of spaces will be used | ||
Here is a full list of the defaults: | ||
```js | ||
{ | ||
html: { | ||
file: 'index', | ||
type: 'html', // or 'jade' | ||
}, | ||
styles: { | ||
folder: 'styles', | ||
file: 'main', | ||
type: 'css', // or 'scss', 'sass', 'less', 'styl' | ||
}, | ||
scripts: { | ||
folder: 'scripts', | ||
file: 'main', | ||
type: 'js', // or 'babel', 'coffee' | ||
}, | ||
babelPolyfill: false, | ||
normalizeCss: false, | ||
whitespaceFormatting: 'tabs', | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18655
183
122
7
6
+ Addeddeep-extend@^0.4.1
+ Addeddeep-extend@0.4.2(transitive)