.editorconfig000066400000000000000000000006371517023264500135460ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] # Change these settings to your own preference indent_style = space indent_size = 4 # We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false .gitignore000066400000000000000000000004521517023264500130540ustar00rootroot00000000000000node_modules npm-debug.log tmp *.sublime-project *.sublime-workspace /build /dist /node_modules /*.log /*.iws .idea/workspace.xml .idea/tasks.xml .idea/profiles_settings.xml .idea/inspectionProfiles/Project_Default.xml .idea/inspectionProfiles/profiles_settings.xml node_modules/.yarn-integrity .idea/000077500000000000000000000000001517023264500120435ustar00rootroot00000000000000.idea/codeStyleSettings.xml000066400000000000000000000004251517023264500162420ustar00rootroot00000000000000 .idea/grunt-express.iml000066400000000000000000000005201517023264500153710ustar00rootroot00000000000000 .idea/inspectionProfiles/000077500000000000000000000000001517023264500157225ustar00rootroot00000000000000.idea/inspectionProfiles/Project_Default.xml000066400000000000000000000003711517023264500215170ustar00rootroot00000000000000 .idea/misc.xml000066400000000000000000000015161517023264500135230ustar00rootroot00000000000000 true false true .idea/modules.xml000066400000000000000000000004261517023264500142370ustar00rootroot00000000000000 .idea/vcs.xml000066400000000000000000000002471517023264500133630ustar00rootroot00000000000000 .travis.yml000066400000000000000000000014571517023264500132030ustar00rootroot00000000000000language: node_js cache: npm: false node_js: - lts/* before_script: - npm install -g grunt-cli npm env: global: secure: FLrKJOim23L8cv/zGma2s+9TvhZscbJD4TvRzwcBtIUro31rylAmalZrLCJg0GiLhW8qTjyP/8JXJnWqYq9AZxql3Zj7ZogymfS1QWy1eDAb6LTMQShdHWlXKc9q1TiatxaTMQhYy84sk88LaVR79cViSrYt0GLx2x4iVexqqD0jiEGJe31eiYBfNhBbOCklqft1OFkJVlo6xA3p4MAs/KQEvXHP0mwMkT3ngiXpJM1zsd7eQCaLcIDwCJsMo38cMDLeQvWjP0q2uoKO4IZdhulk6YORoJ7GBf8oJln78B3mBN1cjReZdqtMD3HxRmVOSToSZFAF14DcEDmZfMDp4nG50je96eUHqxvMJ5K2jCVMd++FEy1q9VwpWkW9VnilwVCj/Yi699+Bq0QESSXzWz8wF9suTN3bWMPRac38mjf3SB2Yhi+0E/b75FsE8uCYCWTWMGy5fgqa11GmB27ABvM4SdpAGn9PnSq/d6urCYuut1r3+pDXcZqJ13pOgCm47VgDt09pRyvGYFUGzEMk9NGctuXI5HGoY5BsyR0YXh8ZFFF+W654b0r3LiBG7UfQvRY03d3Cr1sR//QmoMBtl55TdyGwB+r2A13bQaj/VQtsOgymoP16J8PzON7cexVYbW9xGbsEdF9DWQ5hx8NxLJOK68Idm860MCKMPrZBUyE= Gruntfile.js000066400000000000000000000004551517023264500133640ustar00rootroot00000000000000module.exports = (grunt) => { const builder = require(`corifeus-builder`); const loader = new builder.loader(grunt); loader.js({ replacer: { type: 'p3x', npmio: true, }, }); grunt.registerTask('default', builder.config.task.build.js); }; LICENSE000066400000000000000000000023431517023264500120720ustar00rootroot00000000000000 @license grunt-p3x-express v2020.4.159 🚧 Grunt Express Server updated with additional options https://corifeus.com/grunt-p3x-express Copyright (c) 2020 Patrik Laszlo / P3X / Corifeus and contributors. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. README.md000066400000000000000000000207111517023264500123430ustar00rootroot00000000000000[//]: #@corifeus-header [![NPM](https://nodei.co/npm/grunt-p3x-express.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/grunt-p3x-express/) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://paypal.me/patrikx3) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Corifeus @ Facebook](https://img.shields.io/badge/Facebook-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) [![Build Status](https://api.travis-ci.com/patrikx3/grunt-p3x-express.svg?branch=master)](https://travis-ci.com/patrikx3/grunt-p3x-express) [![Uptime Robot ratio (30 days)](https://img.shields.io/uptimerobot/ratio/m780749701-41bcade28c1ea8154eda7cca.svg)](https://uptimerobot.patrikx3.com/) # 🚧 Grunt Express Server updated with additional options v2020.4.159 **Bugs are evident™ - MATRIX️** ### NodeJs LTS Version Requirement ```txt >=12.13.0 ``` ### Built on NodeJs ```txt v12.16.3 ``` The ```async``` and ```await``` keywords are required. Only the latest LTS variant is supported. Install NodeJs: https://nodejs.org/en/download/package-manager/ # Description [//]: #@corifeus-header:end Simple grunt task for running an Express server that works great with LiveReload + Watch/Regarde. It works with the latest Node and some additional options. ## Changelog [readme](artifacts/readme/changelog.md) ## Getting Started This plugin requires Grunt `>=1.0.0` If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```bash npm install grunt-p3x-express --save-dev ``` Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js grunt.loadNpmTasks('grunt-p3x-express'); ``` ## The `express` task ### Setup In your project's Gruntfile, you can create one or multiple servers: ```js grunt.initConfig({ express: { options: { // Override defaults here }, dev: { options: { script: 'path/to/dev/server.js' } }, prod: { options: { script: 'path/to/prod/server.js', node_env: 'production', env: { 'NODE_MODE': 'cluster' } } }, test: { options: { script: 'path/to/test/server.js' } } } }); ``` You can override the default `options` either in the root of the `express` config or within each individual server task. ### Default `options` ```js express: { options: { // Override the command used to start the server. // (do not use 'coffee' here, the server will not be able to restart // see below at opts for coffee-script support) cmd: process.argv[0], // Will turn into: `node OPT1 OPT2 ... OPTN path/to/server.js ARG1 ARG2 ... ARGN` // (e.g. opts: ['node_modules/coffee-script/bin/coffee'] will correctly parse coffee-script) opts: [ ], args: [ ], // Setting to `false` will effectively just run `node path/to/server.js` background: true, // Called when the spawned server throws errors fallback: function() {}, // Override node env's PORT port: 3000, // Override node env's NODE_ENV node_env: undefined, // Merge the process environment of this option env: {}, // Enable Node's --harmony flag harmony: false, // Consider the server to be "running" after an explicit delay (in milliseconds) // (e.g. when server has no initial output) delay: 0, // Regular expression that matches server output to indicate it is "running" output: ".+", // Set --debug or --inspect (it checks the nodejs version) (true | false | integer from 1024 to 65535, has precedence over breakOnFirstLine) debug: false, // Set --debug-brk or --inspect-brk (it checks the nodejs version) (true | false | integer from 1024 to 65535) breakOnFirstLine: false, // Object with properties `out` and `err` both will take a path to a log file and // append the output of the server. Make sure the folders exist. logs: undefined } } ``` ### Usage By default, unless `delay` or `output` has been customized, **the server is considered "running" once any output is logged to the console**, upon which control is passed back to grunt. Typically, this is: > Express server listening on port 3000 If your server doesn't log anything, the express task will never finish and **none** of the following tasks, after it, will be executed. For example - if you have a development task like this one: ```js grunt.registerTask('rebuild', ['clean', 'browserify:scripts', 'stylus', 'copy:images']); grunt.registerTask('dev', ['rebuild', 'express', 'watch']); ``` If you run the dev task and your server doesn't log anything, **'watch' will never be started**. This can easily be avoided, if you log something, when server is created like that: ```js var server = http.createServer( app ).listen( PORT, function() { console.log('Express server listening on port ' + PORT); } ); ``` If you log output *before* the server is running, either set `delay` or `output` to indicate when the server has officially started. #### Starting the server If you have a server defined named `dev`, you can start the server by running `express:dev`. The server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. #### Stopping the server Similarly, if you start the `dev` server with `express:dev`, you can stop the server with `express:dev:stop`. #### With [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) ```js grunt.initConfig({ watch: { express: { files: [ '**/*.js' ], tasks: [ 'express:dev' ], options: { spawn: false // for grunt-contrib-watch v0.5.0+, "nospawn: true" for lower versions. Without this option specified express won't be reloaded } } } }); grunt.registerTask('server', [ 'express:dev', 'watch' ]) ``` **Important:** Note that the `spawn: false` options only need be applied to the watch target regarding the express task. You may have other watch targets that use `spawn: true`, which is useful, for example, to reload CSS and not LESS changes. ```js watch: { options: { livereload: true }, express: { files: [ '**/*.js' ], tasks: [ 'express:dev' ], options: { spawn: false, env: { 'NODE_MODE': 'cluster' } } }, less: { files: ["public/**/*.less"], tasks: ["less"], options: { livereload: false } }, public: { files: ["public/**/*.css", "public/**/*.js"] } } ``` ## Release History ### Old version https://github.com/ericclemmons/grunt-express-server [//]: #@corifeus-footer --- 🙏 This is an open-source project. Star this repository, if you like it, or even donate to maintain the servers and the development. Thank you so much! Possible, this server, rarely, is down, please, hang on for 15-30 minutes and the server will be back up. All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://corifeus.com)) could have minor errors, since I am developing in my free time. However, it is usually stable. **Note about versioning:** Versions are cut in Major.Minor.Patch schema. Major is always the current year. Minor is either 4 (January - June) or 10 (July - December). Patch is incremental by every build. If there is a breaking change, it should be noted in the readme. --- [**GRUNT-P3X-EXPRESS**](https://corifeus.com/grunt-p3x-express) Build v2020.4.159 [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) ## P3X Sponsor [IntelliJ - The most intelligent Java IDE](https://www.jetbrains.com/?from=patrikx3) [![JetBrains](https://cdn.corifeus.com/assets/svg/jetbrains-logo.svg)](https://www.jetbrains.com/?from=patrikx3) [//]: #@corifeus-footer:end artifacts/000077500000000000000000000000001517023264500130435ustar00rootroot00000000000000artifacts/readme/000077500000000000000000000000001517023264500143005ustar00rootroot00000000000000artifacts/readme/changelog.md000066400000000000000000000032471517023264500165570ustar00rootroot00000000000000[//]: #@corifeus-header # 🚧 Grunt Express Server updated with additional options [//]: #@corifeus-header:end ### v1.1.199-248 * the task uses colors now [//]: #@corifeus-footer --- 🙏 This is an open-source project. Star this repository, if you like it, or even donate to maintain the servers and the development. Thank you so much! Possible, this server, rarely, is down, please, hang on for 15-30 minutes and the server will be back up. All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://corifeus.com)) could have minor errors, since I am developing in my free time. However, it is usually stable. **Note about versioning:** Versions are cut in Major.Minor.Patch schema. Major is always the current year. Minor is either 4 (January - June) or 10 (July - December). Patch is incremental by every build. If there is a breaking change, it should be noted in the readme. --- [**GRUNT-P3X-EXPRESS**](https://corifeus.com/grunt-p3x-express) Build v2020.4.159 [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) ## P3X Sponsor [IntelliJ - The most intelligent Java IDE](https://www.jetbrains.com/?from=patrikx3) [![JetBrains](https://cdn.corifeus.com/assets/svg/jetbrains-logo.svg)](https://www.jetbrains.com/?from=patrikx3) [//]: #@corifeus-footer:end grunt-express.iml000066400000000000000000000005171517023264500144170ustar00rootroot00000000000000 grunt-p3x-express.iml000066400000000000000000000006021517023264500151220ustar00rootroot00000000000000 package.json000066400000000000000000000027141517023264500133550ustar00rootroot00000000000000{ "name": "grunt-p3x-express", "corifeus": { "publish": true, "type": "p3x", "code": "Next", "nodejs": "v12.16.3", "opencollective": false, "reponame": "grunt-p3x-express", "build": true }, "description": "🚧 Grunt Express Server updated with additional options", "version": "2020.4.159", "homepage": "https://corifeus.com/grunt-p3x-express", "author": { "name": "Eric Clemmons", "email": "eric@smarterspam.com" }, "contributors": [ { "name": "Patrik Laszlo", "email": "alabard@gmail.com" } ], "repository": { "type": "git", "url": "git://github.com/patrikx3/grunt-express.git" }, "bugs": { "url": "https://github.com/patrikx3/grunt-express/issues" }, "license": "MIT", "main": "Gruntfile.js", "engines": { "node": ">=12.13.0" }, "scripts": { "test": "./node_modules/.bin/grunt" }, "devDependencies": { "corifeus-builder": "^2020.4.205", "express": "^4.17.1", "grunt": "^1.1.0", "grunt-cli": "^1.3.2", "grunt-contrib-clean": "^2.0.0", "grunt-contrib-jshint": "^2.1.0", "grunt-contrib-nodeunit": "^2.1.0", "grunt-contrib-watch": "^1.1.0", "lodash": "^4.17.15" }, "keywords": [ "gruntplugin", "express", "server" ], "dependencies": {} }src/000077500000000000000000000000001517023264500116525ustar00rootroot00000000000000src/express.js000066400000000000000000000030151517023264500137000ustar00rootroot00000000000000/* * grunt-p3x-express * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Copyright (c) 2017 Patrik Laszlo * Licensed under the MIT license. */ const path = require('path'); module.exports = function (grunt) { const servers = {}; grunt.registerMultiTask('express', 'Start an express web server', function () { if (!servers[this.target]) { servers[this.target] = require('./lib/server')(grunt, this.target); } const server = servers[this.target]; const action = this.args.shift() || 'start'; const options = this.options({ cmd: process.argv[0], opts: [], args: [], node_env: undefined, harmony: false, background: true, fallback: function () { /* Prevent EADDRINUSE from breaking Grunt */ }, port: process.env.PORT || 3000, delay: 0, output: ".+", debug: false, breakOnFirstLine: false, logs: undefined, hardStop: false }); if (options.harmony) { options.args.unshift('--harmony'); } options.script = path.resolve(options.script); options.args.unshift(options.script); if (!grunt.file.exists(options.script)) { grunt.log.error('Could not find server script: ' + options.script); return false; } server[action](options); }); }; src/index.js000066400000000000000000000001601517023264500133140ustar00rootroot00000000000000module.exports = { express: require('./express'), } module.exports.express.server = require('./lib/server');src/lib/000077500000000000000000000000001517023264500124205ustar00rootroot00000000000000src/lib/server.js000066400000000000000000000147071517023264500142750ustar00rootroot00000000000000/* * grunt-p3x-express * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Copyright (c) 2017 Patrik Laszlo * Licensed under the MIT license. */ 'use strict'; const spawn = require('child_process').spawn; const process = require('process'); const path = require('path'); const _ = require('lodash'); module.exports = function (grunt, target) { if (!process._servers) { process._servers = {}; } let backup = null; let done = null; let server = process._servers[target]; // Store server between live reloads to close/restart express let finished = function () { if (done) { done(); done = null; } }; return { start: function start(options) { if (server) { this.stop(options); if (grunt.task.current.flags.stop) { finished(); return; } } backup = JSON.parse(JSON.stringify(process.env)); // Clone process.env // For some weird reason, on Windows the process.env stringify produces a "Path" // member instead of a "PATH" member, and grunt chokes when it can't find PATH. if (!backup.PATH) { if (backup.Path) { backup.PATH = backup.Path; delete backup.Path; } } grunt.log.writeln('Starting '.cyan + (options.background ? 'background' : 'foreground') + ' Express server'); done = grunt.task.current.async(); // Set PORT for new processes process.env.PORT = options.port; // Set NODE_ENV for new processes if (options.node_env) { process.env.NODE_ENV = options.node_env; } if (options.env) { process.env = _.merge(process.env, options.env) } if (options.cmd === 'coffee') { grunt.log.writeln('You are using cmd: coffee'.red); grunt.log.writeln('coffee does not allow a restart of the server'.red); grunt.log.writeln('use opts: ["path/to/your/coffee"] instead'.red); } // Set debug mode for node-inspector // Based on https://github.com/joyent/node/blob/master/src/node.cc#L2903 let debugFlag = 'debug'; if (parseInt(process.versions.node.split('.')[0]) > 7) { debugFlag = 'inspect'; } if (options.debug === true) { options.opts.unshift('--' + debugFlag); } else if (!isNaN(parseInt(options.debug, 10))) { options.opts.unshift('--' + debugFlag + '=' + options.debug); } else if (options.breakOnFirstLine === true) { options.opts.unshift('--' + debugFlag + '-brk'); } else if (!isNaN(parseInt(options.breakOnFirstLine, 10))) { options.opts.unshift('--' + debugFlag + '-brk=' + options.breakOnFirstLine); } if ((options.debug || options.breakOnFirstLine) && options.cmd === 'coffee') { options.opts.unshift('--nodejs'); } if (options.background) { let errtype = process.stderr; let spawnOptions = { env: _.merge(process.env, { FORCE_COLOR: true }), stdio: ['inherit'], // shell: true, customFds: [0, 1, 2] }; if (options.logs && options.logs.err) { errtype = 'pipe'; spawnOptions = { env: process.env, stdio: ['ignore', 'pipe', errtype] } } const args = options.opts.concat(options.args); // console.log(process.argv0) // console.log(args) // console.log(spawnOptions) // process.exit() server = process._servers[target] = spawn(process.argv0, args, spawnOptions); if (options.debug !== undefined && options.debug !== false) { //server } if (options.delay) { setTimeout(finished, options.delay); } if (options.output) { server.stdout.on('data', function (data) { let message = "" + data; let regex = new RegExp(options.output, "gi"); if (message.match(regex)) { finished(); } }); server.stderr.on('data', function (data) { console.error(data.toString()); }); } let out = process.stdout; if (options.logs) { const fs = require('fs'); if (options.logs.out) { out = fs.createWriteStream(path.resolve(options.logs.out), {flags: 'a'}); } if (options.logs.err && errtype === 'pipe') { server.stderr.pipe(fs.createWriteStream(path.resolve(options.logs.err), {flags: 'a'})); } } server.stdout.pipe(out); server.on('close', this.stop); } else { // Server is ran in current process server = process._servers[target] = require(options.script); } process.on('exit', this.stop); }, stop: function stop(options) { if (server && server.kill) { grunt.log.writeln('Stopping'.red + ' Express server'); server.removeAllListeners('close'); if (options.hardStop) { grunt.log.writeln('Using ' + 'SIGKILL'.red); server.kill('SIGKILL'); } else { server.kill('SIGTERM'); } process.removeListener('exit', finished); process.removeListener('exit', stop); server = process._servers[target] = null; } // Restore original process.env if (backup) { process.env = JSON.parse(JSON.stringify(backup)); } finished(); } }; }; tasks/000077500000000000000000000000001517023264500122105ustar00rootroot00000000000000tasks/express.js000066400000000000000000000000531517023264500142350ustar00rootroot00000000000000module.exports = require('../src/express');