From a7931c0105477219c9acb809b7e914eb085d4b23 Mon Sep 17 00:00:00 2001 From: Yaw Joseph Etse Date: Tue, 25 Nov 2014 14:01:42 -0500 Subject: [PATCH] bumped node requirement, requires forever, environment specific extension --- README.md | 5 ++++- app/lib/config.js | 29 ++++++++++++++++++++++--- app/routes/index.js | 8 ++++++- content/config/environment/default.json | 1 + package.json | 11 +++++----- releases/3.1.2.md | 28 ++++++++++++++++-------- scripts/deploymentsync.js | 4 ---- 7 files changed, 62 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 5aadf7d1..96e33694 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,10 @@ Applications built with Periodic range from simple blogs, complicated enterprise ### Quick start guide ``` -$ npm start --e [name-of-environment (development by default)] +$ npm start --e [name-of-environment (development by default)] # runs nodemon +$ npm run forever --e [name-of-environment (development by default)] # runs forever + nodemon +$ npm run deploy --e [name-of-environment (development by default)] # deploys with pm2 +$ npm run sync # syncs dependencies ``` | [![Install home](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/install-start-screen.png)](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/install-start-screen.png) | [![Admin home](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-content-dropdown.png)](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-content-dropdown.png) | [![New Item](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-item-new-2.png)](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-item-new-2.png) | [![review revision](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-review-revisions-collection.png)](https://raw.githubusercontent.com/typesettin/wiki-resources/master/images/periodic/admin-review-revisions-collection.png) | diff --git a/app/lib/config.js b/app/lib/config.js index dec8d033..9328d5d6 100644 --- a/app/lib/config.js +++ b/app/lib/config.js @@ -34,6 +34,8 @@ var config = function () { configurationFileJSON, configurationOverrideFileJSON, configurationDefaultFileJSON, + lastRuntimeEnvironment, + lastRuntimeEnvironmentFilePath = path.resolve(process.cwd(), 'content/config/process/runtime.json'), config = {}; /** @@ -83,6 +85,10 @@ var config = function () { this.init = function () { /** get info from package.json */ packagejsonFileJSON = fs.readJSONSync(path.resolve(process.cwd(), './package.json')); + /** get info from last runtime environemnt */ + if(fs.existsSync(lastRuntimeEnvironmentFilePath)){ + lastRuntimeEnvironment = fs.readJSONSync(lastRuntimeEnvironmentFilePath).environment; + } /** load user config file: content/config/config.json */ configurationOverrideFileJSON = fs.readJSONSync(configurationOverrideFile); @@ -95,12 +101,29 @@ var config = function () { if (process.env.NODE_ENV) { appEnvironment = process.env.NODE_ENV; } + else if(argv.e){ + appEnvironment = argv.e; + } + else if(lastRuntimeEnvironment){ + appEnvironment = lastRuntimeEnvironment; + } + else if(typeof configurationOverrideFileJSON.application !== 'undefined' && typeof configurationOverrideFileJSON.application.environment !== 'undefined'){ + appEnvironment = configurationOverrideFileJSON.application.environment; + } else { - appEnvironment = (argv.e) ? - argv.e : (typeof configurationOverrideFileJSON.application !== 'undefined' && typeof configurationOverrideFileJSON.application.environment !== 'undefined') ? - configurationOverrideFileJSON.application.environment : 'development'; + appEnvironment = 'development'; } + //** save last runtime environment to load as a backup */ + fs.outputJson(path.resolve(process.cwd(),'content/config/process/runtime.json'),{environment:appEnvironment},function(err){ + if(err){ + console.error(err); + } + else{ + console.log('saved runtime environment',appEnvironment); + } + }); + /** set & load file path for base environment config */ configurationFile = this.getConfigFilePath(appEnvironment); diff --git a/app/routes/index.js b/app/routes/index.js index dd1d080b..8814342e 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -36,7 +36,13 @@ module.exports = function (periodic) { var homeController = require('../controller/home')(periodic), appRouter = periodic.express.Router(), ignoreExtensionIndex, - ExtensionCore = new Extensions(periodic.settings); + ExtensionCore; + + if(periodic.settings.use_test_extensions_by_environment){ + periodic.settings.extensionFilePath = path.resolve(process.cwd(), 'content/config/process/'+periodic.settings.application.environment+'.extensions.json'); + } + ExtensionCore = new Extensions(periodic.settings); + /** load extensions */ periodic.settings.extconf = ExtensionCore.settings(); diff --git a/content/config/environment/default.json b/content/config/environment/default.json index 19ca9589..efca1b70 100644 --- a/content/config/environment/default.json +++ b/content/config/environment/default.json @@ -17,6 +17,7 @@ }, "session_secret":"hjoiuu87go9hui", "expressCompression": true, + "use_test_extensions_by_environment": false, "templateengine": "ejs", "templatepackage": "ejs", "templatefileextension": "ejs", diff --git a/package.json b/package.json index c3493588..89686ec0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "periodicjs", "description": "Periodic is an application framework built on top of Express and MongoDB designed for data driven, content based web and mobile applications.", - "version": "3.1.1", + "version": "3.1.2", "main": "index.js", "engines": { "node": ">=0.10.31" @@ -33,15 +33,14 @@ "url": "git://github.com/typesettin/periodicjs.git" }, "scripts": { - "nd": "NODE_ENV=development nodemon --watch app --watch content/config/restart.json --watch content/config/database.js index.js ", "start": "node index.js --cli --nd --e", - "stop": "pm2 delete periodicjs", + "forever": "forever start -o logs/app-out.forever.log -e logs/app-err.forever.log -c nodemon index.js --e", + "stop": "forever stop -c nodemon index.js", + "deploy": "node index.js --cli --deploy", "test": "mocha -R spec --recursive", "coverage": "mocha -R html-cov --recursive > test/coverage.html", "postinstall": "node scripts/install.js", - "deploysync": "node scripts/deploymentsync.js", - "deploy_dev": "node index.js --cli --deploy dev", - "deploy_prod": "node index.js --cli --deploy production" + "sync": "node scripts/deploymentsync.js" }, "dependencies": { "async": "0.9.0", diff --git a/releases/3.1.2.md b/releases/3.1.2.md index d9db528a..90855236 100644 --- a/releases/3.1.2.md +++ b/releases/3.1.2.md @@ -5,14 +5,24 @@ * moving extension config to `content/config/extensions.json` * moved restart.json to `content/config` * added enterprise data security requirements for dbseed, custom data scrubbing -* requires node >= 0.10.31, npm >= 2.0.0 +* added support for environemnt specific extensions for testing +* **requires node >= 0.10.31, npm >= 2.0.0** ### Notes -* Periodic Migration guide from 3.0.0 - ``` - # move content/extensions/extensions.json, content/extensions/log, content/extensions/restart.json to content/config - # delete content/extensions directory - # install latest version of periodic - $ cd /path/to/web/app - $ npm install periodicjs@3.1.1 --prefix ./ # or $ npm install periodicjs@latest - ``` +#### Periodic Migration guide from 3.0.0 +``` +# move content/extensions/extensions.json, content/extensions/log, content/extensions/restart.json to content/config +# delete content/extensions directory +# install latest version of periodic +$ npm install forever -g # install forever +$ cd /path/to/web/app +$ npm install periodicjs@3.1.2 --prefix ./ # or $ npm install periodicjs@latest +``` +#### Periodic Runtime Options +``` +$ npm start --e [name-of-environment (development by default)] # runs nodemon +$ npm run forever --e [name-of-environment (development by default)] # runs forever + nodemon +$ npm run deploy --e [name-of-environment (development by default)] # deploys with pm2 +$ npm run sync # syncs dependencies +``` +Running npm start saves the environment in `content/config/process/runtime.json`, if no environment is specified, it will reload in this environment, this is helpful server restarts \ No newline at end of file diff --git a/scripts/deploymentsync.js b/scripts/deploymentsync.js index 57ea3ad3..4f41a8f4 100644 --- a/scripts/deploymentsync.js +++ b/scripts/deploymentsync.js @@ -27,9 +27,5 @@ async.waterfall([ else{ console.log('deployment sync result',result); CoreUtilities.restart_app({}); - CoreUtilities.run_cmd( 'pm2', ['restart','periodicjs'], function(text) { - console.log (text); - process.exit(0); - }); } });