Permalink
Browse files

spm build should work now

  • Loading branch information...
1 parent f5082dd commit ef9945b7256b9534d0e67b7ba546b0e89a260e4d @lepture lepture committed Apr 11, 2013
Showing with 437 additions and 3 deletions.
  1. +27 −0 .gitignore
  2. +40 −1 bin/spm-build
  3. +62 −0 index.js
  4. +294 −0 lib/config.js
  5. +14 −2 package.json
View
@@ -0,0 +1,27 @@
+*.iml
+.idea/
+.ipr
+.iws
+*~
+~*
+*.diff
+*.patch
+*.bak
+.DS_Store
+Thumbs.db
+.project
+.*proj
+.svn/
+*.swp
+*.swo
+*.log
+*.sublime-project
+*.sublime-workspace
+node_modules/
+dist/
+tmp/
+.spm-build
+.buildpath
+.settings
+.yml
+_site
View
@@ -1,3 +1,42 @@
#!/usr/bin/env node
-var build = require('..');
+var commander = require('commander');
+require('colorful').colorful();
+var spm = require('..');
+
+commander.usage('[options]');
+
+commander
+ .option('-I, --input-directory <dir>', 'input directory: [src]')
+ .option('-O, --output-directory <dir>', 'output directory: [dist]')
+ .option('-v, --verbose', 'show more logs')
+ .option('-q, --quiet', 'show less logs')
+ .option('--encoding <encoding>', 'file encoding: [utf8]')
+ .option('--no-color', 'disable colorful print');
+
+
+commander.on('--help', function() {
+ console.log();
+ console.log(' ' + 'Examples:'.to.bold.blue.color);
+ console.log();
+ console.log(' Build a standard cmd module is simple');
+ console.log();
+ console.log(' $ ' + 'spm build'.to.magenta.color);
+ console.log();
+ console.log(' Build from another source');
+ console.log();
+ console.log(' $ ' + 'spm build'.to.magenta.color + ' ' + '-I'.to.cyan.color + ' lib ' + '-O'.to.cyan.color + ' dist');
+ console.log();
+ console.log(' For more information: ' + 'http://docs.spmjs.org/en/build'.to.underline.color);
+ console.log();
+});
+
+
+commander.parse(process.argv);
+
+// verbose vs quiet
+spm.log.config(commander);
+
+// run install
+console.log();
+spm.build(commander);
View
@@ -0,0 +1,62 @@
+var path = require('path');
+var spmrc = require('spmrc');
+var grunt = require('spm-grunt');
+
+exports = module.exports = function(options) {
+ options = options || {};
+ var pkgfile = options.pkgfile || 'package.json';
+ var pkg = {};
+ if (grunt.file.exists(pkgfile)) {
+ pkg = grunt.file.readJSON('package.json');
+ }
+
+ var installpath = spmrc.get('install.path');
+ options.paths = [installpath];
+ if (installpath !== 'sea-modules') {
+ options.paths.push('sea-modules');
+ }
+ var globalpath = path.join(spmrc.get('user.home'), '.spm', 'sea-modules');
+ options.paths.push(globalpath);
+
+ var scripts = pkg.scripts || {};
+ if (scripts.build) {
+ childexec(scripts.build, function() {
+ log.info('success', 'build finished.');
+ });
+ } else {
+ grunt.invokeTask('build', options, function(grunt) {
+ exports.loadBuildTasks(options, pkg);
+ grunt.task.options({'done': function() {
+ log.info('success', 'build finished.');
+ }});
+ grunt.registerInitTask('build', ['spm-build']);
+ });
+ }
+};
+
+exports.loadBuildTasks = function(options, pkg) {
+ grunt.log.writeln('load spm-build');
+ options = options || {};
+ pkg = pkg || grunt.file.readJSON('package.json');
+
+ var config = {pkg: pkg};
+ config.src = options.inputDirectory || 'src';
+ config.dest = options.outputDirectory || 'dist';
+ config.paths = options.paths || ['sea-modules'];
+
+ require('./lib/config').initConfig(grunt, config);
+
+ [
+ 'grunt-cmd-transport',
+ 'grunt-cmd-concat',
+ 'grunt-contrib-uglify',
+ 'grunt-contrib-copy',
+ 'grunt-contrib-cssmin',
+ 'grunt-contrib-clean'
+ ].forEach(function(task) {
+ var taskdir = path.join(__dirname, 'node_modules', task, 'tasks');
+ if (grunt.file.exists(taskdir)) {
+ grunt.loadTasks(taskdir);
+ }
+ });
+};
Oops, something went wrong.

0 comments on commit ef9945b

Please sign in to comment.