1 | var path = require('path');
|
2 | var Project = require('../lib/project');
|
3 | var Atmosphere = require('../lib/atmosphere');
|
4 | var fs = require('fs');
|
5 | var _ = require('underscore');
|
6 | var wrench = require('wrench');
|
7 |
|
8 | Meteorite = function(args, meteorArgs) {
|
9 | this.args = args;
|
10 | this.meteorArgs = meteorArgs;
|
11 |
|
12 |
|
13 | Meteorite.prepareFS();
|
14 |
|
15 | this.project = new Project(process.cwd(), args);
|
16 | };
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | Meteorite.prototype.create = function(fn) {
|
22 | var self = this;
|
23 |
|
24 |
|
25 | var appName = this.args._[1] || this.args.example;
|
26 |
|
27 | if (!appName)
|
28 | throw 'No name provided to mrt create!';
|
29 |
|
30 |
|
31 | if (this.args.path)
|
32 | this.args.path = path.resolve(process.cwd(), this.args.path);
|
33 |
|
34 | self.project = new Project(path.join(process.cwd(), appName), this.args);
|
35 | self.project.meteor.execute(this.meteorArgs, function() {
|
36 |
|
37 |
|
38 | self.project.writeSmartJson();
|
39 | fn();
|
40 |
|
41 | });
|
42 | };
|
43 |
|
44 | Meteorite.prototype['create-package'] = function(fn) {
|
45 | var self = this;
|
46 |
|
47 | var packageDir = this.args._[1]
|
48 | var packageName = path.basename(packageDir);
|
49 |
|
50 | console.log("Creating package named " + packageName + " in " + packageDir);
|
51 |
|
52 | var packageFile = packageName + '.js';
|
53 | var testFile = packageName + '_tests.js';
|
54 |
|
55 | wrench.mkdirSyncRecursive(packageDir);
|
56 |
|
57 |
|
58 | fs.writeFileSync(path.join(packageDir, 'package.js'),
|
59 | 'Package.describe({\n' +
|
60 | ' summary: "/* fill me in */"\n' +
|
61 | '});\n\n' +
|
62 | 'Package.on_use(function (api, where) {\n' +
|
63 | ' api.add_files(\'' + packageFile + '\', [\'client\', \'server\']);\n' +
|
64 | '});\n\n' +
|
65 | 'Package.on_test(function (api) {\n' +
|
66 | ' api.use(\'' + packageName + '\');\n\n' +
|
67 | ' api.add_files(\'' + testFile + '\', [\'client\', \'server\']);\n' +
|
68 | '});\n'
|
69 | );
|
70 |
|
71 |
|
72 | fs.writeFileSync(path.join(packageDir, packageFile), '');
|
73 | fs.writeFileSync(path.join(packageDir, testFile), '');
|
74 |
|
75 |
|
76 | fs.writeFileSync(path.join(packageDir, 'smart.json'), JSON.stringify({
|
77 | "name": packageName,
|
78 | "description": "",
|
79 | "homepage": "",
|
80 | "author": "",
|
81 | "version": "0.0.1",
|
82 | "git": "",
|
83 | "packages": {}
|
84 | }, null, 2));
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | Meteorite.prototype['link-package'] = function(fn) {
|
90 | var self = this;
|
91 |
|
92 | var packageDir = this.args._[1];
|
93 | var packageName = path.basename(packageDir);
|
94 | var packagePath = 'packages/' + packageName;
|
95 |
|
96 | console.log("Linking package named " + packageName + " to " + packageDir);
|
97 |
|
98 | var old;
|
99 | try { old = fs.readlinkSync(packagePath); } catch (err) {}
|
100 |
|
101 |
|
102 | if (old && old === packageDir)
|
103 | return;
|
104 |
|
105 |
|
106 | if (old)
|
107 | fs.unlinkSync(packagePath);
|
108 |
|
109 | fs.symlinkSync(packageDir, packagePath);
|
110 | }
|
111 |
|
112 |
|
113 |
|
114 | Meteorite.prototype.install = function(fn) {
|
115 | this.project.install(fn);
|
116 | };
|
117 |
|
118 | Meteorite.prototype.update = function(fn) {
|
119 | this.project.update(fn);
|
120 | };
|
121 |
|
122 | Meteorite.prototype.publish = function(fn) {
|
123 | Atmosphere.publish(fn);
|
124 | };
|
125 |
|
126 | Meteorite.prototype.release = function(fn) {
|
127 | Atmosphere.release(fn);
|
128 | };
|
129 |
|
130 | Meteorite.prototype.uninstall = function(fn) {
|
131 | if (this.args.system)
|
132 | Meteorite.uninstall();
|
133 | else
|
134 | this.project.uninstall(fn);
|
135 | };
|
136 |
|
137 |
|
138 | Meteorite.prototype.add = function(fn) {
|
139 | var self = this;
|
140 | var packageName = this.meteorArgs[1];
|
141 |
|
142 | var version = this.args['pkg-version'];
|
143 |
|
144 |
|
145 |
|
146 | if (this.args._.length > 2)
|
147 | console.log("NOTE: mrt add only supports adding a single package at a time, truncating.");
|
148 |
|
149 |
|
150 | self.project.installPackage(packageName, version, function() {
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | self.project.isUsing(packageName, function(success) {
|
158 | if (!success) {
|
159 | self.project.execute(['add', packageName], fn);
|
160 | } else {
|
161 | fn();
|
162 | }
|
163 | });
|
164 | });
|
165 | };
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | _.each([
|
171 | 'run',
|
172 | 'help',
|
173 | 'remove',
|
174 | 'list',
|
175 | 'bundle',
|
176 | 'mongo',
|
177 | 'deploy',
|
178 | 'logs',
|
179 | 'reset',
|
180 | 'test-packages'
|
181 | ], function(command) {
|
182 | Meteorite.prototype[command] = function(fn) {
|
183 | this.project.execute(this.meteorArgs, fn);
|
184 | };
|
185 | });
|
186 |
|
187 |
|
188 |
|
189 | Meteorite.root = function() {
|
190 | var homeDir = process.env.HOME;
|
191 | return path.join(homeDir, '.meteorite');
|
192 | };
|
193 |
|
194 |
|
195 | Meteorite.prepareFS = function() {
|
196 | var root = Meteorite.root();
|
197 | if (!fs.existsSync(root))
|
198 | fs.mkdirSync(root);
|
199 | };
|
200 |
|
201 |
|
202 | Meteorite.uninstall = function() {
|
203 |
|
204 | console.log('Deleting ~/.meteorite. Note that previously installed projects will no longer work');
|
205 |
|
206 | var root = Meteorite.root();
|
207 | if (fs.existsSync(root))
|
208 | wrench.rmdirSyncRecursive(root);
|
209 | };
|
210 |
|
211 | module.exports = Meteorite;
|
212 |
|
213 |
|
214 |
|