1 | var path = require('path');
|
2 | var config = require('./config');
|
3 | var AmpersandState = require('ampersand-state');
|
4 |
|
5 | var Model = AmpersandState.extend({
|
6 | props: {
|
7 | name: {
|
8 | type: 'string',
|
9 | default: 'mongodb'
|
10 | },
|
11 | platform: {
|
12 | type: 'string'
|
13 | },
|
14 | version: {
|
15 | type: 'string'
|
16 | },
|
17 | filename: {
|
18 | type: 'string'
|
19 | },
|
20 | url: {
|
21 | type: 'string'
|
22 | },
|
23 | debug: {
|
24 | type: 'boolean',
|
25 | default: false
|
26 | },
|
27 | enterprise: {
|
28 | type: 'boolean',
|
29 | default: false
|
30 | },
|
31 | distro: {
|
32 | type: 'string'
|
33 | },
|
34 | bits: {
|
35 | type: 'string'
|
36 | },
|
37 | directory: {
|
38 | type: 'string'
|
39 | }
|
40 | },
|
41 | derived: {
|
42 | download_directory: {
|
43 | deps: ['directory'],
|
44 | fn: function() {
|
45 | if (!this.directory) {
|
46 | return undefined;
|
47 | }
|
48 | return path.join(this.directory, 'downloads');
|
49 | }
|
50 | },
|
51 | download_path: {
|
52 | deps: ['download_directory', 'filename'],
|
53 | fn: function() {
|
54 | if (!this.download_directory) {
|
55 | return undefined;
|
56 | }
|
57 | return path.join(this.download_directory, this.filename);
|
58 | }
|
59 | },
|
60 | root_directory: {
|
61 | deps: ['directory', 'name', 'version', 'platform', 'bits', 'enterprise', 'debug'],
|
62 | fn: function() {
|
63 | if (!this.directory) {
|
64 | return undefined;
|
65 | }
|
66 | var dir = [this.name, this.version, this.platform, this.bits].join('-');
|
67 | if (this.enterprise) {
|
68 | dir += '-enterprise';
|
69 | }
|
70 | if (this.debug) {
|
71 | dir += '-debug';
|
72 | }
|
73 | return path.join(this.directory, dir);
|
74 | }
|
75 | },
|
76 | bin_directory: {
|
77 | deps: ['root_directory'],
|
78 | fn: function() {
|
79 | if (!this.root_directory) {
|
80 | return undefined;
|
81 | }
|
82 | return path.join(this.root_directory, 'bin');
|
83 | }
|
84 | }
|
85 | },
|
86 | initialize: function(attrs) {
|
87 | attrs = attrs || {};
|
88 | if (attrs.artifact) {
|
89 | this.filename = attrs.filename = attrs.artifact;
|
90 | }
|
91 | this.directory = attrs.directory = config.ROOT_DIRECTORY;
|
92 | if (attrs.platform === 'win32') {
|
93 | this.platform = attrs.platform = 'windows';
|
94 | }
|
95 | }
|
96 | });
|
97 |
|
98 | module.exports = Model;
|