Skip to content

Commit

Permalink
Merge pull request #2 from databyss-org/paul/packaging
Browse files Browse the repository at this point in the history
paul/packaging
  • Loading branch information
Paul Hine authored Oct 31, 2018
2 parents 5690710 + e1835c2 commit d0c411f
Show file tree
Hide file tree
Showing 7 changed files with 1,130 additions and 1,811 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"browser": true
},
"rules": {
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["**/*.*"]
}
], // we use devDependencies
"no-console": "off", // Console logs are too useful and are removed in prod anyway
"no-underscore-dangle": "off", // It's classic pattern to denote private props.
"react/prop-types": "off", // We're using flow instead
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Call-Em-All

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 60 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
{
"name": "react-text-templates",
"version": "1.0.0",
"description": "simple library to render plaintext templates to React elements",
"version": "1.0.1",
"description": "Simple library to render plaintext templates to React elements",
"main": "index.js",
"repository": "https://github.com/databyss-org/react-text-templates",
"author": "pzhine",
"repository": {
"type": "git",
"url": "https://github.com/databyss-org/react-text-templates"
},
"keywords": [
"react",
"component",
"template",
"tokens"
],
"bugs": {
"url": "https://github.com/databyss-org/react-text-templates/issues"
},
"author": "databyss.org",
"license": "MIT",
"dependencies": {
"react": "^16.4.2"
"peerDependencies": {
"react": "*"
},
"devDependencies": {
"babel-core": "6.26.0",
"babel-preset-react-app": "^3.1.1",
"babel-eslint": "^8.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
"@babel/cli": "7.1.2",
"@babel/core": "7.1.2",
"@babel/node": "7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "7.1.0",
"@babel/preset-react": "7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.6.0",
"cross-env": "^5.1.1",
"eslint": "4.10.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "7.4.0",
"flow-bin": "^0.79.1",
"fs-extra": "^7.0.0",
"jest": "23.6.0",
"jest-pnp-resolver": "^1.0.1",
"jest-resolve": "^23.6.0",
"jest-runner-eslint": "^0.7.1",
"prettier": "1.13.5",
"prettier-eslint": "^8.8.1",
"react": "^16.4.2",
"react-dev-utils": "^5.0.1",
"react-test-renderer": "^16.6.0",
"webpack": "3.8.1",
"webpack-node-externals": "^1.7.2"
"rimraf": "^2.6.2"
},
"scripts": {
"build": "NODE_ENV=production webpack",
"test": "NODE_ENV=test [ ! -z \"$CI\" ] && npx jest || npx jest --watch"
"build": "yarn build:es2015 && yarn build:es2015modules && yarn build:copy-files",
"build:copy-files": "babel-node scripts/copy-files.js",
"build:es2015": "cross-env NODE_ENV=production babel ./index.js --out-dir ./dist",
"build:es2015modules": "cross-env NODE_ENV=production BABEL_ENV=modules babel ./index.js --out-file ./dist/index.es.js",
"prebuild": "rimraf dist",
"test": "node scripts/test.js"
},
"jest": {
"projects": [
Expand All @@ -51,21 +72,11 @@
},
{
"displayName": "test",
"collectCoverageFrom": [
"index.js"
],
"resolver": "jest-pnp-resolver",
"testMatch": [
"<rootDir>/*.test.js"
],
"testEnvironment": "jsdom",
"testURL": "http://localhost",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.js$"
],
"moduleFileExtensions": [
"js"
]
Expand All @@ -74,7 +85,28 @@
},
"babel": {
"presets": [
"react-app"
]
"@babel/preset-env",
"@babel/preset-react"
],
"env": {
"development": {
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
},
"modules": {
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
]
}
}
},
"engines": {
"node": ">=6.0.0"
}
}
65 changes: 65 additions & 0 deletions scripts/copy-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import path from 'path'
import fse from 'fs-extra'

async function copyFile(file) {
const buildPath = path.resolve(__dirname, '../dist/', path.basename(file))
await fse.copy(file, buildPath)
console.log(`Copied ${file} to ${buildPath}`)
}

async function createPackageFile() {
const packageData = await fse.readFile(
path.resolve(__dirname, '../package.json'),
'utf8'
)
const {
scripts,
devDependencies,
jest,
babel,
...packageDataOther
} = JSON.parse(packageData)
const newPackageData = {
...packageDataOther,
main: './index.js',
module: './index.es.js',
private: false,
}
const buildPath = path.resolve(__dirname, '../dist/package.json')

await fse.writeFile(
buildPath,
JSON.stringify(newPackageData, null, 2),
'utf8'
)
console.log(`Created package.json in ${buildPath}`)

return newPackageData
}

async function prepend(file, string) {
const data = await fse.readFile(file, 'utf8')
await fse.writeFile(file, string + data, 'utf8')
}

async function addLicense(packageData) {
const license = `/** @license databyss.org v${packageData.version}
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
`
await Promise.all(
['../dist/index.js', '../dist/index.es.js'].map(file =>
prepend(path.resolve(__dirname, file), license)
)
)
}

async function run() {
await Promise.all(['./README.md', './LICENSE'].map(file => copyFile(file)))
const packageData = await createPackageFile()
await addLicense(packageData)
}

run()
26 changes: 26 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test'
process.env.NODE_ENV = 'test'
process.env.PUBLIC_URL = ''

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err
})

const jest = require('jest')

const argv = process.argv.slice(2)

// Watch unless on CI or in coverage or debug mode
if (
!process.env.CI &&
argv.indexOf('--coverage') < 0 &&
argv.indexOf('--debug') < 0
) {
argv.push('--watchAll')
}

jest.run(argv)
44 changes: 0 additions & 44 deletions webpack.config.js

This file was deleted.

Loading

0 comments on commit d0c411f

Please sign in to comment.