Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongarciah authored Oct 4, 2017
2 parents d730890 + 87f155e commit 42fa029
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 65 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,20 @@ Then you may want to:

Remove `npm run report-coverage` from `.travis.yml`

## Resources

- [Write a library using TypeScript library starter](https://dev.to/alexjoverm/write-a-library-using-typescript-library-starter) by [@alexjoverm](https://github.com/alexjoverm/)
- [📺 Create a TypeScript Library using typescript-library-starter](https://egghead.io/lessons/typescript-create-a-typescript-library-using-typescript-library-starter) by [@alexjoverm](https://github.com/alexjoverm/)
- [Introducing TypeScript Library Starter Lite](https://blog.tonysneed.com/2017/09/15/introducing-typescript-library-starter-lite/) by [@tonysneed](https://github.com/tonysneed)

## Credits

Made with :heart: by [@alexjoverm](https://twitter.com/alexjoverm) and all these wonderful contributors ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/6052309?v=3" width="100px;"/><br /><sub>Ciro</sub>](https://www.linkedin.com/in/ciro-ivan-agulló-guarinos-42109376)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=k1r0s "Code") [🔧](#tool-k1r0s "Tools") | [<img src="https://avatars.githubusercontent.com/u/947523?v=3" width="100px;"/><br /><sub>Marius Schulz</sub>](https://blog.mariusschulz.com)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=mariusschulz "Documentation") | [<img src="https://avatars.githubusercontent.com/u/4152819?v=3" width="100px;"/><br /><sub>Alexander Odell</sub>](https://github.com/alextrastero)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=alextrastero "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/8728882?v=3" width="100px;"/><br /><sub>Ryan Ham</sub>](https://github.com/superamadeus)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=superamadeus "Code") | [<img src="https://avatars1.githubusercontent.com/u/8458838?v=3" width="100px;"/><br /><sub>Chi</sub>](https://consiiii.me)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=ChinW "Code") [🔧](#tool-ChinW "Tools") [📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=ChinW "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/2856501?v=3" width="100px;"/><br /><sub>Matt Mazzola</sub>](https://github.com/mattmazzola)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=mattmazzola "Code") [🔧](#tool-mattmazzola "Tools") | [<img src="https://avatars0.githubusercontent.com/u/2664047?v=3" width="100px;"/><br /><sub>Sergii Lischuk</sub>](http://leefrost.github.io)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=Leefrost "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/618922?v=3" width="100px;"/><br /><sub>Steve Lee</sub>](http;//opendirective.com)<br />[🔧](#tool-SteveALee "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5127501?v=3" width="100px;"/><br /><sub>Flavio Corpa</sub>](http://flaviocorpa.com)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=kutyel "Code") | [<img src="https://avatars2.githubusercontent.com/u/22561997?v=3" width="100px;"/><br /><sub>Dom</sub>](https://github.com/foreggs)<br />[🔧](#tool-foreggs "Tools") | [<img src="https://avatars1.githubusercontent.com/u/755?v=4" width="100px;"/><br /><sub>Alex Coles</sub>](http://alexbcoles.com)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=myabc "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1093738?v=4" width="100px;"/><br /><sub>David Khourshid</sub>](https://github.com/davidkpiano)<br />[🔧](#tool-davidkpiano "Tools") | [<img src="https://avatars0.githubusercontent.com/u/7225802?v=4" width="100px;"/><br /><sub>Aarón García Hervás</sub>](https://aarongarciah.com)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=aarongarciah "Documentation") |
| [<img src="https://avatars1.githubusercontent.com/u/618922?v=3" width="100px;"/><br /><sub>Steve Lee</sub>](http://opendirective.com)<br />[🔧](#tool-SteveALee "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5127501?v=3" width="100px;"/><br /><sub>Flavio Corpa</sub>](http://flaviocorpa.com)<br />[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=kutyel "Code") | [<img src="https://avatars2.githubusercontent.com/u/22561997?v=3" width="100px;"/><br /><sub>Dom</sub>](https://github.com/foreggs)<br />[🔧](#tool-foreggs "Tools") | [<img src="https://avatars1.githubusercontent.com/u/755?v=4" width="100px;"/><br /><sub>Alex Coles</sub>](http://alexbcoles.com)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=myabc "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1093738?v=4" width="100px;"/><br /><sub>David Khourshid</sub>](https://github.com/davidkpiano)<br />[🔧](#tool-davidkpiano "Tools") | [<img src="https://avatars0.githubusercontent.com/u/7225802?v=4" width="100px;"/><br /><sub>Aarón García Hervás</sub>](https://aarongarciah.com)<br />[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=aarongarciah "Documentation") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"scripts": {
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc && rollup -c && rimraf compiled && typedoc --out dist/docs --target es6 --theme minimal src",
"start": "tsc -w & rollup -c -w",
"build": "tsc && rollup -c rollup.config.ts && rimraf compiled && typedoc --out dist/docs --target es6 --theme minimal src",
"start": "tsc -w & rollup -c rollup.config.ts -w",
"test": "jest",
"test:watch": "jest --watch",
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
Expand All @@ -36,7 +36,7 @@
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier --write --no-semi",
"prettier --write --no-semi --single-quote",
"git add"
]
},
Expand Down
27 changes: 14 additions & 13 deletions rollup.config.js → rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import resolve from "rollup-plugin-node-resolve"
import commonjs from "rollup-plugin-commonjs"
import sourceMaps from "rollup-plugin-sourcemaps"
const pkg = require("./package.json")
const camelCase = require("lodash.camelcase")
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps'
import camelCase from 'lodash.camelcase'

const libraryName = "--libraryname--"
const pkg = require('./package.json')

const libraryName = '--libraryname--'

export default {
input: `compiled/${libraryName}.js`,
output: [
{ file: pkg.main, name: camelCase(libraryName), format: "umd" },
{ file: pkg.module, format: "es" }
entry: `compiled/${libraryName}.js`,
targets: [
{ dest: pkg.main, moduleName: camelCase(libraryName), format: 'umd' },
{ dest: pkg.module, format: 'es' },
],
sourcemap: true,
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: "compiled/**"
include: 'compiled/**',
},
plugins: [
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
Expand All @@ -27,6 +28,6 @@ export default {
resolve(),

// Resolve source maps to the original source
sourceMaps()
]
sourceMaps(),
],
}
96 changes: 48 additions & 48 deletions tools/init.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* This script is runned automatically after your first npm-install.
*/
const _prompt = require("prompt")
const { mv, rm, which, exec } = require("shelljs")
const replace = require("replace-in-file")
const colors = require("colors")
const path = require("path")
const { readFileSync, writeFileSync } = require("fs")
const { fork } = require("child_process")

if (!which("git")) {
console.log(colors.red("Sorry, this script requires git"))
const _prompt = require('prompt')
const { mv, rm, which, exec } = require('shelljs')
const replace = require('replace-in-file')
const colors = require('colors')
const path = require('path')
const { readFileSync, writeFileSync } = require('fs')
const { fork } = require('child_process')

if (!which('git')) {
console.log(colors.red('Sorry, this script requires git'))
process.exit(1)
}

function resolve(p: any) {
return path.resolve(__dirname, "..", p)
return path.resolve(__dirname, '..', p)
}

function setupProject() {
Expand All @@ -24,109 +24,109 @@ function setupProject() {
{
files,
from: [/--libraryname--/g, /--username--/g, /--usermail--/g],
to: [libraryName, username, usermail]
to: [libraryName, username, usermail],
},
() => {
// Rename main file and test
const renamedFiles = [
`src/${libraryName}.ts`,
`test/${libraryName}.test.ts`
`test/${libraryName}.test.ts`,
]
mv(
path.resolve(__dirname, "..", "src/library.ts"),
path.resolve(__dirname, "..", renamedFiles[0])
path.resolve(__dirname, '..', 'src/library.ts'),
path.resolve(__dirname, '..', renamedFiles[0])
)
mv(
path.resolve(__dirname, "..", "test/library.test.ts"),
path.resolve(__dirname, "..", renamedFiles[1])
path.resolve(__dirname, '..', 'test/library.test.ts'),
path.resolve(__dirname, '..', renamedFiles[1])
)

console.log()
console.log(colors.cyan(renamedFiles.join(",")) + " renamed")
console.log(colors.cyan(files.join(",")) + " updated")
console.log(colors.cyan(renamedFiles.join(',')) + ' renamed')
console.log(colors.cyan(files.join(',')) + ' updated')

// Recreate init folder and initialize husky
exec('git init "' + path.resolve(__dirname, "..") + '"')
exec('git init "' + path.resolve(__dirname, '..') + '"')
console.log()
console.log(colors.cyan("Git initialized"))
console.log(colors.cyan('Git initialized'))
console.log()

// Remove post-install command
const pkg = JSON.parse(
readFileSync(path.resolve(__dirname, "..", "package.json")) as any
)
const pkg = JSON.parse(readFileSync(
path.resolve(__dirname, '..', 'package.json')
) as any)

delete pkg.scripts.postinstall
writeFileSync(
path.resolve(__dirname, "..", "package.json"),
path.resolve(__dirname, '..', 'package.json'),
JSON.stringify(pkg, null, 2)
)
console.log()
console.log(colors.cyan("Removed postinstall script"))
console.log(colors.cyan('Removed postinstall script'))
console.log()

fork(
path.resolve(__dirname, "..", "node_modules", "husky", "bin", "install")
path.resolve(__dirname, '..', 'node_modules', 'husky', 'bin', 'install')
)

console.log()
console.log(colors.green("Happy coding!! ;)"))
console.log(colors.green('Happy coding!! ;)'))
console.log()
}
)
}

let libraryName = "test" // Default, in case it runns on a CI
let username = exec("git config user.name").stdout.trim()
let usermail = exec("git config user.email").stdout.trim()
let libraryName = 'test' // Default, in case it runns on a CI
let username = exec('git config user.name').stdout.trim()
let usermail = exec('git config user.email').stdout.trim()
let inCI = process.env.CI

const _promptSchema = {
properties: {
library: {
description: colors.cyan("Enter your library name (use kebab-case)"),
description: colors.cyan('Enter your library name (use kebab-case)'),
pattern: /^[a-z]+(\-[a-z]+)*$/,
type: "string",
required: true
}
}
type: 'string',
required: true,
},
},
}

const files = [
resolve("package.json"),
resolve("rollup.config.js"),
resolve("LICENSE"),
resolve("test/library.test.ts"),
resolve("tools/gh-pages-publish.ts")
resolve('package.json'),
resolve('rollup.config.ts'),
resolve('LICENSE'),
resolve('test/library.test.ts'),
resolve('tools/gh-pages-publish.ts'),
]

_prompt.start()
_prompt.message = ""
_prompt.message = ''

// Clear console
let lines = (process.stdout as any).getWindowSize()[1]
for (let i = 0; i < lines; i++) {
console.log("\r\n")
console.log('\r\n')
}

// Say hi!
console.log(colors.yellow("Hi! I'm setting things up for you!!"))

// Remove .git folder
rm("-Rf", path.resolve(__dirname, "..", ".git"))
console.log("\r\n", "Removed .git directory", "\r\n")
rm('-Rf', path.resolve(__dirname, '..', '.git'))
console.log('\r\n', 'Removed .git directory', '\r\n')

// Remove files
const filesRm = ["tools/init.ts", ".all-contributorsrc", ".gitattributes"]
const pathsRm = filesRm.map(f => path.resolve(__dirname, "..", f))
const filesRm = ['tools/init.ts', '.all-contributorsrc', '.gitattributes']
const pathsRm = filesRm.map(f => path.resolve(__dirname, '..', f))
rm(pathsRm)
console.log(`\r\nRemoved files: ${filesRm.toString()}\r\n`)

if (!inCI) {
// Ask for library name
_prompt.get(_promptSchema, (err: any, res: any) => {
if (err) {
console.log(colors.red("There was an error building the workspace :("))
console.log(colors.red('There was an error building the workspace :('))
process.exit(1)
return
}
Expand Down

0 comments on commit 42fa029

Please sign in to comment.