Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Use webpack to build final product #117

Merged
merged 38 commits into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bdeaeed
Use webpack to build final product
dmsnell Sep 9, 2015
168ed90
Small updates: formatting, version, main file
dmsnell Oct 1, 2015
e687f6c
Remove 'only' that was hogging the test suites
dmsnell Oct 2, 2015
e27b382
Update Makefile and tests to use minified build
dmsnell Oct 2, 2015
255aa55
Push new distribution build of minified files.
dmsnell Oct 2, 2015
da5dbb3
Settle on a build layout.
dmsnell Oct 2, 2015
ef24996
Figure out public build process
dmsnell Oct 22, 2015
4cf07e5
Make tests use `dist` version
dmsnell Oct 22, 2015
3f63b0d
Update CircleCI config to build dist version
dmsnell Oct 22, 2015
4188dca
fixup! Update CircleCI config to build dist version
dmsnell Oct 22, 2015
3c3d212
Add the standalone file back into the repo
dmsnell Oct 23, 2015
42adf06
Added phony targets to .PHONY in Makefile
mattsherman Nov 3, 2015
500d902
Added dist/lib, dist/util, dist/test to .gitignore
mattsherman Nov 3, 2015
c153740
Cleaned up dist target dependencies in Makefile
mattsherman Nov 3, 2015
17ae5b0
Remove prepublish npm script, create publish make target
mattsherman Nov 3, 2015
cb2e1f9
Remove install make target
mattsherman Nov 3, 2015
f68831d
dist
retrofox Nov 3, 2015
33e910f
Use webpack to build final product
retrofox Nov 3, 2015
94df1ab
Small updates: formatting, version, main file
dmsnell Oct 1, 2015
854f212
Push new distribution build of minified files.
retrofox Nov 3, 2015
76e2084
Settle on a build layout.
retrofox Nov 3, 2015
c7968a0
Figure out public build process
retrofox Nov 3, 2015
df4cccb
Update CircleCI config to build dist version
dmsnell Oct 22, 2015
a3ddbab
fixup! Update CircleCI config to build dist version
dmsnell Oct 22, 2015
c30cc98
Add the standalone file back into the repo
retrofox Nov 3, 2015
accc3d3
examples-cors: remove node.js server
retrofox Nov 3, 2015
dfd1ab6
Fix example server to grab config from test/config instead of test/data
mattsherman Nov 4, 2015
9ed9b74
Committing dist files
mattsherman Nov 4, 2015
32a7a6a
pkg: move babel into "dependencies" key
retrofox Nov 4, 2015
4a1cb85
Clean up .gitignore, remove dist/index.js
mattsherman Nov 4, 2015
503466a
Merge branch 'update/webpack-build-system' of github.com:Automattic/w…
mattsherman Nov 4, 2015
fe07656
Added self to list of contributors
mattsherman Nov 4, 2015
793bcdd
remove `fs` from building process
retrofox Nov 5, 2015
53498ba
example: update uploading testing file (proxy)
retrofox Nov 5, 2015
8eba5e8
dist:updated
retrofox Nov 5, 2015
7021e6f
Fixed `examples/browser-cors/upload-images.html`
mattsherman Nov 5, 2015
6cff4f1
example: tweak upload images cors example
retrofox Nov 6, 2015
c77b18d
example: rename uploading testing file
retrofox Nov 6, 2015
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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"blacklist": [ "strict" ]
"blacklist": [ "strict" ],
"sourceMaps": "true"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ npm-debug.log
/gh-tmp
.DS_Store
.idea
/dist/lib
/dist/util
/dist/test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just add /dist/ here or are there files we want to keep?

If, for example we want to keep the standalone file...

/gh-tmp
.DS_Store
.idea
/dist
!/dist/wpcom.js

That ! should whitelist the file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of in 4a1cb85

46 changes: 29 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,43 @@ BIN := $(THIS_DIR)/node_modules/.bin
NODE ?= node
NPM ?= $(NODE) $(shell which npm)
MOCHA ?= $(NODE) $(BIN)/mocha
BROWSERIFY ?= $(NODE) $(BIN)/browserify
BABEL ?= $(NODE) $(BIN)/babel
WEBPACK ?= $(NODE) $(BIN)/webpack

standalone: dist/wpcom.js

install: node_modules

clean:
@rm -rf node_modules dist
@rm -rf dist

distclean: clean
@rm -rf node_modules

dist: dist/lib dist/test
@mkdir -p $@

dist/lib: dist/lib/util
@mkdir -p $@

dist/lib/util:
@mkdir -p $@

dist:
dist/test:
@mkdir -p $@

dist/wpcom.js: node_modules *.js dist lib/*.js
@$(BROWSERIFY) -s WPCOM . > $@
dist/wpcom.js: *.js dist lib/*.js
@$(WEBPACK) -p --config webpack.config.js

node_modules: package.json
@NODE_ENV= $(NPM) install
@touch node_modules
babelify: dist
@$(BABEL) index.js --out-file dist/index.js
@$(BABEL) lib --out-dir dist/lib
@$(BABEL) lib/util --out-dir dist/lib/util
@$(BABEL) test --out-dir dist/test

example-server:
cd examples/server/; $(NPM) install
$(NODE) examples/server/index.js

example-browser-cors: all
cd examples/browser-cors/; $(NPM) install
$(NODE) examples/browser-cors/index.js

test: node_modules
test: babelify
@$(MOCHA) \
--compilers js:babel/register \
--timeout 120s \
Expand All @@ -46,12 +55,15 @@ test: node_modules
--bail \
--reporter spec

test-all: node_modules
test-all: babelify
@$(MOCHA) \
--compilers js:babel/register \
--timeout 120s \
--slow 3s \
--bail \
--reporter spec

.PHONY: all standalone install clean test test-all
publish: clean standalone
$(NPM) publish

.PHONY: all standalone clean distclean babelify example-server example-browser-cors test test-all publish
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ blog.posts({ number: 8 })

### Browser

Include `dist/wpcom.js` in a `<script>` tag:
Include `dist/wpcom.js` and a suitable browser shim if needed
to support the ES2015 features in `<script>` tags:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.25/browser-polyfill.js"></script>
<script src="wpcom.js"></script>
<script>
var wpcom = WPCOM('<your-token>');
Expand Down
183 changes: 183 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@


/**
* Module dependencies.
*/

var request_handler = require('wpcom-xhr-request');

/**
* Local module dependencies.
*/

var Me = require('./lib/me');
var Site = require('./lib/site');
var Users = require('./lib/users');
var Batch = require('./lib/batch');
var Req = require('./lib/util/request');
var sendRequest = require('./lib/util/send-request');
var debug = require('debug')('wpcom');

/**
* Local module constants
*/
var DEFAULT_ASYNC_TIMEOUT = 30000;

/**
* XMLHttpRequest (and CORS) API access method.
*
* API authentication is done via an (optional) access `token`,
* which needs to be retrieved via OAuth.
*
* Request Handler is optional and XHR is defined as default.
*
* @param {String} [token] - OAuth API access token
* @param {Function} [reqHandler] - function Request Handler
* @public
*/

function WPCOM(token, reqHandler) {
if (!(this instanceof WPCOM)) {
return new WPCOM(token, reqHandler);
}

// `token` is optional
if ('function' === typeof token) {
reqHandler = token;
token = null;
}

if (token) {
debug('Token defined: %s…', token.substring(0, 6));
this.token = token;
}

// Set default request handler
if (!reqHandler) {
debug('No request handler. Adding default XHR request handler');

this.request = function (params, fn) {
params = params || {};

// token is optional
if (token) {
params.authToken = token;
}

return request_handler(params, fn);
};
} else {
this.request = reqHandler;
}

// Add Req instance
this.req = new Req(this);

// Default api version;
this.apiVersion = '1.1';
}

/**
* Get `Me` object instance
*
* @api public
*/

WPCOM.prototype.me = function () {
return new Me(this);
};

/**
* Get `Site` object instance
*
* @param {String} id
* @api public
*/

WPCOM.prototype.site = function (id) {
return new Site(id, this);
};

/**
* Get `Users` object instance
*
* @api public
*/

WPCOM.prototype.users = function () {
return new Users(this);
};

WPCOM.prototype.batch = function () {
return new Batch(this);
};

/**
* List Freshly Pressed Posts
*
* @param {Object} [query]
* @param {Function} fn callback function
* @api public
*/

WPCOM.prototype.freshlyPressed = function (query, fn) {
return this.req.get('/freshly-pressed', query, fn);
};

/**
* Expose send-request
* @TODO: use `this.req` instead of this method
*/

WPCOM.prototype.sendRequest = function (params, query, body, fn) {
var msg = 'WARN! Don use `sendRequest() anymore. Use `this.req` method.';
if (console && console.warn) {
//eslint-disable-line no-console
console.warn(msg); //eslint-disable-line no-console
} else {
console.log(msg); //eslint-disable-line no-console
}

return sendRequest.call(this, params, query, body, fn);
};

if (!Promise.prototype.timeout) {
/**
* Returns a new promise with a deadline
*
* After the timeout interval, the promise will
* reject. If the actual promise settles before
* the deadline, the timer is cancelled.
*
* @param {number} delay how many ms to wait
* @returns {Promise}
*/
Promise.prototype.timeout = function () {
var _this = this;

var delay = arguments.length <= 0 || arguments[0] === undefined ? DEFAULT_ASYNC_TIMEOUT : arguments[0];

var cancelTimeout = undefined,
timer = undefined,
timeout = undefined;

timeout = new Promise(function (resolve, reject) {
timer = setTimeout(function () {
reject(new Error('Action timed out while waiting for response.'));
}, delay);
});

cancelTimeout = function () {
clearTimeout(timer);
return _this;
};

return Promise.race([this.then(cancelTimeout)['catch'](cancelTimeout), timeout]);
};
}

/**
* Expose `WPCOM` module
*/

module.exports = WPCOM;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file here? shouldn't this be .git-ignored and build on install?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of in 4a1cb85

Loading