• R/O
  • HTTP
  • SSH
  • HTTPS

zephyr: Commit

This repository is for zephyr, which is implemented for a GUI of Eos.


Commit MetaInfo

Revision5a7fb38fe8e5fe801f4ac62cc638b3ae5ec6be41 (tree)
Time2016-01-25 22:55:15
Authorhimetani_cafe <fumifumi@yasu...>
Commiterhimetani_cafe

Log Message

[DEBUG] zephyr serve, zephyr debug command

zephyr serve:

NODE_ENV = 'production'
uploadDir = ZEPHYR_HOME/user-specific-files/workspace
dbPath = ZEPHYR_HOME/user-specific-files/db/db.workspace
db.workspace is a persistent file

zephyr debug:

NODE_ENV = 'debug'
uploadDir = ZEPHYR_HOME/user-specific-files/workspace.debug
dbPath = ZEPHYR_HOME/user-specific-files/db/db.debug
db.debug is renewed whenever executing zephyr debug
Please enter the commit message for your changes. Lines starting
with will be ignored, and an empty message aborts the commit.
On branch master
Changes to be committed:

modified: .gitignore
modified: cli/zephyr-debug
modified: server/api/v1/fileUpload/index.js
modified: server/app.js
modified: server/class/DB.js

Change Summary

Incremental Difference

--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,5 @@ cli/npm-debug.log*
1313 user-specific-files/OptionControlFile/
1414 user-specific-files/meta/
1515 user-specific-files/workspace/
16+user-specific-files/workspace.debug
1617 user-specific-files/db/
--- a/cli/zephyr-debug
+++ b/cli/zephyr-debug
@@ -3,12 +3,12 @@
33 const zephyr = require('commander');
44 const chalk = require('chalk');
55 const cp = require('child_process').spawn;
6+const fs = require('fs');
67
78 zephyr
89 .usage('[action]')
910
10-process.env.NODE_ENV = 'production';
11-process.env.ZEPHYR_MODE = 'DEBUG';
11+process.env.NODE_ENV = 'debug';
1212 const npm = cp('node', ['--harmony', process.env.ZEPHYR_HOME + '/server/app/']);
1313
1414 npm.stdout.on('data', function (data) {
--- a/server/api/v1/fileUpload/index.js
+++ b/server/api/v1/fileUpload/index.js
@@ -10,7 +10,11 @@ router.post('/', function(req, res) {
1010 DB()
1111 .then(function(db) {
1212 var form = new formidable.IncomingForm();
13- form.uploadDir = __dirname + '/../../../../user-specific-files/workspace';
13+ if(process.env['NODE_ENV'] === 'debug') {
14+ form.uploadDir = __dirname + '/../../../../user-specific-files/workspace.debug';
15+ } else {
16+ form.uploadDir = __dirname + '/../../../../user-specific-files/workspace';
17+ }
1418
1519 form.parse(req, function(err, fields, files) {
1620 var parentDirectory = fields['parentDirectory'];
--- a/server/app.js
+++ b/server/app.js
@@ -15,7 +15,6 @@ require('./routes')(app)
1515 var server = app.listen(config.port, config.ip, function () {
1616 console.log('Zephyr listening at http://%s:%s', config.ip, config.port);
1717 console.log(app.get('env'))
18- console.log(process.env.ZEPHYR_MODE);
1918 });
2019
2120 var io = require('socket.io').listen(server)
--- a/server/class/DB.js
+++ b/server/class/DB.js
@@ -34,7 +34,7 @@ function DB() {
3434 parentId: '',
3535 fileType: 0
3636 };
37- if(process.env.ZEPHYR_MODE === 'DEBUG') {
37+ if(process.env.NODE_ENV === 'debug') {
3838 return Files.create(root);
3939 }
4040 })
@@ -163,9 +163,9 @@ function DB() {
163163 })
164164 .then(function(fileId) {
165165 var q = {
166- where: {
167- name: fileName,
168- parentId: fileId
166+ where: {
167+ name: fileName,
168+ parentId: fileId
169169 }
170170 };
171171 return Files.findOne(q)
@@ -197,9 +197,9 @@ function DB() {
197197 })
198198 .then(function(fileId) {
199199 var q = {
200- where: {
201- name: fileName,
202- parentId: fileId
200+ where: {
201+ name: fileName,
202+ parentId: fileId
203203 }
204204 };
205205 return Files.findOne(q)
@@ -510,18 +510,42 @@ function DB() {
510510 * @constructor
511511 * @returns {promise}
512512 */
513- if(process.env['NODE_ENV'] === 'production') {
514- var dbPath = __dirname + '/../../user-specific-files/db/db.workspace';
515- dbOption.storage = dbPath;
516513
514+ /**
515+ * productionモード時は、db.workspaceを永続化させる
516+ * DEBUGモードの時は、db.debugを実行毎に作成する。
517+ * DEBUGモードの時は、sync()の中で、/レコードがFilesテーブルに追加される。
518+ * モードの切り替えは環境変数NODE_ENVで行っている。
519+ * zephyr serveコマンドが実行されるとNODE_ENV = 'production'
520+ * zephyr debugコマンドが実行されるとNODE_ENV = 'debug'
521+ * となる。
522+ * それぞれの設定は$ZEOHYR_HOME/cli/zephyr-serve, $ZEPHYR_HOME/zephyre_debugを参照
523+ */
524+
525+ var dbPath;
526+ if(process.env['NODE_ENV'] === 'production') {
527+ dbPath = __dirname + '/../../user-specific-files/db/db.workspace';
517528 // if doesn't exist workspace.db, create.
518529 try {
519530 fs.accessSync(dbPath, fs.R_OK | fs.W_OK);
520531 } catch(e) {
521532 fs.writeFileSync(dbPath, '');
522533 }
534+
535+ } else if(process.env['NODE_ENV'] === 'debug') {
536+ dbPath = __dirname + '/../../user-specific-files/db/db.debug';
537+ try {
538+ fs.accessSync(dbPath, fs.R_OK | fs.W_OK);
539+ fs.unlinkSync(dbPath);
540+ } catch(e) {
541+ }
542+
543+ fs.writeFileSync(dbPath, '');
523544 }
524545
546+
547+ dbOption.storage = dbPath;
548+
525549 sequelize = new Sequelize('','','', dbOption);
526550
527551 var Files = sequelize.define('file', {
Show on old repository browser