Skip to content

Commit aa2c80d

Browse files
committed
major reorg, now compiling mimosa with mimosa so can deploy to NPM as js not coffee, references #187, also fixes #207, issues with emblem template validation and template comment
1 parent c6a9580 commit aa2c80d

File tree

262 files changed

+40511
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+40511
-44
lines changed

.gitignore

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
.DS_Store
2-
3-
lib-cov
4-
*.seed
5-
*.log
6-
*.csv
7-
*.dat
8-
*.out
9-
*.pid
10-
*.gz
11-
12-
pids
13-
logs
14-
results
15-
16-
node_modules
17-
npm-debug.log
1+
node_modules

bin/mimosa

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
require('coffee-script');
43
var path = require('path'),
54
fs = require('fs');
65

lib/command/build.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var Cleaner, Watcher, build, configurer, logger, register,
2+
_this = this;
3+
4+
logger = require('logmimosa');
5+
6+
configurer = require('../util/configurer');
7+
8+
Watcher = require('../util/watcher');
9+
10+
Cleaner = require('../util/cleaner');
11+
12+
build = function(opts, foo, bar, baz, what) {
13+
if (opts.debug) {
14+
logger.setDebug();
15+
process.env.DEBUG = true;
16+
}
17+
logger.info("Beginning build");
18+
opts.build = true;
19+
return configurer(opts, function(config, modules) {
20+
var doBuild;
21+
22+
doBuild = function() {
23+
config.isClean = false;
24+
return new Watcher(config, modules, false, function() {
25+
logger.success("Finished build");
26+
return process.exit(0);
27+
});
28+
};
29+
config.isClean = true;
30+
return new Cleaner(config, modules, doBuild);
31+
});
32+
};
33+
34+
register = function(program, callback) {
35+
return program.command('build').description("make a single pass through assets, compile them, and optionally package them").option("-o, --optimize", "run r.js optimization after building").option("-m, --minify", "minify each asset as it is compiled using uglify").option("-p, --package", "package code for distribution after the code has been built").option("-P, --profile <profileName>", "select a mimosa profile").option("-D, --debug", "run in debug mode").action(callback).on('--help', function() {
36+
logger.green(' The build command will make a single pass through your assets and bulid any that need building');
37+
logger.green(' and then exit.');
38+
logger.blue('\n $ mimosa build\n');
39+
logger.green(' Pass an \'optimize\' flag and Mimosa will use requirejs to optimize your assets and provide you');
40+
logger.green(' with single files for the named requirejs modules. ');
41+
logger.blue('\n $ mimosa build --optimize');
42+
logger.blue(' $ mimosa build -o\n');
43+
logger.green(' Pass an \'minify\' flag and Mimosa will use uglify to minify/compress your assets when they are compiled.');
44+
logger.green(' You can provide exclude, files you do not want to minify, in the mimosa-config. If you run \'minify\' ');
45+
logger.green(' and \'optimize\' at the same time, optimize will not run the uglify portion of its processing which occurs as');
46+
logger.green(' a separate step after everything has compiled and does not allow control of what gets uglified. Use \'optimize\'');
47+
logger.green(' and \'minify\' together if you need to control which files get mangled by uglify (because sometimes uglify');
48+
logger.green(' can break them) but you still want everything together in a single file.');
49+
logger.blue('\n $ mimosa watch --minify');
50+
logger.blue(' $ mimosa watch -m\n');
51+
logger.green(' Pass a \'package\' flag if you have installed a module (like mimosa-web-package) that is capable of');
52+
logger.green(' executing packaging functionality for you after the building of assets is complete.');
53+
logger.blue('\n $ mimosa build --package');
54+
logger.blue(' $ mimosa build -p\n');
55+
logger.green(' Pass a \'profile\' flag and the name of a Mimosa profile to run with mimosa config overrides from a profile.');
56+
logger.blue('\n $ mimosa build --profile build');
57+
return logger.blue(' $ mimosa build -P build');
58+
});
59+
};
60+
61+
module.exports = function(program) {
62+
return register(program, build);
63+
};

lib/command/clean.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var Cleaner, clean, configurer, fs, logger, register, wrench,
2+
_this = this;
3+
4+
fs = require('fs');
5+
6+
wrench = require('wrench');
7+
8+
logger = require('logmimosa');
9+
10+
Cleaner = require('../util/cleaner');
11+
12+
configurer = require('../util/configurer');
13+
14+
clean = function(opts) {
15+
var _this = this;
16+
17+
if (opts.debug) {
18+
logger.setDebug();
19+
process.env.DEBUG = true;
20+
}
21+
opts.clean = true;
22+
return configurer(opts, function(config, modules) {
23+
if (opts.force) {
24+
if (fs.existsSync(config.watch.compiledDir)) {
25+
logger.info("Forcibly removing the entire directory [[ " + config.watch.compiledDir + " ]]");
26+
wrench.rmdirSyncRecursive(config.watch.compiledDir);
27+
return logger.success("[[ " + config.watch.compiledDir + " ]] has been removed");
28+
} else {
29+
return logger.success("Compiled directory already deleted");
30+
}
31+
} else {
32+
config.isClean = true;
33+
return new Cleaner(config, modules, function() {
34+
logger.success("[[ " + config.watch.compiledDir + " ]] has been cleaned.");
35+
return process.exit(0);
36+
});
37+
}
38+
});
39+
};
40+
41+
register = function(program, callback) {
42+
return program.command('clean').option("-f, --force", "completely delete your compiledDir").option("-P, --profile <profileName>", "select a mimosa profile").option("-D, --debug", "run in debug mode").description("clean out all of the compiled assets from the compiled directory").action(callback).on('--help', function() {
43+
logger.green(' The clean command will remove all of the compiled assets from the configured compiledDir. After');
44+
logger.green(' the assets are deleted, any empty directories left over are also removed. Mimosa will also remove any');
45+
logger.green(' Mimosa copied assets, like template libraries. It will not remove anything that did not originate');
46+
logger.green(' from the source directory.');
47+
logger.blue('\n $ mimosa clean\n');
48+
logger.green(' In the course of development, some files get left behind that no longer have counterparts in your');
49+
logger.green(' source directories. If you have \'mimosa watch\' turned off when you delete a file, for instance,');
50+
logger.green(' the compiled version of that file will not get removed from your compiledDir, and \'mimosa clean\'');
51+
logger.green(' will leave it alone because it does not recognize it as coming from mimosa. If you want to ');
52+
logger.green(' forcibly remove the entire compiledDir, use the \'force\' flag.');
53+
logger.blue('\n $ mimosa clean -force');
54+
logger.blue(' $ mimosa clean -f\n');
55+
logger.green(' Pass a \'profile\' flag and the name of a Mimosa profile to run with mimosa config overrides from a profile.');
56+
logger.blue('\n $ mimosa clean --profile build');
57+
return logger.blue(' $ mimosa clean -P build');
58+
});
59+
};
60+
61+
module.exports = function(program) {
62+
return register(program, clean);
63+
};

lib/command/config.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var buildConfig, copyConfig, fs, logger, path, register;
2+
3+
path = require('path');
4+
5+
fs = require('fs');
6+
7+
logger = require('logmimosa');
8+
9+
buildConfig = require('../util/config-builder');
10+
11+
copyConfig = function(opts) {
12+
var configText, currPath;
13+
14+
if (opts.debug) {
15+
logger.setDebug();
16+
process.env.DEBUG = true;
17+
}
18+
currPath = path.join(path.resolve(''), "mimosa-config.coffee");
19+
if (fs.existsSync(currPath)) {
20+
logger.warn("A mimosa-config.coffee already exists in this directory. Will not overwrite. Please navigate to a directory that does not contain a mimosa-config.");
21+
} else {
22+
configText = buildConfig();
23+
logger.debug("Writing config file to " + currPath);
24+
fs.writeFileSync(currPath, configText, 'ascii');
25+
logger.success("Copied default config file into current directory.");
26+
}
27+
return process.exit(0);
28+
};
29+
30+
register = function(program, callback) {
31+
var _this = this;
32+
33+
return program.command('config').option("-D, --debug", "run in debug mode").description("copy the default Mimosa config into the current folder").action(callback).on('--help', function() {
34+
logger.green(' The config command will copy the default Mimosa config to the current directory.');
35+
logger.green(' There are no options for the config command.');
36+
return logger.blue('\n $ mimosa config\n');
37+
});
38+
};
39+
40+
module.exports = function(program) {
41+
return register(program, copyConfig);
42+
};

lib/command/external.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var Cleaner, Watcher, configurer, logger, modules;
2+
3+
modules = require('../modules');
4+
5+
configurer = require('../util/configurer');
6+
7+
Watcher = require('../util/watcher');
8+
9+
Cleaner = require('../util/cleaner');
10+
11+
logger = require('logmimosa');
12+
13+
module.exports = function(program) {
14+
var mod, _i, _len, _ref, _results;
15+
16+
_ref = modules.modulesWithCommands();
17+
_results = [];
18+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19+
mod = _ref[_i];
20+
_results.push(mod.registerCommand(program, function(buildFirst, callback) {
21+
var _this = this;
22+
23+
return configurer({}, function(config, mods) {
24+
if (buildFirst) {
25+
config.isClean = true;
26+
return new Cleaner(config, mods, function() {
27+
config.isClean = false;
28+
return new Watcher(config, mods, false, function() {
29+
logger.success("Finished build");
30+
return callback(config);
31+
});
32+
});
33+
} else {
34+
return callback(config);
35+
}
36+
});
37+
}));
38+
}
39+
return _results;
40+
};

lib/command/module/config.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var config, getModule, logger, register;
2+
3+
logger = require('logmimosa');
4+
5+
config = function(name, opts) {
6+
var mod, text;
7+
8+
if (name == null) {
9+
return logger.error("Must provide a module name, ex: mimosa mod:config mimosa-moduleX");
10+
}
11+
mod = getModule(name);
12+
if (mod == null) {
13+
mod = getModule("mimosa-" + name);
14+
}
15+
if (mod != null) {
16+
if (mod.placeholder) {
17+
text = mod.placeholder();
18+
logger.green("" + text + "\n\n");
19+
} else {
20+
logger.info("Module [[ " + name + " ]] has no configuration");
21+
}
22+
} else {
23+
return logger.error("Could not find module named [[ " + name + " ]]");
24+
}
25+
return process.exit(0);
26+
};
27+
28+
getModule = function(name) {
29+
var err;
30+
31+
try {
32+
return require(name);
33+
} catch (_error) {
34+
err = _error;
35+
return logger.debug("Did not find module named [[ " + name + " ]]");
36+
}
37+
};
38+
39+
register = function(program, callback) {
40+
var _this = this;
41+
42+
return program.command('mod:config [name]').option("-D, --debug", "run in debug mode").description("Print out the configuration snippet for a module to the console").action(callback).on('--help', function() {
43+
logger.green(' The mod:config command will print out the default commented out CoffeeScript snippet ');
44+
logger.green(' for the given named Mimosa module. If there is already a mimosa-config.coffee in the');
45+
logger.green(' current directory, Mimosa will not copy the file in.');
46+
return logger.blue('\n $ mimosa mod:config [nameOfModule]\n');
47+
});
48+
};
49+
50+
module.exports = function(program) {
51+
return register(program, config);
52+
};

lib/command/module/init.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var copySkeleton, fs, init, logger, path, register, wrench;
2+
3+
path = require('path');
4+
5+
fs = require('fs');
6+
7+
wrench = require('wrench');
8+
9+
logger = require('logmimosa');
10+
11+
init = function(name, opts) {
12+
var moduleDirPath;
13+
14+
if (name == null) {
15+
return logger.error("Must provide a module name, ex: mimosa mod:init mimosa-moduleX");
16+
}
17+
if (name.indexOf('mimosa-') !== 0) {
18+
return logger.error("Your Mimosa module name isn't prefixed with 'mimosa-'. To work properly with Mimosa, " + "modules must be prefixed with 'mimosa-', ex: 'mimosa-moduleX'.");
19+
}
20+
moduleDirPath = path.resolve(name);
21+
return fs.exists(moduleDirPath, function(exists) {
22+
if (exists) {
23+
logger.warn("Directory/file already exists at [[ " + moduleDirPath + " ]], will not overwrite it.");
24+
return process.exit(0);
25+
} else {
26+
return copySkeleton(name, opts.coffee, moduleDirPath);
27+
}
28+
});
29+
};
30+
31+
copySkeleton = function(name, isCoffee, moduleDirPath) {
32+
var lang, npmignore, packageJson, skeletonPath;
33+
34+
lang = isCoffee ? "coffee" : 'js';
35+
skeletonPath = path.join(__dirname, '..', '..', '..', 'skeletons', 'module', lang);
36+
wrench.copyDirSyncRecursive(skeletonPath, moduleDirPath, {
37+
excludeHiddenUnix: false
38+
});
39+
npmignore = path.join(moduleDirPath, 'npmignore');
40+
if (fs.existsSync(npmignore)) {
41+
fs.renameSync(npmignore, path.join(moduleDirPath, '.npmignore'));
42+
}
43+
packageJson = path.join(moduleDirPath, 'package.json');
44+
return fs.readFile(packageJson, 'ascii', function(err, text) {
45+
text = text.replace('???', name);
46+
return fs.writeFile(packageJson, text, function(err) {
47+
var readme;
48+
49+
readme = path.join(moduleDirPath, 'README.md');
50+
return fs.readFile(readme, 'ascii', function(err, text) {
51+
text = text.replace(/\?\?\?/g, name);
52+
return fs.writeFile(readme, text, function(err) {
53+
logger.success(("Module skeleton successfully placed in " + name + " directory. The first thing you'll") + (" want to do is go into " + name + path.sep + "package.json and replace the placeholders."));
54+
return process.exit(0);
55+
});
56+
});
57+
});
58+
});
59+
};
60+
61+
register = function(program, callback) {
62+
var _this = this;
63+
64+
return program.command('mod:init [name]').option("-D, --debug", "run in debug mode").option("-c, --coffee", "get a coffeescript version of the skeleton").description("create a Mimosa module skeleton in the named directory").action(callback).on('--help', function() {
65+
logger.green(' The mod:init command will create a directory for the name given, and place a starter');
66+
logger.green(' module skeleton into the directory. If a directory for the name given already exists');
67+
logger.green(' Mimosa will place the module skeleton inside of it.');
68+
logger.blue('\n $ mimosa mod:init [nameOfModule]\n');
69+
logger.green(' The default skeleton is written in JavaScript. If you want a skeleton delivered');
70+
return logger.green(' in CoffeeScript add a \'coffee\' flag.');
71+
});
72+
};
73+
74+
module.exports = function(program) {
75+
return register(program, init);
76+
};

0 commit comments

Comments
 (0)