Skip to content

Commit

Permalink
Merge pull request #45 from spmjs/feat1.0.0
Browse files Browse the repository at this point in the history
Feat1.0.0
  • Loading branch information
soda-x committed Dec 8, 2015
2 parents ef8991c + 4fe3f21 commit a86f3fc
Show file tree
Hide file tree
Showing 41 changed files with 196 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Thumbs.db
*.log
*.sublime-project
*.sublime-workspace
node_modules/
node_modules/*
tmp/
.spm-build
.buildpath
Expand Down
6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ program
.version(require('./package').version, '-v, --version')
.option('-I, --input-directory <dir>', 'input directory, default: current working directory')
.option('-O, --output-directory <dir>', 'output directory, default: dist')
.option('-f, --force', 'force install dependencies from registry')
//.option('-f, --force', 'force install dependencies from registry')
.option('-c, --clean', 'clean dest directory first')
.option('-w, --watch', 'watch mode')
.option('-r, --registry <url>', 'registry url of repository server')
//.option('-r, --registry <url>', 'registry url of repository server')
.option('--umd [umd]', 'UMD-wrapped version with given global name')
.option('--global <global>', 'replace package name to global variable, format jquery:$,underscore:_')
.option('--debug', 'build files without compress')
.option('--verbose', 'show more logging')
.option('--progress', 'show progress')
.option('--no-color', 'disable colorful print')
.option('--no-install', 'disable install')
//.option('--no-install', 'disable install')
.option('--sourcemap', 'enable sourcemap for build')
.option('--define [yourMode]', 'using the value of pkg.spm.define.yourMode or pkg.spm.define.default when "yourMode" is not specified')
.parse(process.argv);
Expand Down
60 changes: 32 additions & 28 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ProgressPlugin = require('webpack/lib/ProgressPlugin');
var qs = require('qs');

var SPMWebpackPlugin = require('./SPMWebpackPlugin');
//var SPMWebpackPlugin = require('./SPMWebpackPlugin');
var FixCSSPathPlugin = require('./FixCSSPathPlugin');
var SPMPlugins = require('./SPMPlugins');
var getFiles = require('./getFiles');
var getArgs = require('./getArgs');

var co = require('co');
var install = co(require('spm-client/lib/install'));
//var co = require('co');
//var install = co(require('spm-client/lib/install'));

var utils = require('./utils');
var normalize = utils.normalizeLoader;

module.exports = function build(opts, callback) {
installDeps(opts, function() {
checkDeps(opts, function() {
// get opts
var webpackOpts = getWebpackOpts(opts);

Expand Down Expand Up @@ -58,13 +58,13 @@ Object.defineProperty(module.exports, 'getWebpackOpts', {
}
});

Object.defineProperty(module.exports, 'installDeps', {
Object.defineProperty(module.exports, 'checkDeps', {
get: function() {
return installDeps;
return checkDeps;
}
});

function installDeps(opts, callback) {
function checkDeps(opts, callback) {
var cwd = opts.cwd = opts.cwd || process.cwd();

log.config({quiet: opts.quiet, verbose: opts.verbose});
Expand All @@ -75,26 +75,30 @@ function installDeps(opts, callback) {
pkg = opts.pkg = JSON.parse(readFile(join(cwd, 'package.json'), 'utf-8'));
}

// Get deps to install.
var query = [];
if (!opts.noInstall && pkg && pkg.spm && pkg.spm.dependencies) {
for (var k in pkg.spm.dependencies) {
query.push(k+'@'+pkg.spm.dependencies[k]);
}
}

install({
name: query,
cwd: cwd,
registry: pkg && pkg.spm && pkg.spm.registry
}, function(err) {
if (err) {
log.error('exit', err.message);
console.log();
process.exit(1);
}
callback();
});
callback();
/**
* spmjs.io -> npm
*/
//// Get deps to install.
//var query = [];
//if (!opts.noInstall && pkg && pkg.spm && pkg.spm.dependencies) {
// for (var k in pkg.spm.dependencies) {
// query.push(k+'@'+pkg.spm.dependencies[k]);
// }
//}
//
//install({
// name: query,
// cwd: cwd,
// registry: pkg && pkg.spm && pkg.spm.registry
//}, function(err) {
// if (err) {
// log.error('exit', err.message);
// console.log();
// process.exit(1);
// }
// callback();
//});
}

function getWebpackOpts(opts, callback) {
Expand Down Expand Up @@ -179,7 +183,7 @@ function getWebpackOpts(opts, callback) {
]
},
plugins: [
new SPMWebpackPlugin(cwd),
//new SPMWebpackPlugin(cwd),
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]),
new FixCSSPathPlugin(opts.build.debug)
]
Expand Down
90 changes: 71 additions & 19 deletions test/build-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,27 @@ describe('lib/build.js', function() {
assert(dest, 'hash');
});

it('vendor', function*() {
yield build({
debug: true,
cwd: join(fixtures, 'js-entry'),
dest: dest,
vendor: ['a']
});
assert(dest, 'js-entry-vendor');
});

it('vendor-with-name-and-version', function*() {
yield build({
debug: true,
cwd: join(fixtures, 'vendor-with-name-and-version'),
dest: dest,
vendor: ['a']
});
assert(dest, 'vendor-with-name-and-version');
});
//xit('vendor', function*() {
// console.log(join(fixtures, 'js-entry'))
// yield build({
// debug: true,
// cwd: join(fixtures, 'js-entry'),
// dest: dest,
// vendor: ["a"],
// verbose: true
// });
// assert(dest, 'js-entry-vendor');
//});
//
//xit('vendor-with-name-and-version', function*() {
// yield build({
// debug: true,
// cwd: join(fixtures, 'vendor-with-name-and-version'),
// dest: dest,
// vendor: ['a']
// });
// assert(dest, 'vendor-with-name-and-version');
//});

it('common', function*() {
yield build({
Expand Down Expand Up @@ -345,6 +347,56 @@ describe('lib/build.js', function() {
assert(dest, 'html-minify-enable');
});

describe('vendor', function() {

var oldCwd;

before(function() {
oldCwd = process.cwd();
process.chdir(join(fixtures, 'js-entry'));
});

after(function() {
process.chdir(oldCwd);
});

it('vendor', function*() {
yield build({
debug: true,
cwd: join(fixtures, 'js-entry'),
dest: dest,
vendor: ['a']
});
assert(dest, 'js-entry-vendor');
});

});

describe('vendor-with-name-and-version', function() {

var oldCwd;

before(function() {
oldCwd = process.cwd();
process.chdir(join(fixtures, 'vendor-with-name-and-version'));
});

after(function() {
process.chdir(oldCwd);
});

it('vendor-with-name-and-version', function*() {
yield build({
debug: true,
cwd: join(fixtures, 'vendor-with-name-and-version'),
dest: dest,
vendor: ['a']
});
assert(dest, 'vendor-with-name-and-version');
});

});

describe('css-output-custom-loader', function() {

var oldCwd;
Expand Down
22 changes: 12 additions & 10 deletions test/expected/js-entry-no-pkg/a.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,45 @@

'use strict';

__webpack_require__(3);
__webpack_require__(2);
__webpack_require__(5);
__webpack_require__(4);

console.log('entry');

/***/ },
/* 2 */
/***/ function(module, exports) {
/***/ function(module, exports, __webpack_require__) {

'use strict';

console.log('relative');
console.log('a');

__webpack_require__(3);

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {


console.log('a');
/***/ function(module, exports) {

__webpack_require__(5);
'use strict';

console.log('b');

/***/ },
/* 4 */
/***/ function(module, exports) {

console.log('private in a');
'use strict';

console.log('private in a');

/***/ },
/* 5 */
/***/ function(module, exports) {

console.log('b');
'use strict';

console.log('relative');

/***/ }
/******/ ]);
22 changes: 12 additions & 10 deletions test/expected/js-entry-umd/a.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,45 @@ return /******/ (function(modules) { // webpackBootstrap

'use strict';

__webpack_require__(3);
__webpack_require__(2);
__webpack_require__(5);
__webpack_require__(4);

console.log('entry');

/***/ },
/* 2 */
/***/ function(module, exports) {
/***/ function(module, exports, __webpack_require__) {

'use strict';

console.log('relative');
console.log('a');

__webpack_require__(3);

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {


console.log('a');
/***/ function(module, exports) {

__webpack_require__(5);
'use strict';

console.log('b');

/***/ },
/* 4 */
/***/ function(module, exports) {

console.log('private in a');
'use strict';

console.log('private in a');

/***/ },
/* 5 */
/***/ function(module, exports) {

console.log('b');
'use strict';

console.log('relative');

/***/ }
/******/ ])
Expand Down
12 changes: 7 additions & 5 deletions test/expected/js-entry-vendor/a.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ webpackJsonp([1],[
'use strict';

__webpack_require__(1);
__webpack_require__(3);
__webpack_require__(5);
__webpack_require__(4);

console.log('entry');

/***/ },
/* 3 */
/* 3 */,
/* 4 */
/***/ function(module, exports) {

'use strict';

console.log('relative');
console.log('private in a');

/***/ },
/* 4 */
/* 5 */
/***/ function(module, exports) {

console.log('private in a');
'use strict';

console.log('relative');

/***/ }
]);

0 comments on commit a86f3fc

Please sign in to comment.