UNPKG

2.17 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.10.0
2(function() {
3 var assert, colors, fs, init, path, popular_modules, userHome, yaml;
4
5 assert = require('assert');
6
7 colors = require('colors');
8
9 fs = require('fs');
10
11 path = require('path');
12
13 userHome = require('user-home');
14
15 yaml = require('js-yaml');
16
17 popular_modules = [];
18
19 init = function(opts) {
20 var config, exp, exports, i, len, module_name;
21 if (opts._ && opts._[1]) {
22 opts.path = opts._[1];
23 } else {
24 opts.path = opts.path || this.path || process.cwd();
25 }
26 if (!opts.path) {
27 throw new Error('Path is required.');
28 } else if (!fs.existsSync(opts.path)) {
29 throw new Error("Path does not exist: " + opts.path);
30 }
31 config = this.load(opts.path);
32 if (config !== false) {
33 throw new Error("Autocode has already been initialized in: " + opts.path);
34 }
35 console.log(("Initializing Autocode in: " + opts.path).green.bold);
36 config = {};
37 if (opts.name) {
38 config.name = opts.name;
39 } else {
40 config.name = path.basename(opts.path);
41 }
42 if (opts.description) {
43 config.description = opts.description;
44 }
45 if (opts.author) {
46 config.author = {
47 name: opts.author_name,
48 email: opts.author_email,
49 url: opts.author_url
50 };
51 }
52 if (opts.copyright) {
53 config.copyright = opts.copyright;
54 }
55 if (opts.modules) {
56 config.modules = {};
57 for (module_name in opts.modules) {
58 exports = opts.modules[module_name];
59 config.modules[module_name] = 'latest';
60 if (exports.length) {
61 config.imports = {};
62 for (i = 0, len = exports.length; i < len; i++) {
63 exp = exports[i];
64 config.imports["" + exp] = module_name + "." + exp;
65 }
66 }
67 }
68 }
69 config = yaml.safeDump(config);
70 if (!fs.existsSync(opts.path + "/.autocode")) {
71 fs.mkdirSync(opts.path + "/.autocode");
72 }
73 fs.writeFileSync(opts.path + "/.autocode/config.yml", config);
74 console.log('Autocode initialization is complete.'.green);
75 return this.build(opts.path);
76 };
77
78 module.exports = init;
79
80}).call(this);