Skip to content

Commit

Permalink
Add popup build script
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-f committed Sep 8, 2017
1 parent 492b294 commit 0fd6f74
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 40 deletions.
1 change: 0 additions & 1 deletion .env.demo.example

This file was deleted.

2 changes: 0 additions & 2 deletions .env.popup.example

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -69,5 +69,4 @@ typings/
lib
dist-lib
dist-popup
.env.demo
.env.popup
dist-demo
88 changes: 88 additions & 0 deletions bin/solid-auth-client.js
@@ -0,0 +1,88 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')

const program = require('commander')
const { isWebUri } = require('valid-url')

const { version } = require('../package.json')

// helpers

function ns(fn) {
return function() {
fn.apply(
null,
['[solid-auth-client]'].concat(Array.prototype.slice.call(arguments))
)
}
}

const log = ns(console.log.bind(console))
const warn = ns(console.log.bind(console))

// CLI

program
.version(version)
.command('generate-popup <trusted-origin> <trusted-name> [filename]')
.description('build a secure login app named for your application')
.action(generatePopup)

program.parse(process.argv)

// Show help if called with no arguments
if (!process.argv.slice(2).length) {
program.outputHelp()
}

// generatePopup command

function generatePopup(trustedOrigin, trustedName, filename) {
filename = filename || 'popup.html'
if (!isWebUri(trustedOrigin)) {
throw new Error(`Trusted origin "${trustedOrigin}" must be a valid origin`)
}

log(
`Generating "${filename}" with trusted origin "${trustedOrigin}" and trusted app name "${trustedName}"`
)

const templateFilename = path.resolve(
__dirname,
'..',
'dist-popup/popup.html'
)
if (!fs.existsSync(templateFilename)) {
const issueUrl = 'https://github.com/solid/solid-auth-client/issues'
warn(
`Could not find popup template. Expected it to be located at "${templateFilename}". Please file a bug at ${issueUrl}`
)
return
}

let popupTemplateBuffer
try {
popupTemplateBuffer = fs.readFileSync(templateFilename)
} catch (err) {
warn(`Could not read the popup template`)
console.error(err)
return
}

const popupBuffer = popupTemplateBuffer
.toString()
.replace(/{{TRUSTED_APP_ORIGIN}}/g, trustedOrigin)
.replace(/{{TRUSTED_APP_NAME}}/g, trustedName)

try {
fs.writeFileSync(filename, popupBuffer)
} catch (err) {
warn(`Could not write the popup to "${filename}".`)
console.error(err)
return
}

log(`Popup is generated and available at "${filename}"!`)
}
21 changes: 14 additions & 7 deletions package.json
Expand Up @@ -3,9 +3,12 @@
"version": "0.5.0",
"description": "Opaquely authenticates solid clients",
"main": "lib/index.js",
"bin": "./bin/solid-auth-client.js",
"files": [
"lib",
"dist-lib"
"bin",
"dist-lib",
"dist-popup",
"lib"
],
"repository": "git@github.com:solid/solid-auth-client.git",
"author": "Daniel Friedman <dfriedman58@gmail.com>",
Expand All @@ -14,28 +17,31 @@
"start:demo": "webpack-dev-server --env development --config=./webpack/webpack.demo.config.js",
"start:popup": "webpack-dev-server --env development --config=./webpack/webpack.popup.config.js",
"jest": "jest src",
"format": "prettier --parser flow --no-semi --single-quote --write '{src,demo,popup-app}/**/*.js'",
"format": "prettier --parser flow --no-semi --single-quote --write '{src,bin,demo,popup-app}/**/*.js'",
"prelint": "yarn format",
"lint": "eslint '{src,demo,popup-app}/**/*.js'",
"lint": "eslint '{src,bin,demo,popup-app}/**/*.js'",
"pretest": "flow && yarn lint",
"test": "yarn jest",
"test:dev": "yarn jest -- --watch",
"test:debug": "node --debug-brk ./node_modules/.bin/jest --runInBand src",
"coverage:report": "cat ./coverage/lcov.info | coveralls",
"build": "yarn build:lib && yarn build:lib:umd",
"build": "yarn build:lib && yarn build:lib:umd && yarn build:popup:template",
"build:lib": "rm -rf lib && babel --ignore '**.spec.js' src -d lib",
"build:lib:umd": "webpack --config=./webpack/webpack.lib.config.js -p",
"build:demo": "webpack --config=./webpack/webpack.demo.config.js -p",
"build:popup": "webpack --config=./webpack/webpack.popup.config.js -p && rm ./dist-popup/popup.bundle.js",
"build:popup:template": "cross-env TRUSTED_APP_NAME='{{TRUSTED_APP_NAME}}' TRUSTED_APP_ORIGIN='{{TRUSTED_APP_ORIGIN}}' yarn build:popup",
"preversion": "yarn test",
"postversion": "git push --follow-tags",
"prepublishOnly": "yarn build"
},
"dependencies": {
"@trust/oidc-rp": "^0.4.3",
"auth-header": "^0.3.1",
"commander": "^2.11.0",
"isomorphic-fetch": "^2.2.1",
"uuid": "^3.1.0"
"uuid": "^3.1.0",
"valid-url": "^1.0.9"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand All @@ -52,8 +58,8 @@
"bootstrap": "^4.0.0-alpha.6",
"clean-webpack-plugin": "^0.1.16",
"coveralls": "^2.13.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.4",
"dotenv-webpack": "^1.5.4",
"eslint": "^4.5.0",
"eslint-config-prettier": "^2.3.0",
"eslint-config-standard": "^10.2.1",
Expand Down Expand Up @@ -85,6 +91,7 @@
"testURL": "https://app.biz/page?foo=bar#more-params",
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"bin",
"demo",
"popup-app"
]
Expand Down
3 changes: 3 additions & 0 deletions webpack/webpack.common.config.js
@@ -1,4 +1,7 @@
const path = require('path')

module.exports = {
context: path.resolve(__dirname, '..'),
module: {
rules: [
{
Expand Down
16 changes: 7 additions & 9 deletions webpack/webpack.demo.config.js
@@ -1,19 +1,20 @@
const CleanWebpackPlugin = require('clean-webpack-plugin')
const DotenvPlugin = require('dotenv-webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
const webpack = require('webpack')
const { EnvironmentPlugin, HotModuleReplacementPlugin } = require('webpack')
const path = require('path')

const {
context,
module: _module,
externals,
devtool
} = require('./webpack.common.config')

const outputDir = './docs'
const outputDir = './dist-demo'

module.exports = {
context,
entry: {
demo: './demo/index.js'
},
Expand All @@ -30,18 +31,15 @@ module.exports = {
}
},
plugins: [
new DotenvPlugin({
path: './.env.demo',
safe: './.env.demo.example'
}),
new CleanWebpackPlugin(['./docs']),
new EnvironmentPlugin(['POPUP_URI']),
new CleanWebpackPlugin([outputDir]),
new HtmlWebpackPlugin({
chunks: ['demo'],
filename: 'demo.html',
title: 'Solid Auth Client Demo'
}),
new HtmlWebpackInlineSourcePlugin(),
new webpack.HotModuleReplacementPlugin(outputDir)
new HotModuleReplacementPlugin(outputDir)
],
devtool,
devServer: {
Expand Down
2 changes: 2 additions & 0 deletions webpack/webpack.lib.config.js
@@ -1,6 +1,7 @@
const path = require('path')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const {
context,
module: _module,
externals,
devtool
Expand All @@ -9,6 +10,7 @@ const {
const outputDir = './dist-lib'

module.exports = {
context,
entry: {
'solid-auth-client': './src/index.js'
},
Expand Down
14 changes: 5 additions & 9 deletions webpack/webpack.popup.config.js
@@ -1,19 +1,15 @@
const CleanWebpackPlugin = require('clean-webpack-plugin')
const DotenvPlugin = require('dotenv-webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
const path = require('path')
const { EnvironmentPlugin } = require('webpack')

const { module: _module, externals } = require('./webpack.common.config')
const { context, module: _module, externals } = require('./webpack.common.config')

const outputDir = './dist-popup'

const dotEnvPlugin = new DotenvPlugin({
path: './.env.popup',
safe: './.env.popup.example'
})

module.exports = {
context,
entry: {
popup: './popup-app/index.js'
},
Expand All @@ -30,8 +26,8 @@ module.exports = {
}
},
plugins: [
dotEnvPlugin,
new CleanWebpackPlugin(['./dist-popup']),
new EnvironmentPlugin(['TRUSTED_APP_NAME', 'TRUSTED_APP_ORIGIN']),
new CleanWebpackPlugin([outputDir]),
new HtmlWebpackPlugin({
template: 'popup-app/index.ejs',
filename: 'popup.html',
Expand Down
25 changes: 15 additions & 10 deletions yarn.lock
Expand Up @@ -1500,6 +1500,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

cross-env@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.0.5.tgz#4383d364d9660873dd185b398af3bfef5efffef3"
dependencies:
cross-spawn "^5.1.0"
is-windows "^1.0.0"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -1845,16 +1852,6 @@ domutils@1.5.1:
dom-serializer "0"
domelementtype "1"

dotenv-webpack@^1.5.4:
version "1.5.4"
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-1.5.4.tgz#9c92e46e412a1cfbc60217ed33d69d2bbfddbf9f"
dependencies:
dotenv "^4.0.0"

dotenv@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"

ecc-jsbn@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
Expand Down Expand Up @@ -3139,6 +3136,10 @@ is-utf8@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"

is-windows@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9"

isarray@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
Expand Down Expand Up @@ -5873,6 +5874,10 @@ v8flags@^2.1.1:
dependencies:
user-home "^1.1.1"

valid-url@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"

validate-npm-package-license@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
Expand Down

0 comments on commit 0fd6f74

Please sign in to comment.