├── .editorconfig ├── .gitignore ├── .jshintignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── HISTORY.md ├── Makefile ├── README.md ├── cli.js ├── lib ├── build.js ├── generatePackageJSON.js ├── getArgs.js ├── getDepFiles.js ├── getDuplicate.js ├── getExtraDeps.js ├── getFiles.js ├── index.js ├── logArgs.js └── utils.js ├── package.json └── test ├── build.js ├── expected ├── autoprefixer │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ └── a.css ├── copy-img │ └── a │ │ └── 0.1.0 │ │ └── a.gif ├── css-package │ └── a │ │ └── 1.0.0 │ │ └── src │ │ ├── a-debug.css │ │ └── a.css ├── css-resources │ ├── a.png │ ├── b-debug.css │ ├── b.css │ ├── b_0_2_0_a.jpg │ └── css │ │ ├── a-debug.css │ │ └── a.css ├── entry-without-pkg │ ├── a-debug.js │ └── a.js ├── entry │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.js │ │ └── a.js ├── extra-deps │ └── a │ │ └── 0.1.0 │ │ ├── index-debug.js │ │ └── index.js ├── hash │ └── a │ │ ├── a-626a1277-debug.js │ │ └── a-626a1277.js ├── multiple-versions │ └── a │ │ └── 0.1.0 │ │ ├── index-debug.js │ │ ├── index.js │ │ ├── output-debug.js │ │ └── output.js ├── nodeps-ignore │ └── a │ │ └── 0.1.0 │ │ ├── index-debug.js │ │ └── index.js ├── normal-all │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-empty-idleading │ ├── a-debug.css │ ├── a-debug.js │ ├── a.css │ └── a.js ├── normal-global │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-ignore │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-standalone-ignore │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-standalone │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-umd │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── normal-withDeps │ ├── a │ │ └── 0.1.0 │ │ │ ├── a-debug.css │ │ │ ├── a-debug.js │ │ │ ├── a.css │ │ │ └── a.js │ └── type │ │ └── 0.1.0 │ │ ├── index-debug.js │ │ └── index.js ├── normal │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js ├── package-file │ └── a │ │ └── 0.1.0 │ │ ├── a-debug.css │ │ ├── a-debug.js │ │ ├── a.css │ │ └── a.js └── to5 │ └── a │ └── 0.1.0 │ ├── a-debug.js │ └── a.js ├── fixtures ├── autoprefixer │ ├── a.css │ └── package.json ├── copy-img │ ├── a.gif │ └── package.json ├── css-package │ ├── b.css │ ├── package.json │ └── src │ │ └── a.css ├── css-resources │ ├── b.css │ ├── css │ │ └── a.css │ ├── img │ │ └── a.png │ ├── package.json │ └── spm_modules │ │ └── b │ │ └── 0.2.0 │ │ ├── a.jpg │ │ ├── b.css │ │ └── package.json ├── entry-without-pkg │ └── a.js ├── entry │ ├── a.js │ ├── index.js │ └── package.json ├── extra-deps │ ├── a.css │ ├── a.handlebars │ ├── index.js │ ├── package.json │ └── spm_modules │ │ ├── handlebars-runtime │ │ └── 1.3.0 │ │ │ ├── dist │ │ │ └── cjs │ │ │ │ └── handlebars.runtime.js │ │ │ └── package.json │ │ └── import-style │ │ └── 1.0.0 │ │ ├── index.js │ │ └── package.json ├── get-args │ └── package.json ├── get-files │ ├── package.json │ └── src │ │ └── index │ │ ├── index.css │ │ ├── index.html │ │ └── index.js ├── hash │ ├── a.js │ └── package.json ├── multiple-versions │ ├── index.js │ ├── output.js │ ├── package.json │ ├── relative.js │ └── spm_modules │ │ ├── b │ │ └── 0.1.0 │ │ │ ├── index.js │ │ │ └── package.json │ │ └── c │ │ ├── 0.1.0 │ │ ├── index.js │ │ └── package.json │ │ └── 0.1.1 │ │ ├── index.js │ │ └── package.json ├── nodeps-ignore │ ├── index.js │ └── package.json ├── normal │ ├── a.css │ ├── a.js │ ├── package.json │ └── spm_modules │ │ └── type │ │ └── 0.1.0 │ │ ├── index.js │ │ ├── package.json │ │ └── type.css ├── package-file │ ├── a.css │ ├── a.js │ ├── package.json │ └── spm_modules │ │ └── type │ │ └── 0.1.0 │ │ ├── b.js │ │ ├── index.js │ │ ├── package.json │ │ └── type.css ├── scripts │ └── package.json └── to5 │ ├── a.js │ └── package.json ├── getArgs.js └── getFiles.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [Makefile] 16 | indent_style = tab 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | .ipr 4 | .iws 5 | *~ 6 | ~* 7 | *.diff 8 | *.patch 9 | *.bak 10 | .DS_Store 11 | Thumbs.db 12 | .project 13 | .*proj 14 | .svn/ 15 | *.swp 16 | *.swo 17 | *.log 18 | *.sublime-project 19 | *.sublime-workspace 20 | node_modules/ 21 | tmp/ 22 | .spm-build 23 | .buildpath 24 | .settings 25 | .yml 26 | _site 27 | sea-modules 28 | coverage 29 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | test/fixtures 4 | test/expected 5 | tmp 6 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "expr": true, 3 | "eqeqeq": true, 4 | "eqnull": true, 5 | "indent": 2, 6 | "latedef": "nofunc", 7 | "newcap": true, 8 | "quotmark": true, 9 | "trailing": true, 10 | "undef": true, 11 | "unused": true, 12 | "lastsemic": true, 13 | "boss": true, 14 | "funcscope": true, 15 | "loopfunc": true, 16 | "smarttabs": true, 17 | "sub": true, 18 | "strict": true, 19 | "node": true, 20 | "esnext": true, 21 | "globals": { 22 | "describe": false, 23 | "xdescribe": false, 24 | "it": false, 25 | "xit": false, 26 | "before": false, 27 | "beforeEach": false, 28 | "after": false, 29 | "afterEach": false, 30 | "define": false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | docs/ 3 | coverage/ 4 | node_modules/ 5 | tmp/ 6 | .idea/ 7 | .npmignore 8 | .editorconfig 9 | .travis.yml 10 | .jshintrc 11 | .DS_Store 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.11" 5 | - "0.12" 6 | - "iojs" 7 | 8 | after_success: make coveralls 9 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # History 2 | 3 | --- 4 | 5 | ## 1.0.1 6 | 7 | - Fix: include don't work, Close #5 8 | - Fix: registry is hardcoded 9 | 10 | ## 1.0.0 11 | 12 | - Feat: parse ~ prefix css deps as module, else as file 13 | 14 | ## 0.1.0 15 | 16 | - First version, view more history is [spm-build](https://github.com/spmjs/spm/blob/master/HISTORY.md). 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: jshint 2 | node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -R spec -t 20000 --require should --require co-mocha --inline-diffs 3 | 4 | coveralls: test 5 | cat ./coverage/lcov.info | ./node_modules/.bin/coveralls 6 | 7 | debug: 8 | node --harmony $(NODE_DEBUG) ./node_modules/.bin/_mocha -R spec -t 20000 --require should --require co-mocha --inline-diffs 9 | 10 | jshint: 11 | @./node_modules/.bin/jshint . 12 | 13 | .PHONY: test 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spm-sea 2 | 3 | [![NPM version](https://img.shields.io/npm/v/spm-sea.svg?style=flat)](https://npmjs.org/package/spm-sea) 4 | [![Build Status](https://img.shields.io/travis/spmjs/spm-sea.svg?style=flat)](https://travis-ci.org/spmjs/spm-sea) 5 | [![Coverage Status](https://img.shields.io/coveralls/spmjs/spm-sea.svg?style=flat)](https://coveralls.io/r/spmjs/spm-sea) 6 | [![NPM downloads](http://img.shields.io/npm/dm/spm-sea.svg?style=flat)](https://npmjs.org/package/spm-sea) 7 | 8 | SPM project bundler in seajs. 9 | 10 | --- 11 | 12 | ## Install 13 | 14 | ```bash 15 | $ npm install spm-sea -g 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```bash 21 | $ spm-sea [option] [file] 22 | ``` 23 | 24 | ## LISENCE 25 | 26 | Copyright (c) 2015-2114 chencheng. Licensed under the MIT license. 27 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | require('colorful').colorful(); 6 | require('gnode'); 7 | require('babel-core/register')({ 8 | ignore: '', 9 | only: /scripts-hook\/_index/ 10 | }); 11 | 12 | var program = require('commander'); 13 | var log = require('spm-log'); 14 | var join = require('path').join; 15 | var exists = require('fs').existsSync; 16 | var readFile = require('fs').readFileSync; 17 | var Build = require('./lib').Build; 18 | var hook = require('scripts-hook'); 19 | 20 | program 21 | .option('-I, --input-directory ', 'input directory, default: current working directory') 22 | .option('-O, --output-directory ', 'output directory, default: dist') 23 | .option('-o, --output-file ', 'output file') 24 | .option('-f, --force', 'force to clean dest directory first') 25 | .option('-r, --registry ', 'registry url of yuan server') 26 | .option('--include ', 'file include mode with seajs, optional: self, relative, all') 27 | .option('--global ', 'replace package name to global variable, format jquery:$,underscore:_') 28 | .option('--ignore ', 'determine which id will not be transported') 29 | .option('--skip ', 'determine which id will not be parsed when analyse') 30 | .option('--idleading [idleading]', 'prefix of module name, default: {{name}}/{{version}}') 31 | .option('--with-deps', 'build package in dependencies') 32 | .option('--verbose', 'show more logging') 33 | .option('--no-color', 'disable colorful print') 34 | .option('--no-install', 'disable install') 35 | .parse(process.argv); 36 | 37 | log.config(program); 38 | 39 | var cwd = join(process.cwd(), program.inputDirectory || ''); 40 | var file = join(cwd, 'package.json'); 41 | var pkg = exists(file) && JSON.parse(readFile(file, 'utf-8')) || {}; 42 | var entry = program.args; 43 | 44 | var info = ''; 45 | if (entry.length) { 46 | info = 'build ' + entry.join(','); 47 | } else if (!pkg || !pkg.spm) { 48 | console.log(); 49 | log.error('miss', 'package.json or "spm" key'); 50 | console.log(); 51 | process.exit(1); 52 | } else { 53 | var pkgId = pkg.name && pkg.version && (pkg.name + '@' + pkg.version) || ''; 54 | info = ('build ' + pkgId).to.magenta.color; 55 | } 56 | 57 | var begin = Date.now(); 58 | console.log(); 59 | log.info('start', info); 60 | 61 | var args = { 62 | dest: program.outputDirectory, 63 | cwd: cwd, 64 | outputFile: program.outputFile, 65 | 66 | include: program.include, 67 | ignore: program.ignore, 68 | global: program.global, 69 | skip: program.skip, 70 | idleading: program.idleading, 71 | registry: program.registry || (pkg.spm && pkg.spm.registry), 72 | 73 | withDeps: program.withDeps, 74 | zip: program.zip, 75 | force: program.force, 76 | install: program.install, 77 | 78 | originPkg: pkg, 79 | entry: entry 80 | }; 81 | 82 | var scripts = pkg && pkg.spm && pkg.spm.scripts || {}; 83 | hook(scripts, 'build', function(done) { 84 | new Build(args) 85 | .getArgs() 86 | .installDeps() 87 | .parsePkg() 88 | .addCleanTask() 89 | .run(function(err) { 90 | if (err) { 91 | log.error(err.message); 92 | log.error(err.stack); 93 | process.exit(1); 94 | } 95 | 96 | done(); 97 | }); 98 | }).then(function() { 99 | log.info('finish', info + showDiff(begin)); 100 | console.log(); 101 | }, function() {}); 102 | 103 | function showDiff(time) { 104 | var diff = Date.now() - time; 105 | return (' (' + diff + 'ms)').to.gray.color; 106 | } 107 | -------------------------------------------------------------------------------- /lib/build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('colorful').colorful(); 4 | 5 | var debug = require('debug')('spm-sea'); 6 | var relative = require('path').relative; 7 | var join = require('path').join; 8 | var client = require('spm-client'); 9 | var vfs = require('vinyl-fs'); 10 | var Package = require('father').SpmPackage; 11 | var rimraf = require('rimraf'); 12 | var pipe = require('multipipe'); 13 | var log = require('spm-log'); 14 | var spmrc = require('spmrc'); 15 | var extend = require('extend'); 16 | var flatten = require('flatten'); 17 | var cdeps = require('cdeps'); 18 | var Step = require('step.js'); 19 | var thunkify = require('thunkify'); 20 | var unyield = require('unyield'); 21 | var through = require('through2'); 22 | 23 | var _if = require('gulp-if'); 24 | var mirror = require('gulp-mirror'); 25 | var spm = require('gulp-spm'); 26 | var size = require('gulp-size2'); 27 | var uglify = require('gulp-uglify'); 28 | var cssmin = require('gulp-minify-css'); 29 | var zip = require('gulp-zip'); 30 | var autoprefixer = require('gulp-autoprefixer'); 31 | var to5 = require('gulp-6to5'); 32 | 33 | var logArgs = require('./logArgs'); 34 | var getArgs = require('./getArgs'); 35 | var getFiles = require('./getFiles'); 36 | var getDepFiles = require('./getDepFiles'); 37 | var getExtraDeps = require('./getExtraDeps'); 38 | var getDuplicate = require('./getDuplicate'); 39 | var generatePackageJSON = require('./generatePackageJSON'); 40 | var utils = require('./utils'); 41 | 42 | module.exports = Build; 43 | 44 | function Build(opt) { 45 | if (!(this instanceof Build)) return new Build(opt); 46 | this.opt = opt || {}; 47 | this.plugins = new Step(); 48 | this.plugins.run = thunkify(this.plugins.run); 49 | this.fns = this.plugins.fns; 50 | } 51 | 52 | /** 53 | * Add plugin. 54 | */ 55 | Build.prototype.use = function(fn) { 56 | if (this.plugins.fns.indexOf(fn) > -1) return this; 57 | var name = fn.name || '(anonymous)'; 58 | debug('using plugin: %s', name); 59 | this.plugins.use(fn); 60 | return this; 61 | }; 62 | 63 | /** 64 | * Start build. 65 | */ 66 | Build.prototype.run = unyield(function *() { 67 | // Run Plugins. 68 | yield this.plugins.run.call(this); 69 | 70 | var files = this.files; 71 | var args = this.args; 72 | 73 | // Build stream 74 | yield function(cb) { 75 | var ignore = through.obj(function(file, enc, cb) { cb(); }); 76 | var stream = pipe( 77 | vfs.src(files, {cwd: args.cwd, cwdbase: true}), 78 | _if(args['6to5'], _if(utils.isJs, to5(args['6to5']))), 79 | mirror( 80 | // normal 81 | pipe( 82 | spm(args), 83 | _if(utils.isJs, uglify(args.uglify)), 84 | _if(utils.isCSS, pipe( 85 | _if(args.autoprefixer, autoprefixer(args.autoprefixer)), 86 | cssmin(args.cssmin) 87 | )), 88 | size({gzip:true, showFiles:true, log:function(title, what, size) { 89 | size = ((size/1024.0).toFixed(2) + 'kB').to.magenta; 90 | log.info('size', what + ' ' + size + ' (gzipped)'.to.gray); 91 | }}) 92 | ), 93 | // debug 94 | _if(!!args.outputFile, ignore, pipe( 95 | spm(extend({}, args, {rename: {hash:args.hash,debug:true}})), 96 | _if(utils.isCSS, pipe( 97 | _if(args.autoprefixer, autoprefixer(args.autoprefixer)) 98 | )) 99 | )) 100 | ), // end mirror 101 | _if(!!args.outputFile, through.obj(function(file, enc, cb) { 102 | file.path = join(args.cwd, args.outputFile); 103 | cb(null, file); 104 | })), 105 | vfs.dest(args.outputFile ? args.cwd : args.dest).on('data', function(file) { 106 | log.info('generate file', relative(args.cwd, file.path)); 107 | }), 108 | _if(args.zip, pipe(zip('archive.zip'), vfs.dest(args.dest))) 109 | ); // end stream pipe 110 | 111 | stream.once('error', cb).once('end', cb).resume(); 112 | }; // end stream yield 113 | }); 114 | 115 | var Plugins = { 116 | 117 | /** 118 | * Merge args from arguments and spm.buildArgs in package.json. 119 | */ 120 | getArgs: function() { 121 | var args = this.args = getArgs(this.opt); 122 | 123 | if (args.outputFile && !args.entry.length) { 124 | log.error('error', '--output-file should be together with entry file'); 125 | console.log(); 126 | process.exit(1); 127 | } 128 | 129 | logArgs(args); 130 | 131 | // Try to generate package.json if entry is supplied 132 | if (args.entry.length) { 133 | generatePackageJSON(this.args); 134 | } 135 | }, 136 | 137 | /** 138 | * Install deps. 139 | */ 140 | installDeps: function* () { 141 | var args = this.args; 142 | if (args.entry.length) { 143 | var deps = flatten(args.entry.map(function(item) { 144 | return cdeps(join(args.cwd, item)); 145 | })); 146 | log.info('entry deps', deps.join(', ')); 147 | yield* client.install({cwd:args.cwd, registry:args.registry, name:deps, save:true}); 148 | } else if (args.install) { 149 | yield* client.install({cwd:args.cwd, registry:args.registry}); 150 | } 151 | }, 152 | 153 | /** 154 | * Parse pkg, files and dep files. 155 | */ 156 | parsePkg: function* () { 157 | var args = this.args; 158 | 159 | // Parse pkg 160 | var pkg = new Package(args.cwd, { 161 | ignore: args.ignore, 162 | skip: args.skip, 163 | moduleDir: spmrc.get('install.path'), 164 | entry: args.entry 165 | }); 166 | args.pkg = pkg; 167 | log.debug('package', 'analyse infomation'); 168 | log.debug('package', 'dependencies: ' + Object.keys(pkg.dependencies)); 169 | log.debug('package', 'files: ' + Object.keys(pkg.files)); 170 | 171 | // Get files to build 172 | var files = args.entry.length ? args.entry : getFiles(pkg); 173 | log.info('output', 'files: ' + files); 174 | 175 | // Check duplicate 176 | var dups = getDuplicate(files, pkg); 177 | for (var k in dups) { 178 | log.warn('duplicate', '%s (%s) while build %s'.to.yellow.color, 179 | k, dups[k].versions, dups[k].file.path); 180 | } 181 | 182 | // Include files in dependent packages 183 | var depFilesMap; 184 | if (args.withDeps) { 185 | var dep = getDepFiles(pkg); 186 | files = files.concat(dep.files); 187 | depFilesMap = dep.filesMap; 188 | log.info('withDeps', 'files: ' + files); 189 | } 190 | 191 | this.files = files; 192 | this.depFilesMap = depFilesMap; 193 | 194 | // Get extra deps 195 | if (!arguments[0]) { 196 | var extraDeps = getExtraDeps(this.files, args.pkg, this.depFilesMap); 197 | log.info('extra deps', extraDeps.length ? extraDeps.join(',') : 'no'); 198 | if (extraDeps && extraDeps.length) { 199 | log.info('extra deps', 'install extra deps'); 200 | yield* client.install({ 201 | cwd: args.cwd, 202 | registry: args.registry, 203 | save: true, 204 | name: extraDeps 205 | }); 206 | 207 | // Call self to parse again 208 | yield* Plugins.parsePkg.call(this, true); 209 | } 210 | } 211 | }, 212 | 213 | /** 214 | * Add clean task before build. 215 | */ 216 | addCleanTask: function() { 217 | var args = this.args; 218 | 219 | // Clean dest folder 220 | if (args.force) { 221 | var target = args.outputFile || args.dest; 222 | log.info('clean', target); 223 | rimraf.sync(target); 224 | } 225 | } 226 | }; 227 | 228 | // Map plugins to proto 229 | Object.keys(Plugins).forEach(function(name) { 230 | Build.prototype[name] = function() { 231 | return this.use(Plugins[name]); 232 | }; 233 | }); 234 | -------------------------------------------------------------------------------- /lib/generatePackageJSON.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var join = require('path').join; 4 | var exists = require('fs').existsSync; 5 | var writeFile = require('fs').writeFileSync; 6 | 7 | module.exports = function(args) { 8 | var file = join(args.cwd, 'package.json'); 9 | if (exists(file)) { 10 | return; 11 | } 12 | 13 | var pkg = { 14 | spm: {} 15 | }; 16 | writeFile(file, JSON.stringify(pkg, null, 2)); 17 | }; 18 | -------------------------------------------------------------------------------- /lib/getArgs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var join = require('path').join; 4 | var resolve = require('path').resolve; 5 | var exists = require('fs').existsSync; 6 | var readFile = require('fs').readFileSync; 7 | var mixarg = require('mixarg'); 8 | var spmrc = require('spmrc'); 9 | 10 | var defaults = { 11 | // from command 12 | cwd: process.cwd(), 13 | dest: 'dist', 14 | zip: false, 15 | force: false, 16 | withDeps: false, 17 | install: true, 18 | 19 | // build config 20 | ignore: '', 21 | skip: '', 22 | idleading: '{{name}}/{{version}}', 23 | global: '', 24 | 25 | // other 26 | uglify: {output:{ascii_only:true}}, 27 | cssmin: {}, 28 | entry: [], 29 | registry: spmrc.get('registry') || 'http://spmjs.io' 30 | }; 31 | 32 | module.exports = function(opt) { 33 | var cwd = opt.cwd = opt.cwd || process.cwd(); 34 | var file = join(cwd, 'package.json'); 35 | var pkg = exists(file) && JSON.parse(readFile(file, 'utf-8')) || {}; 36 | var spm = pkg.spm || {}; 37 | 38 | var args = mixarg(defaults, spm.buildArgs || '', spm, opt); 39 | args.dest = resolve(cwd, args.O || args.dest); 40 | 41 | if (typeof args.ignore === 'string') args.ignore = args.ignore ? args.ignore.split(/\s*,\s*/) : []; 42 | if (typeof args.skip === 'string') args.skip = args.skip ? args.skip.split(/\s*,\s*/) : []; 43 | args.global = getGlobal(args.global); 44 | args.skip = args.skip.concat(Object.keys(args.global)); 45 | 46 | args.include = args.include || args.sea || 'relative'; 47 | args.rename = {hash: !!args.hash}; 48 | 49 | return args; 50 | }; 51 | 52 | function getGlobal(str) { 53 | if (({}).toString.call(str) === '[object Object]') return str; 54 | if (typeof str !== 'string') return {}; 55 | 56 | var ret = {}; 57 | str.split(/\s*,\s*/).forEach(function(item) { 58 | var m = item.split(':'); 59 | if (m[1]) { 60 | ret[m[0]] = m[1].trim(); 61 | } 62 | }); 63 | return ret; 64 | } 65 | -------------------------------------------------------------------------------- /lib/getDepFiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var spmrc = require('spmrc'); 4 | var getFiles = require('./getFiles'); 5 | 6 | module.exports = function(pkg) { 7 | var filesMap = {}; 8 | var files = []; 9 | 10 | var depPkgs = getAllDependencies(pkg); 11 | for (var id in depPkgs) { 12 | var depPkg = depPkgs[id]; 13 | getFiles(depPkg).forEach(function(f) { 14 | var filepath = spmrc.get('install.path') + '/' + id.replace('@','/') + '/' + f; 15 | filesMap[filepath] = depPkg.files[f]; 16 | files.push(filepath); 17 | }); 18 | } 19 | 20 | return { 21 | files: files, 22 | filesMap: filesMap 23 | }; 24 | }; 25 | 26 | function getAllDependencies(pkg) { 27 | var result = {}; 28 | recurseDependencies(pkg); 29 | return result; 30 | 31 | function recurseDependencies(pkg) { 32 | Object.keys(pkg.dependencies).forEach(function(key) { 33 | var id = pkg.dependencies[key].id; 34 | if (!result[id]) { 35 | result[id] = pkg.dependencies[key]; 36 | recurseDependencies(pkg.dependencies[key]); 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/getDuplicate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(files, pkg) { 4 | var rootPkgName = pkg.name; 5 | var ret = {}; 6 | 7 | files.forEach(function(f) { 8 | var dup = {}; 9 | var file = pkg.files[f]; 10 | 11 | file.lookup(function (fileInfo) { 12 | var name = fileInfo.pkg.name; 13 | var version = fileInfo.pkg.version; 14 | if (name === rootPkgName) return; 15 | dup[name] = dup[name] || {}; 16 | dup[name][version] = true; 17 | }); 18 | 19 | for (var k in dup) { 20 | var versions = Object.keys(dup[k]); 21 | if (versions.length > 1) { 22 | ret[k] = {versions:versions, file:file}; 23 | } 24 | } 25 | }); 26 | 27 | return ret; 28 | }; 29 | -------------------------------------------------------------------------------- /lib/getExtraDeps.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var extname = require('path').extname; 4 | 5 | module.exports = function(files, pkg, depFilesMap) { 6 | var deps = {}; 7 | files.forEach(function(f) { 8 | if (extname(f) !== '.js') return; 9 | var file = (depFilesMap && depFilesMap[f]) || pkg.files[f]; 10 | if (!file) return; 11 | if (!pkg.dependencies['import-style'] && file.hasExt('css')) { 12 | deps['import-style'] = true; 13 | } 14 | if (!pkg.dependencies['handlebars-runtime'] && file.hasExt('handlebars')) { 15 | deps['handlebars-runtime'] = true; 16 | } 17 | }); 18 | return Object.keys(deps); 19 | }; 20 | -------------------------------------------------------------------------------- /lib/getFiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var join = require('path').join; 4 | var exists = require('fs').existsSync; 5 | var stat = require('fs').statSync; 6 | var uniq = require('uniq'); 7 | var glob = require('glob'); 8 | 9 | module.exports = function(pkg) { 10 | var files = []; 11 | 12 | if (exists(join(pkg.dest, pkg.main))) { 13 | files.push(pkg.main); 14 | } 15 | 16 | pkg.output.forEach(function(pattern) { 17 | var items = glob.sync(pattern, {cwd: pkg.dest}); 18 | items = items.filter(function(item) { 19 | return stat(join(pkg.dest, item)).isFile(); 20 | }); 21 | files = files.concat(items); 22 | }); 23 | 24 | return uniq(files); 25 | }; 26 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.Build = require('./build'); 4 | exports.getArgs = require('./getArgs'); 5 | exports.logArgs = require('./logArgs'); 6 | exports.getDepFiles = require('./getDepFiles'); 7 | exports.getDuplicate = require('./getDuplicate'); 8 | exports.getExtraDeps = require('./getExtraDeps'); 9 | exports.getFiles = require('./getFiles'); 10 | exports.utils = require('./utils'); 11 | -------------------------------------------------------------------------------- /lib/logArgs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var log = require('spm-log'); 4 | 5 | module.exports = function(args) { 6 | Object.keys(args).forEach(function(key) { 7 | if (key === 'pkg' || key === '_') return; 8 | var val = args[key]; 9 | if (typeof(val) === 'object') { 10 | val = JSON.stringify(val); 11 | } 12 | log.debug('arguments', key + ' = ' + val); 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var extname = require('path').extname; 4 | 5 | exports.isJs = function(file) { 6 | return extname(file.path) === '.js'; 7 | }; 8 | 9 | exports.isCSS = function(file) { 10 | return extname(file.path) === '.css'; 11 | }; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spm-sea", 3 | "version": "1.0.1", 4 | "description": "SPM project bundler in seajs.", 5 | "main": "lib/index", 6 | "dependencies": { 7 | "babel-core": "~4.7.16", 8 | "cdeps": "~0.1.0", 9 | "co": "~4.1.0", 10 | "colorful": "~2.1.0", 11 | "commander": "~2.5.0", 12 | "debug": "~2.1.1", 13 | "exeq": "~2.0.2", 14 | "extend": "~2.0.0", 15 | "father": "~1.0.0", 16 | "flatten": "0.0.1", 17 | "glob": "~4.3.1", 18 | "gnode": "~0.1.1", 19 | "gulp-6to5": "~2.0.2", 20 | "gulp-autoprefixer": "~2.1.0", 21 | "gulp-if": "~1.2.5", 22 | "gulp-minify-css": "~0.3.12", 23 | "gulp-mirror": "~0.3.1", 24 | "gulp-size2": "~0.4.0", 25 | "gulp-spm": "~1.0.0", 26 | "gulp-uglify": "~1.0.2", 27 | "gulp-zip": "~2.0.2", 28 | "mixarg": "~0.2.0", 29 | "multipipe": "~0.1.2", 30 | "rimraf": "~2.2.8", 31 | "scripts-hook": "~0.1.0", 32 | "spm-client": "~0.4.0", 33 | "spm-log": "~0.1.1", 34 | "spmrc": "~1.2.0", 35 | "step.js": "~2.0.5", 36 | "through2": "~0.6.3", 37 | "thunkify": "~2.1.2", 38 | "uniq": "~1.0.1", 39 | "unyield": "0.0.1", 40 | "vinyl-fs": "~0.3.13" 41 | }, 42 | "devDependencies": { 43 | "co-mocha": "~1.0.0", 44 | "coveralls": "2", 45 | "istanbul-harmony": "0", 46 | "jshint": "~2.5.11", 47 | "mocha": "1", 48 | "should": "3", 49 | "sinon": "~1.12.1" 50 | }, 51 | "repository": { 52 | "type": "git", 53 | "url": "https://github.com/spmjs/spm-sea" 54 | }, 55 | "homepage": "https://github.com/spmjs/spm-sea", 56 | "author": "chencheng ", 57 | "license": "MIT", 58 | "scripts": { 59 | "test": "make test" 60 | }, 61 | "bin": { 62 | "spm-sea": "cli.js" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var glob = require('glob'); 5 | var rimraf = require('rimraf'); 6 | var join = require('path').join; 7 | var sinon = require('sinon'); 8 | var log = require('spm-log'); 9 | var thunkify = require('thunkify'); 10 | 11 | var Build = require('../lib/build'); 12 | 13 | var build = thunkify(function(args, done) { 14 | new Build(args) 15 | .getArgs() 16 | .installDeps() 17 | .parsePkg() 18 | .addCleanTask() 19 | .run(done); 20 | }); 21 | 22 | var fixtures = join(__dirname, 'fixtures'); 23 | var dest = join(fixtures, 'tmp'); 24 | 25 | log.info = log.warn = function() {}; 26 | 27 | describe('lib/index.js', function() { 28 | 29 | afterEach(function(done) { 30 | rimraf(dest, done); 31 | }); 32 | 33 | it('normal', function* () { 34 | yield build({ 35 | cwd: join(fixtures, 'normal'), 36 | dest: dest, 37 | install: true 38 | }); 39 | assert(dest, join(fixtures, '../expected/normal')); 40 | }); 41 | 42 | it('normal with `--sea`', function* () { 43 | yield build({ 44 | cwd: join(fixtures, 'normal'), 45 | dest: dest, 46 | install: true, 47 | sea: 'relative' 48 | }); 49 | assert(dest, join(fixtures, '../expected/normal')); 50 | }); 51 | 52 | it('normal all', function* () { 53 | yield build({ 54 | cwd: join(fixtures, 'normal'), 55 | dest: dest, 56 | install: true, 57 | sea: 'all' 58 | }); 59 | assert(dest, join(fixtures, '../expected/normal-all')); 60 | }); 61 | 62 | it('normal withDeps', function* () { 63 | yield build({ 64 | cwd: join(fixtures, 'normal'), 65 | dest: dest, 66 | withDeps: true, 67 | install: false 68 | }); 69 | assert(dest, join(fixtures, '../expected/normal-withDeps')); 70 | }); 71 | 72 | it('normal ignore', function* () { 73 | yield build({ 74 | cwd: join(fixtures, 'normal'), 75 | dest: dest, 76 | ignore: 'type', 77 | install: false 78 | }); 79 | assert(dest, join(fixtures, '../expected/normal-ignore')); 80 | }); 81 | 82 | it('normal empty idleading', function* () { 83 | yield build({ 84 | cwd: join(fixtures, 'normal'), 85 | dest: dest, 86 | idleading: '', 87 | install: false 88 | }); 89 | assert(dest, join(fixtures, '../expected/normal-empty-idleading')); 90 | }); 91 | 92 | it('normal global', function* () { 93 | yield build({ 94 | cwd: join(fixtures, 'normal'), 95 | dest: dest, 96 | global: 'type: Type', 97 | install: false 98 | }); 99 | assert(dest, join(fixtures, '../expected/normal-global')); 100 | }); 101 | 102 | it('nodeps ignore', function* () { 103 | yield build({ 104 | cwd: join(fixtures, 'nodeps-ignore'), 105 | dest: dest, 106 | ignore: 'jquery', 107 | install: false 108 | }); 109 | assert(dest, join(fixtures, '../expected/nodeps-ignore')); 110 | }); 111 | 112 | it('multiple versions', function* () { 113 | var logWarn = sinon.spy(log, 'warn'); 114 | yield build({ 115 | cwd: join(fixtures, 'multiple-versions'), 116 | dest: dest, 117 | install: false 118 | }); 119 | assert(dest, join(fixtures, '../expected/multiple-versions')); 120 | logWarn.callCount.should.be.equal(1); 121 | }); 122 | 123 | it('css package', function* () { 124 | yield build({ 125 | cwd: join(fixtures, 'css-package'), 126 | dest: dest, 127 | install: false 128 | }); 129 | assert(dest, join(fixtures, '../expected/css-package')); 130 | }); 131 | 132 | it('css resources', function* () { 133 | yield build({ 134 | cwd: join(fixtures, 'css-resources'), 135 | dest: dest, 136 | install: false 137 | }); 138 | assert(dest, join(fixtures, '../expected/css-resources')); 139 | }); 140 | 141 | it('package file', function* () { 142 | yield build({ 143 | cwd: join(fixtures, 'package-file'), 144 | dest: dest, 145 | install: false 146 | }); 147 | assert(dest, join(fixtures, '../expected/package-file')); 148 | }); 149 | 150 | it('autoprefixer', function* () { 151 | yield build({ 152 | cwd: join(fixtures, 'autoprefixer'), 153 | dest: dest, 154 | install: false 155 | }); 156 | assert(dest, join(fixtures, '../expected/autoprefixer')); 157 | }); 158 | 159 | it('to5', function* () { 160 | yield build({ 161 | cwd: join(fixtures, 'to5'), 162 | dest: dest, 163 | install: false 164 | }); 165 | assert(dest, join(fixtures, '../expected/to5')); 166 | }); 167 | 168 | describe('extra deps', function() { 169 | afterEach(function() { 170 | fs.writeFileSync(join(fixtures, 'extra-deps/package.json'), 171 | '{"name":"a","version":"0.1.0","spm":{}}\n', 'utf-8'); 172 | }); 173 | 174 | it('extra deps', function* () { 175 | yield build({ 176 | cwd: join(fixtures, 'extra-deps'), 177 | dest: dest, 178 | install: false 179 | }); 180 | assert(dest, join(fixtures, '../expected/extra-deps')); 181 | }); 182 | }); 183 | 184 | it('entry', function* () { 185 | yield build({ 186 | cwd: join(fixtures, 'entry'), 187 | dest: dest, 188 | install: false, 189 | entry: ['a.js'] 190 | }); 191 | assert(dest, join(fixtures, '../expected/entry')); 192 | }); 193 | 194 | describe('entry without pkg', function() { 195 | 196 | afterEach(function() { 197 | rimraf.sync(join(fixtures, 'entry-without-pkg/package.json')); 198 | }); 199 | 200 | it('entry without pkg', function* () { 201 | yield build({ 202 | cwd: join(fixtures, 'entry-without-pkg'), 203 | dest: dest, 204 | install: false, 205 | entry: ['a.js'] 206 | }); 207 | assert(dest, join(fixtures, '../expected/entry-without-pkg')); 208 | }); 209 | 210 | it('output file', function*() { 211 | yield build({ 212 | cwd: join(fixtures, 'entry-without-pkg'), 213 | dest: dest, 214 | install: false, 215 | entry: ['a.js'], 216 | outputFile: 'build.js' 217 | }); 218 | fs.readFileSync(join(fixtures, 'entry-without-pkg/build.js'), 'utf-8').should.be.equal('define("/a",[],function(){console.log("a.js")});'); 219 | rimraf.sync(join(fixtures, 'entry-without-pkg/build.js')); 220 | }); 221 | 222 | }); 223 | 224 | it('hash', function* () { 225 | yield build({ 226 | cwd: join(fixtures, 'hash'), 227 | dest: dest, 228 | install: false 229 | }); 230 | assert(dest, join(fixtures, '../expected/hash')); 231 | }); 232 | 233 | it('copy img', function* () { 234 | yield build({ 235 | cwd: join(fixtures, 'copy-img'), 236 | dest: dest, 237 | install: false 238 | }); 239 | assert(dest, join(fixtures, '../expected/copy-img')); 240 | }); 241 | 242 | it('force', function* () { 243 | var fakeFile = join(dest, 'a.js'); 244 | fs.mkdirSync(dest); 245 | fs.writeFileSync(fakeFile); 246 | 247 | yield build({ 248 | cwd: join(fixtures, 'normal'), 249 | dest: dest, 250 | force: true, 251 | install: false 252 | }); 253 | 254 | fs.existsSync(fakeFile).should.be.false; 255 | }); 256 | 257 | describe('scripts', function() { 258 | 259 | afterEach(function() { 260 | rimraf.sync(join(fixtures, 'scripts/index.js')); 261 | }); 262 | 263 | it('with scripts', function* () { 264 | process.chdir(join(fixtures, 'scripts')); 265 | yield require('exeq')('node --harmony ' + join(__dirname, '../cli.js')); 266 | fs.readFileSync(join(fixtures, 'scripts', 'index.js'), 'utf-8').should.be.equal('1\n2\n3\n'); 267 | }); 268 | 269 | }); 270 | 271 | }); 272 | 273 | function assert(actual, expect) { 274 | glob.sync('**/*', {cwd: actual}) 275 | .forEach(function(file) { 276 | var filepath = join(actual, file); 277 | if (fs.statSync(filepath).isFile()) { 278 | fs.readFileSync(filepath).toString() 279 | .should.eql(fs.readFileSync(join(expect, file)).toString()); 280 | } 281 | }); 282 | } 283 | -------------------------------------------------------------------------------- /test/expected/autoprefixer/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | a { 2 | -webkit-transition: -webkit-transform 1s; 3 | transition: transform 1s; 4 | } 5 | -------------------------------------------------------------------------------- /test/expected/autoprefixer/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | a{-webkit-transition:-webkit-transform 1s;transition:transform 1s} -------------------------------------------------------------------------------- /test/expected/copy-img/a/0.1.0/a.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/expected/copy-img/a/0.1.0/a.gif -------------------------------------------------------------------------------- /test/expected/css-package/a/1.0.0/src/a-debug.css: -------------------------------------------------------------------------------- 1 | ul { 2 | margin: 0; 3 | } 4 | 5 | body { 6 | background: none; 7 | } 8 | -------------------------------------------------------------------------------- /test/expected/css-package/a/1.0.0/src/a.css: -------------------------------------------------------------------------------- 1 | ul{margin:0}body{background:0 0} -------------------------------------------------------------------------------- /test/expected/css-resources/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/expected/css-resources/a.png -------------------------------------------------------------------------------- /test/expected/css-resources/b-debug.css: -------------------------------------------------------------------------------- 1 | 2 | div { 3 | background: url(b_0_2_0_a.jpg); 4 | } 5 | 6 | a { 7 | background: url(a.png); 8 | } 9 | -------------------------------------------------------------------------------- /test/expected/css-resources/b.css: -------------------------------------------------------------------------------- 1 | div{background:url(b_0_2_0_a.jpg)}a{background:url(a.png)} -------------------------------------------------------------------------------- /test/expected/css-resources/b_0_2_0_a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/expected/css-resources/b_0_2_0_a.jpg -------------------------------------------------------------------------------- /test/expected/css-resources/css/a-debug.css: -------------------------------------------------------------------------------- 1 | div { 2 | background: url(../b_0_2_0_a.jpg); 3 | } 4 | 5 | a { 6 | background: url(../a.png); 7 | } -------------------------------------------------------------------------------- /test/expected/css-resources/css/a.css: -------------------------------------------------------------------------------- 1 | div{background:url(../b_0_2_0_a.jpg)}a{background:url(../a.png)} -------------------------------------------------------------------------------- /test/expected/entry-without-pkg/a-debug.js: -------------------------------------------------------------------------------- 1 | define("/a-debug", [], function(require, exports, module){ 2 | console.log('a.js'); 3 | }); 4 | -------------------------------------------------------------------------------- /test/expected/entry-without-pkg/a.js: -------------------------------------------------------------------------------- 1 | define("/a",[],function(){console.log("a.js")}); -------------------------------------------------------------------------------- /test/expected/entry/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", [], function(require, exports, module){ 2 | console.log('a.js'); 3 | }); 4 | -------------------------------------------------------------------------------- /test/expected/entry/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",[],function(){console.log("a.js")}); -------------------------------------------------------------------------------- /test/expected/extra-deps/a/0.1.0/index-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index-debug", ["handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime-debug","import-style/1.0.0/index-debug"], function(require, exports, module){ 2 | require("a/0.1.0/a-debug.css.js"); 3 | require("a/0.1.0/a-debug.handlebars"); 4 | alert(1); 5 | 6 | }); 7 | define("a/0.1.0/a-debug.css.js", ["import-style/1.0.0/index-debug"], function(require, exports, module){ 8 | require("import-style/1.0.0/index-debug")('a{color:red;}'); 9 | 10 | }); 11 | define("a/0.1.0/a-debug.handlebars", ["handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime-debug"], function(require, exports, module){ 12 | var Handlebars = require("handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime-debug")["default"]; 13 | module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { 14 | this.compilerInfo = [4,'>= 1.0.0']; 15 | helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; 16 | var buffer = ""; 17 | 18 | 19 | return buffer; 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /test/expected/extra-deps/a/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index",["handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime","import-style/1.0.0/index"],function(e){e("a/0.1.0/a.css.js"),e("a/0.1.0/a.handlebars"),alert(1)}),define("a/0.1.0/a.css.js",["import-style/1.0.0/index"],function(e){e("import-style/1.0.0/index")("a{color:red;}")}),define("a/0.1.0/a.handlebars",["handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime"],function(e,a,n){var r=e("handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime")["default"];n.exports=r.template(function(e,a,n,r,s){this.compilerInfo=[4,">= 1.0.0"],n=this.merge(n,e.helpers),s=s||{};var t="";return t})}); -------------------------------------------------------------------------------- /test/expected/hash/a/a-626a1277-debug.js: -------------------------------------------------------------------------------- 1 | define("a/a-626a1277-debug", [], function(require, exports, module){ 2 | console.log(1); 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /test/expected/hash/a/a-626a1277.js: -------------------------------------------------------------------------------- 1 | define("a/a-626a1277",[],function(){console.log(1)}); -------------------------------------------------------------------------------- /test/expected/multiple-versions/a/0.1.0/index-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index-debug", ["b/0.1.0/index-debug","c/0.1.1/index-debug","c/0.1.0/index-debug"], function(require, exports, module){ 2 | require("b/0.1.0/index-debug"); 3 | require("c/0.1.0/index-debug"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/multiple-versions/a/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index",["b/0.1.0/index","c/0.1.1/index","c/0.1.0/index"],function(n){n("b/0.1.0/index"),n("c/0.1.0/index")}); -------------------------------------------------------------------------------- /test/expected/multiple-versions/a/0.1.0/output-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/output-debug", ["b/0.1.0/index-debug","c/0.1.1/index-debug","c/0.1.0/index-debug"], function(require, exports, module){ 2 | require("b/0.1.0/index-debug"); 3 | require("c/0.1.0/index-debug"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/multiple-versions/a/0.1.0/output.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/output",["b/0.1.0/index","c/0.1.1/index","c/0.1.0/index"],function(n){n("b/0.1.0/index"),n("c/0.1.0/index")}); -------------------------------------------------------------------------------- /test/expected/nodeps-ignore/a/0.1.0/index-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index-debug", ["jquery"], function(require, exports, module){ 2 | require("jquery"); 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /test/expected/nodeps-ignore/a/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/index",["jquery"],function(e){e("jquery")}); -------------------------------------------------------------------------------- /test/expected/normal-all/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-all/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", [], function(require, exports, module){ 2 | require("type/0.1.0/index-debug"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | define("type/0.1.0/index-debug", [], function(require, exports, module){ 7 | console.log("type"); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /test/expected/normal-all/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-all/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",[],function(e){e("type/0.1.0/index"),console.log("a@0.1.0")}),define("type/0.1.0/index",[],function(){console.log("type")}); -------------------------------------------------------------------------------- /test/expected/normal-empty-idleading/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-empty-idleading/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a-debug", ["index-debug"], function(require, exports, module){ 2 | require("index-debug"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/normal-empty-idleading/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-empty-idleading/a.js: -------------------------------------------------------------------------------- 1 | define("a",["index"],function(n){n("index"),console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/normal-global/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-global/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", [], function(require, exports, module){ 2 | window.Type; 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/normal-global/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-global/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",[],function(){window.Type,console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/normal-ignore/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-ignore/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", ["type"], function(require, exports, module){ 2 | require("type"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/normal-ignore/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-ignore/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",["type"],function(e){e("type"),console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/normal-standalone-ignore/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-standalone-ignore/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | var a_010_a_debug; 3 | a_010_a_debug = function () { 4 | type; 5 | console.log('a@0.1.0'); 6 | }(); 7 | }()); -------------------------------------------------------------------------------- /test/expected/normal-standalone-ignore/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-standalone-ignore/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | !function(){var n;n=function(){console.log("a@0.1.0")}()}(); -------------------------------------------------------------------------------- /test/expected/normal-standalone/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-standalone/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | var type_010_index_debug, a_010_a_debug; 3 | type_010_index_debug = function () { 4 | console.log('type'); 5 | }(); 6 | a_010_a_debug = function () { 7 | type_010_index_debug; 8 | console.log('a@0.1.0'); 9 | }(); 10 | }()); -------------------------------------------------------------------------------- /test/expected/normal-standalone/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-standalone/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | !function(){var o,n;o=function(){console.log("type")}(),n=function(){console.log("a@0.1.0")}()}(); -------------------------------------------------------------------------------- /test/expected/normal-umd/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-umd/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | ;(function() { 2 | var type_010_index_debug, a_010_a_debug; 3 | type_010_index_debug = function () { 4 | console.log('type'); 5 | }(); 6 | a_010_a_debug = function () { 7 | type_010_index_debug; 8 | console.log('a@0.1.0'); 9 | }(); 10 | 11 | if (typeof exports == "object") { 12 | module.exports = a_010_a_debug; 13 | } else if (typeof define == "function" && (define.cmd || define.amd)) { 14 | define(function(){ return a_010_a_debug }); 15 | } else { 16 | this["a"] = a_010_a_debug; 17 | } 18 | }()); -------------------------------------------------------------------------------- /test/expected/normal-umd/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-umd/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | !function(){var e,n;e=function(){console.log("type")}(),n=function(){console.log("a@0.1.0")}(),"object"==typeof exports?module.exports=n:"function"==typeof define&&(define.cmd||define.amd)?define(function(){return n}):this.a=n}(); -------------------------------------------------------------------------------- /test/expected/normal-withDeps/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal-withDeps/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", ["type/0.1.0/index-debug"], function(require, exports, module){ 2 | require("type/0.1.0/index-debug"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/normal-withDeps/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal-withDeps/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",["type/0.1.0/index"],function(e){e("type/0.1.0/index"),console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/normal-withDeps/type/0.1.0/index-debug.js: -------------------------------------------------------------------------------- 1 | define("type/0.1.0/index-debug", [], function(require, exports, module){ 2 | console.log("type"); 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /test/expected/normal-withDeps/type/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | define("type/0.1.0/index",[],function(){console.log("type")}); -------------------------------------------------------------------------------- /test/expected/normal/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/normal/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", ["type/0.1.0/index-debug"], function(require, exports, module){ 2 | require("type/0.1.0/index-debug"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/normal/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/normal/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",["type/0.1.0/index"],function(e){e("type/0.1.0/index"),console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/package-file/a/0.1.0/a-debug.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/expected/package-file/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", ["type/0.1.0/b-debug"], function(require, exports, module){ 2 | require("type/0.1.0/b-debug"); 3 | console.log("a@0.1.0"); 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /test/expected/package-file/a/0.1.0/a.css: -------------------------------------------------------------------------------- 1 | .type,a{color:red} -------------------------------------------------------------------------------- /test/expected/package-file/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",["type/0.1.0/b"],function(e){e("type/0.1.0/b"),console.log("a@0.1.0")}); -------------------------------------------------------------------------------- /test/expected/to5/a/0.1.0/a-debug.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a-debug", [], function(require, exports, module){ 2 | "use strict"; 3 | 4 | var _ref = [1, 2, 3]; 5 | 6 | var a = _ref[0]; 7 | var b = _ref[2]; 8 | }); 9 | -------------------------------------------------------------------------------- /test/expected/to5/a/0.1.0/a.js: -------------------------------------------------------------------------------- 1 | define("a/0.1.0/a",[],function(){"use strict";{var a=[1,2,3];a[0],a[2]}}); -------------------------------------------------------------------------------- /test/fixtures/autoprefixer/a.css: -------------------------------------------------------------------------------- 1 | a { 2 | transition: transform 1s; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/autoprefixer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "a.css" 7 | ], 8 | "autoprefixer": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/copy-img/a.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/copy-img/a.gif -------------------------------------------------------------------------------- /test/fixtures/copy-img/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "a.gif" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /test/fixtures/css-package/b.css: -------------------------------------------------------------------------------- 1 | ul { 2 | margin: 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/css-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "1.0.0", 4 | "spm": { 5 | "main": "src/a.css" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/css-package/src/a.css: -------------------------------------------------------------------------------- 1 | @import "../b.css"; 2 | 3 | body { 4 | background: none; 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/css-resources/b.css: -------------------------------------------------------------------------------- 1 | 2 | @import './css/a.css'; 3 | -------------------------------------------------------------------------------- /test/fixtures/css-resources/css/a.css: -------------------------------------------------------------------------------- 1 | 2 | @import '~b'; 3 | 4 | a { 5 | background: url(../img/a.png); 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/css-resources/img/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/css-resources/img/a.png -------------------------------------------------------------------------------- /test/fixtures/css-resources/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "spm": { 3 | "output": [ 4 | "b.css", 5 | "css/a.css" 6 | ], 7 | "dependencies": { 8 | "b": "0.2.0" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/css-resources/spm_modules/b/0.2.0/a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/css-resources/spm_modules/b/0.2.0/a.jpg -------------------------------------------------------------------------------- /test/fixtures/css-resources/spm_modules/b/0.2.0/b.css: -------------------------------------------------------------------------------- 1 | 2 | div { 3 | background: url(a.jpg); 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/css-resources/spm_modules/b/0.2.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "b", 3 | "version": "0.2.0", 4 | "spm": { 5 | "main": "b.css" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/entry-without-pkg/a.js: -------------------------------------------------------------------------------- 1 | console.log('a.js'); -------------------------------------------------------------------------------- /test/fixtures/entry/a.js: -------------------------------------------------------------------------------- 1 | console.log('a.js'); -------------------------------------------------------------------------------- /test/fixtures/entry/index.js: -------------------------------------------------------------------------------- 1 | console.log('index.js'); 2 | -------------------------------------------------------------------------------- /test/fixtures/entry/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": {} 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/a.css: -------------------------------------------------------------------------------- 1 | a{color: red} 2 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/a.handlebars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/extra-deps/a.handlebars -------------------------------------------------------------------------------- /test/fixtures/extra-deps/index.js: -------------------------------------------------------------------------------- 1 | require('./a.css'); 2 | require('./a.handlebars'); 3 | alert(1); 4 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/package.json: -------------------------------------------------------------------------------- 1 | {"name":"a","version":"0.1.0","spm":{}} 2 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/spm_modules/handlebars-runtime/1.3.0/dist/cjs/handlebars.runtime.js: -------------------------------------------------------------------------------- 1 | module.exports = function() {}; 2 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/spm_modules/handlebars-runtime/1.3.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "handlebars-runtime", 3 | "barename": "handlebars", 4 | "version": "1.3.0", 5 | "description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration", 6 | "homepage": "http://www.handlebarsjs.com/", 7 | "keywords": [ 8 | "handlebars", 9 | "mustache", 10 | "template", 11 | "html" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/wycats/handlebars.js.git" 16 | }, 17 | "author": "Yehuda Katz", 18 | "license": "MIT", 19 | "readmeFilename": "README.md", 20 | "engines": { 21 | "node": ">=0.4.7" 22 | }, 23 | "dependencies": { 24 | "optimist": "~0.3" 25 | }, 26 | "optionalDependencies": { 27 | "uglify-js": "~2.3" 28 | }, 29 | "devDependencies": { 30 | "async": "~0.2.9", 31 | "aws-sdk": "~1.5.0", 32 | "benchmark": "~1.0", 33 | "dustjs-linkedin": "~2.0.2", 34 | "eco": "~1.1.0-rc-3", 35 | "grunt": "~0.4.1", 36 | "grunt-cli": "~0.1.10", 37 | "grunt-contrib-clean": "~0.4.1", 38 | "grunt-contrib-concat": "~0.3.0", 39 | "grunt-contrib-connect": "~0.5.0", 40 | "grunt-contrib-copy": "~0.4.1", 41 | "grunt-contrib-jshint": "0.x", 42 | "grunt-contrib-requirejs": "~0.4.1", 43 | "grunt-contrib-uglify": "~0.2.2", 44 | "grunt-contrib-watch": "~0.5.3", 45 | "grunt-saucelabs": "~4.1.2", 46 | "es6-module-packager": "0.x", 47 | "jison": "~0.3.0", 48 | "keen.io": "0.0.3", 49 | "mocha": "*", 50 | "mustache": "~0.7.2", 51 | "semver": "~2.1.0", 52 | "underscore": "~1.5.1" 53 | }, 54 | "main": "lib/index.js", 55 | "bin": { 56 | "handlebars": "bin/handlebars" 57 | }, 58 | "scripts": { 59 | "test": "grunt" 60 | }, 61 | "spm": { 62 | "main": "dist/cjs/handlebars.runtime.js" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/spm_modules/import-style/1.0.0/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The Sea.js plugin for embedding style text in JavaScript code 3 | */ 4 | 5 | 6 | var RE_NON_WORD = /\W/g; 7 | var doc = document; 8 | var head = document.getElementsByTagName('head')[0] || 9 | document.documentElement; 10 | var styleNode; 11 | 12 | module.exports = importStyle; 13 | 14 | function importStyle(cssText, id) { 15 | if (id) { 16 | // Convert id to valid string 17 | id = id.replace(RE_NON_WORD, '-'); 18 | 19 | // Don't add multiple times 20 | if (doc.getElementById(id)) return; 21 | } 22 | 23 | var element; 24 | 25 | // Don't share styleNode when id is spectied 26 | if (!styleNode || id) { 27 | element = doc.createElement('style'); 28 | id && (element.id = id); 29 | 30 | // Adds to DOM first to avoid the css hack invalid 31 | head.appendChild(element); 32 | } else { 33 | element = styleNode; 34 | } 35 | 36 | // IE 37 | if (element.styleSheet) { 38 | 39 | // http://support.microsoft.com/kb/262161 40 | if (doc.getElementsByTagName('style').length > 31) { 41 | throw new Error('Exceed the maximal count of style tags in IE'); 42 | } 43 | 44 | element.styleSheet.cssText += cssText; 45 | } 46 | // W3C 47 | else { 48 | element.appendChild(doc.createTextNode(cssText)); 49 | } 50 | 51 | if (!id) { 52 | styleNode = element; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/fixtures/extra-deps/spm_modules/import-style/1.0.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "import-style", 3 | "version": "1.0.0", 4 | "description": "embedding style text in JavaScript code", 5 | "keywords": ["import","style"], 6 | "author": "Frank Wang ", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/popomore/import-style.git" 10 | }, 11 | "spm": { 12 | "main": "index.js", 13 | "devDependencies": { 14 | "expect.js": "0.3.1" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/get-args/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "uglify": 1, 6 | "cssmin": 2 7 | } 8 | } -------------------------------------------------------------------------------- /test/fixtures/get-files/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "./src/**/*" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /test/fixtures/get-files/src/index/index.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/get-files/src/index/index.css -------------------------------------------------------------------------------- /test/fixtures/get-files/src/index/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/get-files/src/index/index.html -------------------------------------------------------------------------------- /test/fixtures/get-files/src/index/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/get-files/src/index/index.js -------------------------------------------------------------------------------- /test/fixtures/hash/a.js: -------------------------------------------------------------------------------- 1 | console.log(1); 2 | -------------------------------------------------------------------------------- /test/fixtures/hash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "spm": { 4 | "output": ["a.js"], 5 | "hash": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/index.js: -------------------------------------------------------------------------------- 1 | require('b'); 2 | require('c'); 3 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/output.js: -------------------------------------------------------------------------------- 1 | require('b'); 2 | require('c'); 3 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "./output.js" 7 | ], 8 | "dependencies": { 9 | "b": "0.1.0", 10 | "c": "0.1.0" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/relative.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('relative'); 3 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/b/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | require('c'); 2 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/b/0.1.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "b", 3 | "version": "0.1.0", 4 | "spm": { 5 | "dependencies": { 6 | "c": "0.1.1" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/c/0.1.0/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/multiple-versions/spm_modules/c/0.1.0/index.js -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/c/0.1.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c", 3 | "version": "0.1.0", 4 | "spm": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/c/0.1.1/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spmjs/spm-sea/43056fab20e1d1bc4a2811bb3750e3429c859079/test/fixtures/multiple-versions/spm_modules/c/0.1.1/index.js -------------------------------------------------------------------------------- /test/fixtures/multiple-versions/spm_modules/c/0.1.1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c", 3 | "version": "0.1.1", 4 | "spm": { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/nodeps-ignore/index.js: -------------------------------------------------------------------------------- 1 | require('jquery'); 2 | -------------------------------------------------------------------------------- /test/fixtures/nodeps-ignore/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": {} 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/normal/a.css: -------------------------------------------------------------------------------- 1 | @import '~type/type.css'; 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/fixtures/normal/a.js: -------------------------------------------------------------------------------- 1 | require('type'); 2 | console.log("a@0.1.0"); 3 | -------------------------------------------------------------------------------- /test/fixtures/normal/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "a.js", 7 | "a.css", 8 | "a.html" 9 | ], 10 | "dependencies": { 11 | "type": "0.1.0" 12 | }, 13 | "cssminOpts": { 14 | "noAdvanced": false 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/normal/spm_modules/type/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | console.log("type"); 2 | -------------------------------------------------------------------------------- /test/fixtures/normal/spm_modules/type/0.1.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "type", 3 | "version": "0.1.0", 4 | "spm": { 5 | } 6 | } -------------------------------------------------------------------------------- /test/fixtures/normal/spm_modules/type/0.1.0/type.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} -------------------------------------------------------------------------------- /test/fixtures/package-file/a.css: -------------------------------------------------------------------------------- 1 | @import '~type/type.css'; 2 | 3 | a {color:red} 4 | -------------------------------------------------------------------------------- /test/fixtures/package-file/a.js: -------------------------------------------------------------------------------- 1 | require('type/b'); 2 | console.log("a@0.1.0"); 3 | -------------------------------------------------------------------------------- /test/fixtures/package-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "a.js", 7 | "a.css", 8 | "a.html" 9 | ], 10 | "dependencies": { 11 | "type": "0.1.0" 12 | }, 13 | "cssminOpts": { 14 | "noAdvanced": false 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/package-file/spm_modules/type/0.1.0/b.js: -------------------------------------------------------------------------------- 1 | alert('b'); -------------------------------------------------------------------------------- /test/fixtures/package-file/spm_modules/type/0.1.0/index.js: -------------------------------------------------------------------------------- 1 | console.log("type"); 2 | -------------------------------------------------------------------------------- /test/fixtures/package-file/spm_modules/type/0.1.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "type", 3 | "version": "0.1.0", 4 | "spm": { 5 | } 6 | } -------------------------------------------------------------------------------- /test/fixtures/package-file/spm_modules/type/0.1.0/type.css: -------------------------------------------------------------------------------- 1 | .type{color:red;} -------------------------------------------------------------------------------- /test/fixtures/scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "spm": { 3 | "scripts": { 4 | "prebuild": "echo 1 >> index.js", 5 | "build": "echo 2 >> index.js", 6 | "postbuild": "echo 3 >> index.js" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/to5/a.js: -------------------------------------------------------------------------------- 1 | var [a, , b] = [1,2,3]; 2 | -------------------------------------------------------------------------------- /test/fixtures/to5/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "0.1.0", 4 | "spm": { 5 | "output": [ 6 | "a.js" 7 | ], 8 | "6to5": {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/getArgs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var join = require('path').join; 4 | var getArgs = require('../lib/getArgs'); 5 | 6 | var fixtures = join(__dirname, 'fixtures'); 7 | 8 | describe('lib/getArgs.js', function() { 9 | 10 | it('normal', function() { 11 | var args = getArgs({cwd:join(fixtures, 'get-args')}); 12 | args.uglify.should.be.equal(1); 13 | args.cssmin.should.be.equal(2); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/getFiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var join = require('path').join; 4 | var getFiles = require('../lib/getFiles'); 5 | var Package = require('father').SpmPackage; 6 | 7 | var fixtures = join(__dirname, 'fixtures'); 8 | 9 | describe('lib/getFiles.js', function() { 10 | 11 | it('normal', function() { 12 | var pkg = new Package(join(fixtures, 'get-files')); 13 | var files = getFiles(pkg); 14 | files.should.be.eql([ 15 | 'src/index/index.css', 16 | 'src/index/index.html', 17 | 'src/index/index.js' 18 | ]); 19 | }); 20 | 21 | }); 22 | --------------------------------------------------------------------------------