Skip to content

Commit a885a65

Browse files
authored
A dep change (#1520)
* Remove *fakes3* dep and all associated Ruby/Rails for pure JavaScript implementation * New dev dep *S3rver* handles what we need with basic i/o for S3 on dev. Please read their homepage * Leaving *fakeS3* `.gitignore`'s in for current data path... please delete your copies as this should eventually go away... or you can manually migrate it yourself perhaps. I'll just reimport from GH the sources on dev which is a better use of my time. * Fix a potential `undefined` I put in trap a while back with a generic string. * Change all docs to accommodate this * Moved a native dependency up top (the TODO)... code style conformance * DELETE OP RETESTED... PASS NOTE: * Contributors, and up, should no longer need to launch the server as it's launched in dev automatically and should terminate with a SIGINT (app exit). Remote local hosts still supported although I've never used that myself. Closes #1519 Auto-merge
1 parent 0e2b585 commit a885a65

File tree

8 files changed

+57
-138
lines changed

8 files changed

+57
-138
lines changed

.github/CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This project uses [editor config](http://editorconfig.org/), please make sure to
1010
* [Git](http://git-scm.com/)
1111
* [node.js](http://nodejs.org/) *(see [`./package.json`](https://github.com/OpenUserJs/OpenUserJS.org/blob/master/package.json) engines for specific requirements)*
1212
* [MongoDB](http://www.mongodb.org/) (Optional. The project is preconfigured to use a dev DB on [MongoLab](https://mongolab.com/).)
13-
* [Ruby](https://www.ruby-lang.org/) (required to run [FakeS3](https://github.com/jubos/fake-s3/))
14-
* [FakeS3](https://github.com/jubos/fake-s3) (required to store libraries/scripts without [AWS S3](http://aws.amazon.com/s3/)) handled by [bundler](https://github.com/bundler/bundler)
1513

1614
#### GitHub Fork Setup
1715

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ data
2020
package-lock.json
2121
Gemfile.lock
2222

23+
S3rver
24+
2325
fakeS3
2426
dev/fakeS3
2527

Gemfile

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Repository | Reference | Recent Version
66
:--- | :---: | :---
77
[nodejs][nodeGHUrl] | [Documentation][nodejsDOCUrl] | <a href="https://raw.githubusercontent.com/nodejs/Release/master/schedule.png"><img src="https://raw.githubusercontent.com/nodejs/Release/master/schedule.png" alt="Current release schedule" title="Click to enlarge... Current release schedule" width="96" height="50"/></a> [CHANGELOG][nodejsReleasesUrl]
88
[npm][npmGHUrl] | [Documentation][npmDOCUrl] | [![npm][npmNPMVersionImage]][npmNPMUrl] [CHANGELOG][npmGHReleasesUrl]
9-
[bundler][bundlerGHUrl] | [Documentation][bundlerDOCUrl] | [![GEM version][bundlerGEMVersionImage]][bundlerGEMUrl] [CHANGELOG][bundlerGHReleasesUrl]
109

1110
### Contributing
1211

@@ -38,7 +37,6 @@ Repository | Reference | Recent Version
3837
[express-brute-mongo][express-brute-mongoGHUrl] <br />&#x22D4; [`MongoDBv3.x`][express-brute-mongoGHMongoDBv3.xUrl] | [Documentation][express-brute-mongoDOCUrl] | [![NPM version][express-brute-mongoNPMVersionImage]][express-brute-mongoNPMUrl]
3938
[express-minify][express-minifyGHUrl] | [Documentation][express-minifyDOCUrl] | [![NPM version][express-minifyNPMVersionImage]][express-minifyNPMUrl]
4039
[express-session][express-sessionGHUrl] | [Documentation][express-sessionDOCUrl] | [![NPM version][express-sessionNPMVersionImage]][express-sessionNPMUrl]
41-
[fakes3][fakes3GHUrl] | [Documentation][fakes3DOCUrl] | [![GEM version][fakes3GEMVersionImage]][fakes3GEMUrl]
4240
[font-awesome][font-awesomeGHUrl] | [Documentation][font-awesomeDOCUrl] | [![NPM version][font-awesomeNPMVersionImage]][font-awesomeNPMUrl]
4341
[formidable][formidableGHUrl] | [Documentation][formidableDOCUrl] | [![NPM version][formidableNPMVersionImage]][formidableNPMUrl]
4442
[git-rev][git-revGHUrl] | [Documentation][git-revDOCUrl] | [![NPM version][git-revNPMVersionImage]][git-revNPMUrl]
@@ -75,6 +73,7 @@ Repository | Reference | Recent Version
7573
[pegjs][pegjsGHUrl] | [Documentation][pegjsDOCUrl] | [![NPM version][pegjsNPMVersionImage]][pegjsNPMUrl]
7674
[request][requestGHUrl] | [Documentation][requestDOCUrl] | [![NPM version][requestNPMVersionImage]][requestNPMUrl]
7775
[rfc2047][rfc2047GHUrl] | [Documentation][rfc2047DOCUrl] | [![NPM version][rfc2047NPMVersionImage]][rfc2047NPMUrl]
76+
[S3rver][s3rverGHUrl] | [Documentation][s3rverDOCUrl] | [![NPM version][s3rverNPMVersionImage]][s3rverNPMUrl]
7877
[sanitize-html][sanitize-htmlGHUrl] | [Documentation][sanitize-htmlDOCUrl] | [![NPM version][sanitize-htmlNPMVersionImage]][sanitize-htmlNPMUrl]
7978
[select2][select2GHUrl] | [Documentation][select2DOCUrl] | [![NPM version][select2NPMVersionImage]][select2NPMUrl]
8079
[select2-bootstrap-css][select2-bootstrap-cssGHUrl] | [Documentation][select2-bootstrap-cssDOCUrl] | [![NPM version][select2-bootstrap-cssNPMVersionImage]][select2-bootstrap-cssNPMUrl]
@@ -166,12 +165,6 @@ Outdated dependencies list can also be achieved with `$ npm --depth 0 outdated`
166165
[bootstrap-markdownNPMUrl]: https://www.npmjs.com/package/bootstrap-markdown
167166
[bootstrap-markdownNPMVersionImage]: https://img.shields.io/npm/v/bootstrap-markdown.svg?style=flat
168167

169-
[bundlerGHUrl]: https://github.com/bundler/bundler
170-
[bundlerDOCUrl]: http://bundler.io/
171-
[bundlerGEMUrl]: http://rubygems.org/gems/bundler
172-
[bundlerGEMVersionImage]: http://img.shields.io/gem/v/bundler.svg?style=flat
173-
[bundlerGHReleasesUrl]: https://github.com/bundler/bundler/blob/master/CHANGELOG.md
174-
175168
[clipboardGHUrl]: https://github.com/zenorocha/clipboard.js
176169
[clipboardDOCUrl]: https://github.com/zenorocha/clipboard.js/blob/master/readme.md
177170
[clipboardNPMUrl]: https://www.npmjs.com/package/clipboard
@@ -218,11 +211,6 @@ Outdated dependencies list can also be achieved with `$ npm --depth 0 outdated`
218211
[express-sessionNPMUrl]: https://www.npmjs.com/package/express-session
219212
[express-sessionNPMVersionImage]: https://img.shields.io/npm/v/express-session.svg?style=flat
220213

221-
[fakes3GHUrl]: https://github.com/jubos/fake-s3
222-
[fakes3DOCUrl]: http://www.rubydoc.info/gems/fakes3
223-
[fakes3GEMUrl]: http://rubygems.org/gems/fakes3
224-
[fakes3GEMVersionImage]: http://img.shields.io/gem/v/fakes3.svg?style=flat
225-
226214
[font-awesomeGHUrl]: https://github.com/FortAwesome/Font-Awesome
227215
[font-awesomeDOCUrl]: http://fontawesome.io/
228216
[font-awesomeNPMUrl]: https://www.npmjs.com/package/font-awesome
@@ -417,6 +405,11 @@ Outdated dependencies list can also be achieved with `$ npm --depth 0 outdated`
417405
[rfc2047NPMUrl]: https://www.npmjs.com/package/rfc2047
418406
[rfc2047NPMVersionImage]: https://img.shields.io/npm/v/rfc2047.svg?style=flat
419407

408+
[s3rverGHUrl]: https://github.com/jamhall/s3rver
409+
[s3rverDOCUrl]: https://github.com/jamhall/s3rver/blob/master/README.md
410+
[s3rverNPMUrl]: https://www.npmjs.com/package/s3rver
411+
[s3rverNPMVersionImage]: https://img.shields.io/npm/v/s3rver.svg?style=flat
412+
420413
[sanitize-htmlGHUrl]: https://github.com/punkave/sanitize-html
421414
[sanitize-htmlDOCUrl]: https://github.com/punkave/sanitize-html/blob/master/README.md
422415
[sanitize-htmlNPMUrl]: https://www.npmjs.com/package/sanitize-html

controllers/scriptStorage.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ var statusError = require('../libs/debug').statusError;
1111
//--- Dependency inclusions
1212
var fs = require('fs');
1313
var util = require('util');
14+
var http = require('http');
1415
var _ = require('underscore');
1516
var crypto = require('crypto');
1617
var request = require('request');
1718
var stream = require('stream');
1819
var peg = require('pegjs');
1920
var AWS = require('aws-sdk');
21+
var S3rver = require('s3rver');
2022
var UglifyJS = require("uglify-es");
2123
var rfc2047 = require('rfc2047');
2224
var mediaType = require('media-type');
@@ -114,24 +116,64 @@ var parsers = (function () {
114116
exports.parsers = parsers;
115117

116118
var bucketName = 'OpenUserJS.org';
119+
if (isDev) {
120+
bucketName = bucketName.toLowerCase(); // NOTE: *S3rver* requirement
121+
}
117122

118123
var DEV_AWS_URL = null;
124+
var devAWSURL = null;
125+
var serverS3 = null;
119126

120127
if (isPro) {
121128
AWS.config.update({
122129
region: 'us-east-1'
123130
});
124131
} else {
125-
// You need to install (and ruby too): https://github.com/jubos/fake-s3
126-
// Then run the fakes3.sh script or: fakes3 -r fakeS3 -p 10001
127132
DEV_AWS_URL = process.env.DEV_AWS_URL || 'http://localhost:10001';
128133
AWS.config.update({
129134
accessKeyId: 'fakeId',
130135
secretAccessKey: 'fakeKey',
131136
httpOptions: {
132137
proxy: DEV_AWS_URL,
133-
agent: require('http').globalAgent // TODO: Move this up eventually
138+
agent: http.globalAgent
139+
}
140+
});
141+
142+
devAWSURL = new URL(DEV_AWS_URL);
143+
144+
serverS3 = new S3rver({
145+
hostname: devAWSURL.hostname,
146+
port: devAWSURL.port,
147+
directory: './S3rver' // WATCHPOINT: Technically this should be `..` Is probably upstream issue
148+
}).run(function (aErr) {
149+
if (aErr) {
150+
console.error([
151+
colors.red('ERROR: S3rver not initialized'),
152+
aErr
153+
].join('\n'));
154+
return;
134155
}
156+
console.log(colors.green('S3rver initialized'));
157+
158+
var s3 = new AWS.S3();
159+
s3.createBucket({ Bucket: bucketName }, function (aErr) {
160+
if (aErr) {
161+
switch (aErr.statusCode) {
162+
case 409:
163+
console.log(colors.green('Default dev S3 bucket already exists'));
164+
break;
165+
default:
166+
console.error([
167+
colors.red('Error creating default dev S3 bucket'),
168+
aErr
169+
].join('\n'));
170+
// fallthrough
171+
}
172+
return;
173+
} else {
174+
console.log(colors.green('Created default dev S3 bucket'));
175+
}
176+
});
135177
});
136178
}
137179

controllers/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ function getExistingScript(aReq, aOptions, aAuthedUser, aCallback) {
19521952
'S3 GET (chunking indirect) ',
19531953
aErr.code,
19541954
'for', installNameBase + (isLib ? '.js' : '.user.js'),
1955-
'in the', bucketName, 'bucket\n' +
1955+
'in the S3 bucket\n' +
19561956
JSON.stringify(aErr, null, ' ') + '\n' +
19571957
aErr.stack
19581958
);

dev/postinstall.js

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -26,123 +26,6 @@ var tasks = [
2626
aCallback(null, ['$ ' + cmd + '\n' + colors.gray(aStdout)]);
2727
});
2828
},
29-
function (aStdouts, aCallback) {
30-
var cmd = 'ruby -v';
31-
32-
exec(cmd, function (aErr, aStdout, aStderr) {
33-
if (aErr) {
34-
aCallback(aErr);
35-
return;
36-
}
37-
38-
aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
39-
aCallback(null, aStdouts);
40-
});
41-
},
42-
function (aStdouts, aCallback) {
43-
var cmd = 'bundler -v';
44-
45-
exec(cmd, function (aErr, aStdout, aStderr) {
46-
if (aErr) {
47-
if (aErr.code === 127) {
48-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
49-
aCallback(null, false, aStdouts);
50-
return;
51-
} else {
52-
aCallback(aErr);
53-
return;
54-
}
55-
}
56-
57-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
58-
aCallback(null, true, aStdouts);
59-
});
60-
},
61-
function (aSkip, aStdouts, aCallback) {
62-
var cmd = 'sudo gem install bundler -v 1.16.4';
63-
64-
if (aSkip) {
65-
aCallback(null, aStdouts);
66-
return;
67-
}
68-
69-
console.log(colors.cyan('Installing *bundler* gem as global...'));
70-
71-
exec(cmd, function (aErr, aStdout, aStderr) {
72-
if (aErr) {
73-
aCallback(aErr);
74-
return;
75-
}
76-
77-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
78-
aCallback(null, aStdouts);
79-
});
80-
},
81-
function (aStdouts, aCallback) {
82-
var cmd = 'bundler outdated';
83-
84-
exec(cmd, function (aErr, aStdout, aStderr) {
85-
if (aErr) {
86-
if (aErr.code === 7) {
87-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
88-
aCallback(null, false, aStdouts);
89-
return;
90-
} else {
91-
aCallback(aErr);
92-
return;
93-
}
94-
}
95-
96-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
97-
aCallback(null, true, aStdouts);
98-
});
99-
},
100-
function (aSkip, aStdouts, aCallback) {
101-
var cmd = 'bundler install';
102-
103-
if (aSkip) {
104-
aCallback(null, aStdouts);
105-
return;
106-
}
107-
108-
console.log(colors.cyan('Installing bundled gem(s) as global...'));
109-
110-
exec(cmd, function (aErr, aStdout, aStderr) {
111-
if (aErr) {
112-
aCallback(aErr);
113-
return;
114-
}
115-
116-
// aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
117-
aCallback(null, aStdouts);
118-
});
119-
},
120-
function (aStdouts, aCallback) {
121-
var cmd = 'gem list';
122-
123-
exec(cmd, function (aErr, aStdout, aStderr) {
124-
if (aErr) {
125-
aCallback(aErr);
126-
return;
127-
}
128-
129-
aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
130-
aCallback(null, aStdouts);
131-
});
132-
},
133-
function (aStdouts, aCallback) {
134-
var cmd = 'gem outdated';
135-
136-
exec(cmd, function (aErr, aStdout, aStderr) {
137-
if (aErr) {
138-
aCallback(aErr);
139-
return;
140-
}
141-
142-
aStdouts.push('$ ' + cmd + '\n' + colors.gray(aStdout));
143-
aCallback(null, aStdouts);
144-
});
145-
},
14629
function (aStdouts, aCallback) {
14730
var cmd = 'npm -v';
14831

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"underscore": "1.9.1",
6969
"useragent": "2.3.0"
7070
},
71+
"devDependencies": {
72+
"s3rver": "2.2.6"
73+
},
7174
"optionalDependencies": {
7275
"kerberos": "1.0.0"
7376
},

0 commit comments

Comments
 (0)