Skip to content

Fix module API export #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ loginModal.close()
loginModal.logout();
```

#### A note on script tag versioning

The `v1` in the above URL is not pinned to the major version of the module API, and will only reflect breaking changes in the
markup API.

### Module API

Netlify Identity Widget also has a module api:
Expand All @@ -71,33 +76,31 @@ yarn add netlify-identity-widget
Import or require as usual:

```js
import NetlifyIdentity from "netlify-identity-widget"
// or
const netlifyIdentity = require("netlify-identity-widget");
const netlifyIdentity = require("netlify-identity-widget")

netlifyIdentity.init({
container: "#netlify-modal" // defaults to document.body
});

identity.open() // open the modal
netlifyIdentity.open() // open the modal

identity.on('init', user => console.log(user))
identity.on('login', login => console.log(user))
identity.on('logout', () => console.log("Logged out"))
identity.on('error', err => console.error("Logged out"))
identity.on('open', () => console.log("Widget opened"))
identity.on('close', () => console.log("Widget closed"))
netlifyIdentity.on('init', user => console.log(user))
netlifyIdentity.on('login', login => console.log(user))
netlifyIdentity.on('logout', () => console.log("Logged out"))
netlifyIdentity.on('error', err => console.error("Logged out"))
netlifyIdentity.on('open', () => console.log("Widget opened"))
netlifyIdentity.on('close', () => console.log("Widget closed"))

// Close the modal
identity.close()

// Logout the user
loginModal.logout();
netlifyIdentity.logout();

// Access the underlying gotrue instance.
// Note that doing things directly through gotrue brings a risk of getting out of
// sync between your state and the widgets state.
identity.gotrue
netlifyIdentity.gotrue
```

## Localhost
Expand Down
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "netlify-identity-widget",
"version": "1.0.0",
"releaseVersion": "v1",
"description": "Netlify Identity widget for easy integration",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --inline --progress",
"dev": "cross-env NODE_ENV=development webpack-dev-server --inline --progress --config webpack.config.babel.js",
"start": "serve build -s -c 1",
"prestart": "npm run build",
"version": "npm run release",
"prepublish": "npm run build",
"build": "cross-env NODE_ENV=production webpack --progress",
"prestart": "run-s build",
"version": "run-s release",
"prepublish": "run-s build",
"build": "run-p build:*",
"build:bundle": "cross-env NODE_ENV=production webpack --progress --config webpack.config.babel.js",
"build:umd": "cross-env NODE_ENV=production webpack --progress --config webpack.umd.config.babel.js",
"prebuild": "mkdirp build",
"test": "eslint src",
"release": "node ./script/release.js",
Expand Down Expand Up @@ -42,27 +45,26 @@
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-react": "^7.0.0",
"file-loader": "^0.11.1",
"gotrue-js": "^0.9.8",
"html-webpack-plugin": "^2.28.0",
"json-loader": "^0.5.4",
"mkdirp": "^0.5.1",
"mobx": "^3.2.2",
"mobx-preact": "^0.3.1",
"npm-run-all": "^4.1.1",
"postcss-cssnext": "^3.0.2",
"postcss-import": "^10.0.0",
"postcss-loader": "^2.0.3",
"postcss-nested": "^2.1.2",
"preact": "^8.1.0",
"preact-compat": "^3.15.0",
"prettier": "^1.6.1",
"raw-loader": "^0.5.1",
"semver": "^5.4.1",
"serve": "^6.0.0",
"source-map-loader": "^0.2.1",
"url-loader": "^0.5.8",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.4.4"
},
"dependencies": {
"gotrue-js": "^0.9.8",
"mobx": "^3.2.2",
"mobx-preact": "^0.3.1",
"postcss-cssnext": "^3.0.2",
"postcss-import": "^10.0.0",
"postcss-nested": "^2.1.2",
"preact": "^8.1.0",
"preact-compat": "^3.15.0",
"serve": "^6.0.0"
}
"dependencies": {}
}
3 changes: 1 addition & 2 deletions script/release.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint no-console: "off" */
const exec = require("child_process").execSync;
const semver = require("semver");
const version = "v" + semver(require("../package.json").version).major;
const version = require("../package.json").releaseVersion;

console.log("Building new release for ", version);

Expand Down
10 changes: 10 additions & 0 deletions src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@
}

</style>

<script>
// Bind to events
netlifyIdentity.on("init", user => console.log(user));
netlifyIdentity.on("login", user => console.log(user));
netlifyIdentity.on("logout", () => console.log("Logged out"));
netlifyIdentity.on("error", err => console.error("Logged out"));
netlifyIdentity.on("open", () => console.log("Widget opened"));
netlifyIdentity.on("close", () => console.log("Widget closed"));
</script>
</head>
<body>
<div class="main">
Expand Down
4 changes: 3 additions & 1 deletion src/netlify-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ function init(options) {
};
setStyle(iframe, iframeStyle);
iframe.src = "about:blank";
const container = options.container ? document.querySelector : document.body;
const container = options.container
? document.querySelector(options.container)
: document.body;
container.appendChild(iframe);
/* There's a certain case where we might have called setStyle before the iframe was ready.
Make sure we take the last style and apply it */
Expand Down
1 change: 0 additions & 1 deletion webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
context: path.resolve(__dirname, "src"),
entry: {
"netlify-identity-widget": "./index.js",
"netlify-identity": "./netlify-identity.js"
},

output: {
Expand Down
21 changes: 21 additions & 0 deletions webpack.umd.config.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import baseConfig from "./webpack.config.babel.js";
import path from "path";

const umdConfig = Object.assign({}, baseConfig, {
entry: {
"netlify-identity": "./netlify-identity.js"
},

output: {
path: path.resolve(__dirname, "build"),
publicPath: "/",
filename: "[name].js",
library: "netlifyIdentity",
libraryTarget: "umd",
libraryExport: "default"
}
})

umdConfig.plugins.splice(2,1) // Remove html plugin

module.exports = umdConfig
Loading