diff --git a/README.md b/README.md index 5bf09fab..fa5c27b6 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,12 @@ 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)): @@ -126,7 +132,7 @@ Made with :heart: by [@alexjoverm](https://twitter.com/alexjoverm) and all these | [
Ciro](https://www.linkedin.com/in/ciro-ivan-agulló-guarinos-42109376)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=k1r0s "Code") [🔧](#tool-k1r0s "Tools") | [
Marius Schulz](https://blog.mariusschulz.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=mariusschulz "Documentation") | [
Alexander Odell](https://github.com/alextrastero)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=alextrastero "Documentation") | [
Ryan Ham](https://github.com/superamadeus)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=superamadeus "Code") | [
Chi](https://consiiii.me)
[💻](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") | [
Matt Mazzola](https://github.com/mattmazzola)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=mattmazzola "Code") [🔧](#tool-mattmazzola "Tools") | [
Sergii Lischuk](http://leefrost.github.io)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=Leefrost "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Steve Lee](http;//opendirective.com)
[🔧](#tool-SteveALee "Tools") | [
Flavio Corpa](http://flaviocorpa.com)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=kutyel "Code") | [
Dom](https://github.com/foreggs)
[🔧](#tool-foreggs "Tools") | [
Alex Coles](http://alexbcoles.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=myabc "Documentation") | [
David Khourshid](https://github.com/davidkpiano)
[🔧](#tool-davidkpiano "Tools") | [
Aarón García Hervás](https://aarongarciah.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=aarongarciah "Documentation") | +| [
Steve Lee](http://opendirective.com)
[🔧](#tool-SteveALee "Tools") | [
Flavio Corpa](http://flaviocorpa.com)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=kutyel "Code") | [
Dom](https://github.com/foreggs)
[🔧](#tool-foreggs "Tools") | [
Alex Coles](http://alexbcoles.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=myabc "Documentation") | [
David Khourshid](https://github.com/davidkpiano)
[🔧](#tool-davidkpiano "Tools") | [
Aarón García Hervás](https://aarongarciah.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=aarongarciah "Documentation") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! diff --git a/package.json b/package.json index d741289d..0f30c823 100644 --- a/package.json +++ b/package.json @@ -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", @@ -36,7 +36,7 @@ }, "lint-staged": { "{src,test}/**/*.ts": [ - "prettier --write --no-semi", + "prettier --write --no-semi --single-quote", "git add" ] }, diff --git a/rollup.config.js b/rollup.config.ts similarity index 52% rename from rollup.config.js rename to rollup.config.ts index 3235d7f3..17cd26ce 100644 --- a/rollup.config.js +++ b/rollup.config.ts @@ -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) @@ -27,6 +28,6 @@ export default { resolve(), // Resolve source maps to the original source - sourceMaps() - ] + sourceMaps(), + ], } diff --git a/tools/init.ts b/tools/init.ts index 2d061aa9..6baf3a58 100644 --- a/tools/init.ts +++ b/tools/init.ts @@ -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() { @@ -24,101 +24,101 @@ 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`) @@ -126,7 +126,7 @@ 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 }