Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

plain layout

  • Loading branch information...
commit d21b80323c1dbb46c5254a403aa2e9b227b431bc 1 parent b48db3f
@azer authored
View
14 bin/onejs
@@ -15,17 +15,18 @@ var opt = require('optimist'),
.options('quiet', {})
.options('verbose', {})
.options('version', {})
+ .options('plain', {})
.options('help', {})
.argv;
var HELP = ['usage: onejs [action] [manifest] [options]'
, ''
- , 'Transforms NodeJS packages into single, stand-alone JavaScript files that can be run at other platforms.'
+ , 'Transforms NodeJS packages into single, stand-alone JavaScript files that can be run at other platforms. See the documentation at http://github.com/azer/onejs for more information.'
, ''
, 'actions:'
- , ' build <manifest> <target> Generate a stand-alone JavaScript file from specified package. Write output to <target> if given any.'
- , ' install [modules] Package specified NodeJS core modules and locate them in node_modules/ directory. Example Usage: onejs install assert util.'
- , ' server <manifest> <port> <host> Publish generated JavaScript file on web. Uses 127.0.0.1:1338 by default.'
+ , ' build <manifest> <target> Generate a stand-alone JavaScript file from specified package. Write output to <target> if given any.'
+ , ' install [modules] Package specified NodeJS core modules and locate them in node_modules/ directory.'
+ , ' server <manifest> <port> <host> Publish generated JavaScript file on web. Uses 127.0.0.1:1338 by default.'
, ''
, 'options:'
, ' --debug Disable module caching. Pass ENV variables to the build.'
@@ -34,6 +35,7 @@ var HELP = ['usage: onejs [action] [manifest] [options]'
, ' --exclude <package name> Do not contain specified dependencies. e.g: --exclude underscore,request '
, ' --noprocess Do not include process implementation.'
, ' --sandbox-console Provide the build an encapsulated, embed console implementation.'
+ , ' --plain Builds the package within a minimalistic template for the packages with single module and no dependencies.'
, ''
, ' --quiet Make console output less verbose.'
, ' --verbose Tell what\'s going on by being verbose.'
@@ -46,6 +48,7 @@ function build(){
target = argv._[2],
tie = argv.tie,
exclude = argv.exclude,
+ plain = argv.plain,
sandboxConsole = argv['sandbox-console'];
if(tie){
@@ -66,7 +69,8 @@ function build(){
'tie': tie,
'debug': argv.debug,
'exclude': exclude,
- 'sandboxConsole': sandboxConsole
+ 'sandboxConsole': sandboxConsole,
+ 'plain': plain
};
one.build(manifest, options, function(error, pkg){
View
17 lib/index.js
@@ -28,7 +28,7 @@ function build(manifestPath, buildOptions, callback){
toIgnore && ( pkgOptions.ignore = toIgnore );
- renderPkg(pkgOptions, buildOptions, callback);
+ templating(pkgOptions, buildOptions, callback);
});
@@ -55,21 +55,6 @@ function readNPMIgnore(pkgOptions, buildOptions, callback){
}
-function renderPkg(pkgOptions, buildOptions, callback){
- pkg(pkgOptions, buildOptions, function(error, loadedPkg){
-
- if(error){
- callback(error);
- return;
- }
-
- templating.dynamic(loadedPkg, buildOptions, function(error, sourceCode){
- callback(error, sourceCode, pkg);
- });
-
- });
-}
-
function quiet(y){
logging.setLevel('ERROR');
}
View
5 lib/templating/coll.js
@@ -4,7 +4,7 @@ var boxcars = require("boxcars"),
render = require('./render');
-function key(filename){
+function templateName(filename){
return filename
.replace(/\.js$/, '')
.replace(/^\w+\//, '');
@@ -47,7 +47,8 @@ function coll(){
while( i --> 0 ){
filename = arguments[i];
- name = key(filename);
+
+ name = templateName(filename);
param[ name ] = config.TEMPLATES_DIR + '/' + filename;
View
4 lib/templating/dynamic/index.js
@@ -10,7 +10,7 @@ var readFile = require('fs').readFile,
templates = require('./templates');
-function index(pkg, options, callback){
+function dynamic(pkg, options, callback){
logging.info('Rendering %s', pkg.name);
@@ -38,5 +38,5 @@ function sort(a, b){
return a.name.localeCompare(b.name);
}
-module.exports = index;
+module.exports = dynamic;
module.exports.flattenPkgTree = flattenPkgTree;
View
39 lib/templating/index.js
@@ -1,6 +1,33 @@
-module.exports = {
- 'dynamic': require('./dynamic'),
- 'static': require('./static'),
- 'flattenPkgTree': require('./flatten'),
- 'objectName': require('./object_name')
-};
+var pkg = require('../package'),
+
+ dynamic = require("./dynamic"),
+ statik = require("./static"),
+ plain = require('./plain'),
+ flatten = require('./flatten'),
+ objectName = require('./object_name');
+
+function main(pkgOptions, buildOptions, callback){
+
+ var layout = buildOptions.plain ? plain : dynamic;
+
+ pkg(pkgOptions, buildOptions, function(error, loadedPkg){
+
+ if(error){
+ callback(error);
+ return;
+ }
+
+ layout(loadedPkg, buildOptions, function(error, sourceCode){
+ callback(error, sourceCode, pkg);
+ });
+
+ });
+
+}
+
+module.exports = main;
+module.exports.dynamic = dynamic;
+module.exports.statik = statik;
+module.exports.plain = plain;
+module.exports.flattenPkgTree = flatten;
+module.exports.objectName = objectName;
View
11 lib/templating/plain/index.js
@@ -0,0 +1,11 @@
+var logging = require('../../logging'),
+ objectName = require('../object_name'),
+ templates = require('./templates');
+
+function plain(pkg, options, callback){
+ logging.info('Rendering %s', pkg.name);
+
+ templates.wrapper({ 'name': objectName(pkg.name), 'content': pkg.modules[0].content }, callback);
+}
+
+module.exports = plain;
View
3  lib/templating/plain/templates.js
@@ -0,0 +1,3 @@
+var coll = require('../coll');
+
+module.exports = coll('plain/wrapper.js');
View
13 templates/plain/wrapper.js
@@ -0,0 +1,13 @@
+var {{ name }} = (function(undefined){
+
+ var exports = {}, module = { 'exports': exports };
+
+ {{{ content }}}
+
+ return module.exports;
+
+})();
+
+if(typeof module != 'undefined' && module.exports){
+ module.exports = {{ name }};
+};
View
2  test/build.js
@@ -1,4 +1,4 @@
-var assert = require('assert'),
+ var assert = require('assert'),
one = require('../lib'),
common = require('./common'),
View
20 test/common.js
@@ -1,4 +1,5 @@
-var child_process = require('child_process');
+var child_process = require('child_process'),
+ joinPath = require('path').join;
function assertListContent(a,b){
return a.length == b.length && a.every(function(el){
@@ -6,8 +7,21 @@ function assertListContent(a,b){
});
}
-function build(target, params, callback){
- var proc = child_process.exec('./bin/onejs build example-project/package.json ' + target + ' ' + params.join(' '));
+function build(/* [pkg], target, params, callback */){
+
+ var args = Array.prototype.slice.call(arguments),
+ pkg = args.length == 4 ? args[0] : 'example-project',
+ target = args[ args.length == 4 ? 1 : 0 ],
+ params = args[ args.length == 4 ? 2 : 1 ],
+ callback = args[ args.length -1 ],
+
+ cmd = [
+ './bin/onejs build',
+ joinPath( pkg, 'package.json' ),
+ target
+ ].concat(params).join(' ');
+
+ var proc = child_process.exec(cmd);
proc.on('exit', function(code){
callback();
View
27 test/main.js
@@ -109,6 +109,31 @@ function test_build_console(callback){
});
}
+function test_build_plain(callback){
+
+ common.build('example-project/node_modules/dependency/node_modules/vegetables', 'tmp/built_plain.js', ['--plain'], function(exitCode){
+
+ fs.readFile('tmp/built_plain.js', function(error, bf){
+
+ if(error){
+ callback(error);
+ return;
+ }
+
+ assert.ok( ! bf.toString().match(/pkgdefs/) );
+
+ var vegetables = require('../tmp/built_plain');
+
+ assertListContent(vegetables, ['tomato', 'potato']);
+
+ callback();
+
+ });
+
+ });
+
+}
+
function test_dependencies(callback){
one.manifest('example-project/package.json', function(error, manifest){
@@ -348,6 +373,8 @@ module.exports = {
'test_build_debug':test_build_debug,
'test_build_debug_noprocess':test_build_debug_noprocess,
'test_build_console':test_build_console,
+ 'test_build_plain': test_build_plain,
+
'test_npmignore': test_npmignore,
'test_programmatic_api': test_programmatic_api
};
Please sign in to comment.
Something went wrong with that request. Please try again.