Skip to content

Commit

Permalink
Merge pull request #2 from callmecavs/cavs/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
callmecavs authored Jan 8, 2017
2 parents b5a0480 + 9258039 commit 08bf1fe
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
dist
node_modules
*.log
*.map
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,39 @@

[![outset-lib on NPM](https://img.shields.io/npm/v/outset-lib.svg?style=flat-square)](https://www.npmjs.com/package/outset-lib)

A boilerplate for modern JavaScript libraries.

## About

Contributing a library to the JS community should be painless, though the current state of the language itself makes it a bit tedious. Allowing creators to use the niceties of ES next, while enabling users to consume the library however they prefer, creates overhead in the process of making and distributing code.

This boilerplate aims to provide an unopinionated solution to this problem.
A boilerplate for vanilla JavaScript libraries.

## Install

Using NPM, install outset-lib globally.

```bash
$ npm install outset-lib -g
```

## Use

In your terminal:
To create a new project:

```bash
$ outset-lib <name>
$ npm install
$ gulp
```
# make a directory for it
$ mkdir project
$ cd project

In your browser:
# run outset-lib, passing the project name
$ outset-lib project

# install dependencies, and start coding
$ npm i
$ npm run dev
```
http://localhost:3000/
```

Work in the `src` folder. Distribute from the `dist` folder.

## Docs
## Linting

* **Creators**: Write in ES6/7 syntax via [Babel.js](https://babeljs.io/), and bundle modules via [rollup](https://github.com/rollup/rollup)
* **Users**: Enjoy distribution files transpiled down to ES5, and wrapped in a UMD wrapper
[![JS Standard Style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](http://standardjs.com)

## License

MIT. © 2016 Michael Cavalea
MIT. © 2017 Michael Cavalea

[![Built With Love](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
61 changes: 33 additions & 28 deletions outset-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,51 @@
const fs = require('fs')

// cache paths
const TO = process.cwd()
const FROM = __dirname + '/template'

// prepare name from parameter
const COPY_FROM = __dirname + '/template'
const COPY_TO = process.cwd()

const FILES = [
'src/index.js',
'test/manual.html',
'.babelrc',
'.eslintrc',
'gitignore',
'package.json',
'README.md',
'rollup.config.js'
]

// prepare names from arg
const input = process.argv[2]

const sanitized = input.indexOf('.') === -1
? input
: input.split('.')[0]
const sanitized = input.includes('.')
? input.substring(0, input.indexOf('.'))
: input

const NAME = {
lower: sanitized.toLowerCase(),
upper: sanitized.charAt(0).toUpperCase() + sanitized.slice(1)
}

// get the file list
const fileList = fs.readdirSync(FROM)

// append to folder results
const srcIndex = fileList.indexOf('src')
const distIndex = fileList.indexOf('dist')
fileList[srcIndex] = 'src/lib.js'
fileList[distIndex] = 'dist/index.html'

// make folders for files
fs.mkdirSync(TO + '/src')
fs.mkdirSync(TO + '/dist')
// create required directories
fs.mkdirSync(COPY_TO + '/src')
fs.mkdirSync(COPY_TO + '/test')

// for each file - read, replace, write
fileList.forEach(file => {
let content = fs.readFileSync(FROM + '/' + file, 'utf8')
FILES.forEach(name => {
// read content
const content = fs.readFileSync(COPY_FROM + '/' + name, 'utf8')

content = content.replace(/\${ NAME.upper }/g, NAME.upper)
content = content.replace(/\${ NAME.lower }/g, NAME.lower)
// replace names
const transformed = content
.replace(/\${ NAME.upper }/g, NAME.upper)
.replace(/\${ NAME.lower }/g, NAME.lower)

fs.writeFileSync(TO + '/' + file, content, 'utf8')
// write file
fs.writeFileSync(COPY_TO + '/' + name, transformed, 'utf8')
})

// rename JS file
fs.renameSync(TO + '/src/lib.js', TO + '/src/' + NAME.lower +'.js')
// rename index
fs.renameSync(COPY_TO + '/src/index.js', COPY_TO + '/src/' + NAME.lower +'.js')

// rename gitignore
fs.renameSync(TO + '/gitignore', TO + '/.gitignore')
fs.renameSync(COPY_TO + '/gitignore', COPY_TO + '/.gitignore')
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
{
"name": "outset-lib",
"description": "A boilerplate for modern JavaScript libraries.",
"description": "A boilerplate for vanilla JavaScript libraries.",

"version": "1.1.1",
"version": "2.0.0",
"license": "MIT",

"repository": "callmecavs/outset-lib",

"bin": {
"outset-lib": "outset-lib.js"
},

"author": {
"name": "Michael Cavalea",
"email": "[email protected]",
"url": "http://callmecavs.com/"
},

"bin": {
"outset-lib": "outset-lib.js"
},

"keywords": [
"boilerplate",
"browser",
"bundle",
"cli",
"es6",
"modules",
"library",
"es6"
"rollup",
"scaffold",
"vanilla"
],

"preferGlobal": true
Expand Down
3 changes: 3 additions & 0 deletions template/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "standard"
}
4 changes: 1 addition & 3 deletions template/gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.DS_Store
node_modules
*.log

dist/maps
dist/index.html
*.map
163 changes: 0 additions & 163 deletions template/gulpfile.js

This file was deleted.

Loading

0 comments on commit 08bf1fe

Please sign in to comment.