Skip to content

Commit

Permalink
Upgrade seed to use tiki. Drop dependency on node.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jolley authored and Charles Jolley committed Apr 6, 2010
1 parent fe0c0ab commit 0bb77be
Show file tree
Hide file tree
Showing 87 changed files with 4,557 additions and 6,330 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
tmp
build
.lock-wscript
old
2 changes: 1 addition & 1 deletion bin/seed
Expand Up @@ -5,4 +5,4 @@ var commands = seed.require('seed:commands');

// first two args are 'node' and path to this binary
var args = Array.prototype.slice.call(process.argv, 2);
commands.invokeSync(args.shift(), args);
commands.invokeSync(args.shift(), args);
3 changes: 2 additions & 1 deletion bin/seed-repl
Expand Up @@ -5,4 +5,5 @@

var repl = require('default:repl');
repl.start('seed> ');
repl.scope.seed = require.seed;
repl.scope.require = require;
repl.scope.module = module;
7 changes: 7 additions & 0 deletions docs/PLATFORMS.rd
@@ -0,0 +1,7 @@
# Porting Seed to New JS Platforms

Seed is intended to run on many different JavaScript platforms. To add
support for your specific JavaScript platform, you just need to make sure the
methods in the lib/platform.js file works as expected. See that files for
more information.

1 change: 1 addition & 0 deletions fixtures/basic/lib/doubles/fig.coffee
@@ -0,0 +1 @@
// ANOTHER FIG!
1 change: 1 addition & 0 deletions fixtures/basic/lib/doubles/fig.js
@@ -0,0 +1 @@
// JS Fig
1 change: 1 addition & 0 deletions fixtures/basic/lib/fig.coffee
@@ -0,0 +1 @@
// ARG! CoffeeScript ahoy
4 changes: 3 additions & 1 deletion fixtures/basic/package.json
@@ -1,5 +1,7 @@
{
"name": "basic",
"version": "0.1.0",
"description": "basic example project"
"description": "basic example project",

"seed:pass-through": "not modified"
}
1 change: 1 addition & 0 deletions fixtures/basic/tests/a_test.js
@@ -0,0 +1 @@
// used to lookup modules
8 changes: 0 additions & 8 deletions fixtures/loaders/package.json

This file was deleted.

File renamed without changes.
@@ -1,5 +1,6 @@
{
"name": "bar",
"version": "3.2.1",
"dependencies": {
"foo": "1.1"
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/with_local/local.json
@@ -0,0 +1,3 @@
{
"testProperty": "local"
}
4 changes: 4 additions & 0 deletions fixtures/with_local/package.json
@@ -0,0 +1,4 @@
{
"name": "with_local",
"testProperty": "package"
}
27 changes: 22 additions & 5 deletions index.js
Expand Up @@ -7,10 +7,27 @@
/**
@file
Bootstraps the seed package manager for node. Place the seed directory
into your .node_libraries folder. When you require('seed') you will get
this file back [which really just forwards to the package index].
Bootstraps the seed package manager. This should be the first module you
actually load directly from the engine to get a seed environment going.
This assume you have a very primitive require() method that can at least
load modules relatives to this one.
*/

exports = module.exports = require('./lib/index');
var Seed = require('./lib/seed').Seed,
core = require('./lib/private/core'),
seed, configPath, SEED_ENV;


// find the seed config file. It's at ~/.seeds/config.json
configPath = core.env.SEED_CONFIG || '~/.seeds/config.json';
configPath = core.path.normalize(configPath);

// create a default seed instance. This is usually what people will work
// with.
seed = module.exports = new Seed(configPath, core.env, core.args);
seed.addDefaultSources();

// if SEED_ENV is defined shift that in as well
SEED_ENV = core.env.SEED_ENV;
if (SEED_ENV) seed.register(core.path.normalize(SEED_ENV));
72 changes: 36 additions & 36 deletions lib/commands.js
Expand Up @@ -3,14 +3,12 @@
// Copyright: ©2009-2010 Apple Inc. All rights reserved.
// License: Licened under MIT license (see __preamble__.js)
// ==========================================================================
/*globals process */

if (!require.seed) throw "Can only load from within seed";
if (!require.sandbox) throw new Error("Can only load from within seed");

var Co = require('private/co');
var core = require('private/core');
var optparse = require('private/optparse');
var Cmds = exports;
var seed = require.seed;
var help = require('commands/help');

var STD_SWITCHES = [
Expand All @@ -27,7 +25,7 @@ exports.STD_SWITCHES = STD_SWITCHES;
function preferredSource() {
// choose a repository to go to. last source not a package.
var repo,
sources = seed.sources;
sources = require.sandbox.loader.sources;
for(var loc=0;(loc<sources.length) && !repo; loc++) {
if (sources[loc].acceptsInstalls) repo = sources[loc];
}
Expand All @@ -40,46 +38,47 @@ exports.preferredSource = preferredSource;
//

// log some output but only if we are in verbose mode
Cmds.verbose = Co.verbose;
Cmds.verbose = core.verbose;

// logs strings as a failed command and then exits done
Cmds.fail = Co.fail;
Cmds.fail = core.fail;

/**
Invokes callback with hash of plugin information
*/
Cmds.collectPluginInfo = function(done) {
var pkg = module.pkg || seed.seedPackage;
require.seed.collectPluginInfo(pkg, 'seed:commands', done);
Cmds.collectPluginInfo = function(key, packages) {
var ret = {};
if (!packages) packages = require.catalogPackages();
packages.forEach(function(pkg) {
var info = pkg.get(key);
if (info) ret[pkg.id] = info;
});

return ret ;
};

/**
Invokes callback with hash of commands mapped to property paths
*/
Cmds.commands = Co.once(function(done) {
var pkg = module.pkg || seed.seedPackage,
SEED = require.seed;

Cmds.collectPluginInfo(function(err, pluginInfo) {
if (err) return done(err);
Cmds.commands = core.once(function(done) {
var pluginInfo = Cmds.collectPluginInfo('seed:commands');

var ret = Co.mixin({}, pluginInfo['seed']);
Object.keys(pluginInfo).forEach(function(packageId) {
if (packageId === 'seed') return ; // skip since we put it there first

var commands = pluginInfo[packageId];
if (!commands) return ; // nothing to do

for(var key in commands) {
if (!commands.hasOwnProperty(key)) continue;
var path = commands[key];
if (path.indexOf(':')<0) path = packageId + ':' + path; // namespace
ret[key.toLowerCase()] = path;
}
});
var ret = core.mixin({}, pluginInfo['seed']);
Object.keys(pluginInfo).forEach(function(packageId) {
if (packageId === 'seed') return ; // skip since we put it there first

var commands = pluginInfo[packageId];
if (!commands) return ; // nothing to do

done(null, ret);
for(var key in commands) {
if (!commands.hasOwnProperty(key)) continue;
var path = commands[key];
if (path.indexOf(':')<0) path = packageId + ':' + path; // namespace
ret[key.toLowerCase()] = path;
}
});

return done(null, ret);
});


Expand All @@ -88,10 +87,11 @@ Cmds.commands = Co.once(function(done) {
on the system.
*/
Cmds.invoke = function(cmd, args, done) {
if (arguments.length<2) throw "invoke() requires least cmd and callback";
if (arguments.length<2) throw new Error("invoke() requires least cmd and callback");

if (!cmd) cmd = 'help';


Cmds.commands(function(err, commands) {
if (err) return done(err);
var packageId = commands[cmd.toLowerCase()], exports;
Expand All @@ -111,7 +111,7 @@ Cmds.invoke = function(cmd, args, done) {
// ok try to parse the options and see if we need to do help
var showHelp = false;
opts.on('help', function() { showHelp = true; });
opts.on('verbose', function() { process.env.VERBOSE = true; });
opts.on('verbose', function() { require.env.VERBOSE = true; });
opts.parse(args);
if (showHelp) {
return help.invoke(cmd, [cmd], opts, done);
Expand All @@ -126,9 +126,9 @@ Cmds.invoke = function(cmd, args, done) {
};

Cmds.invokeSync = function(cmd, args) {
return Co.wait(function(done) {
return core.wait(function(done) {
Cmds.invoke(cmd, args, function(err) {
if (err) Co.println(err);
if (err) core.println(err);
return done();
});
});
Expand All @@ -138,6 +138,6 @@ Cmds.invokeSync = function(cmd, args) {
Invoked whenever you call an unknown command
*/
Cmds.unknown = function(name, args, opts, done) {
Co.println("Command Unknown: " + name);
core.println("Command Unknown: " + name);
help.invoke(null, [], opts, done);
};
20 changes: 10 additions & 10 deletions lib/commands/config.js
Expand Up @@ -4,9 +4,9 @@
// License: Licened under MIT license (see __preamble__.js)
// ==========================================================================

if (!require.seed) throw "Can only load from within seed";
if (!require.sandbox) throw "Can only load from within seed";

var Co = require('private/co');
var core = require('private/core');
var seed = require.seed;
var semver = require('semver');

Expand All @@ -27,7 +27,7 @@ function showAllConfigs(sources, done) {
if (base) key = base + '.' + key;
if (key === 'seed.commands') continue;
if (('object' === typeof val) && !Array.isArray(val)) iter(val, key);
else if (val !== undefined) configs[key] = Co.inspect(val);
else if (val !== undefined) configs[key] = core.inspect(val);
}
}

Expand All @@ -38,7 +38,7 @@ function showAllConfigs(sources, done) {

for(var key in configs) {
if (!configs.hasOwnProperty(key)) continue;
Co.println(key + ': ' + configs[key]);
core.println(key + ': ' + configs[key]);
}

done();
Expand Down Expand Up @@ -78,12 +78,12 @@ function writeableConfig(source, path) {
key = ret.key = path.shift();

working = source.info(key);
working = isHash(working) ? Co.mixin({}, working) : {};
working = isHash(working) ? core.mixin({}, working) : {};
ret.root = working;

while(key = path.shift()) {
next = working[key];
next = isHash(next) ? Co.mixin({}, next) : {};
next = isHash(next) ? core.mixin({}, next) : {};
working[key] = next;
working = next;
}
Expand Down Expand Up @@ -123,13 +123,13 @@ exports.invoke = function(cmd, args, opts, done) {
src = sources[loc];
ret = src.info(key);
}
Co.println(key + ': '+Co.inspect(ret));
core.println(key + ': '+core.inspect(ret));
}
done();

// replace config
} else {
Co.debug(Co.inspect(sources.map(function(src) { return src.config.path; })));
core.debug(core.inspect(sources.map(function(src) { return src.config.path; })));

src = sources[sources.length-1];
if (key.indexOf('.')>=0) {
Expand All @@ -140,8 +140,8 @@ exports.invoke = function(cmd, args, opts, done) {

} else {
src.info(key, makeNative(value));
Co.println(key + ': '+Co.inspect(src.info(key)));
Co.debug(src.config.path);
core.println(key + ': '+core.inspect(src.info(key)));
core.debug(src.config.path);
src.write(function(err) { return done(err); });
}
}
Expand Down

0 comments on commit 0bb77be

Please sign in to comment.