const serverCb = () => { clearTimeout(customServerTimeout); if (startupLogging) { if (serverPath || serverCommand) { logger.info('custom server started, initializing watcher'); } else { let ifshow; // show ipv4 urls if (host === '0.0.0.0') { const os = require('os'); const ifaces = os.networkInterfaces(); Object.keys(ifaces).forEach(function (ifname) { let alias = 0; ifaces[ifname].forEach(function (iface) { if ('IPv4' === iface.family) { // && iface.internal == false) { ifshow = (alias > 0) ? `${ifname}:${alias}` : ifname; logger.info(`application started on http://${iface.address}:${port}/ (${ifshow})`); alias++; } }); }); } // ensure a url is always shown if (!ifshow) logger.info(`application started on http://${host}:${port}/`); } } callback(null, server); };
var write = function() { if (method === 'create' || method === 'overwrite') { logger.info("create " + path); fs.writeFile(path, data, callback); } else if (method === 'append') { logger.info("appending to " + path); fs.appendFile(path, data, callback); } };
fs.exists(path, function(exists) { if (exists && method !== 'overwrite' && method !== 'append') { logger.info("skipping " + path + " (already exists)"); if (callback != null) return callback(); } else { var parentDir = sysPath.dirname(path); var write = function() { if (method === 'create' || method === 'overwrite') { logger.info("create " + path); fs.writeFile(path, data, callback); } else if (method === 'append') { logger.info("appending to " + path); fs.appendFile(path, data, callback); } }; fs.exists(parentDir, function(exists) { if (exists) return write(); logger.info("init " + parentDir); // chmod 755. mkdirp(parentDir, 0x1ed, function(error) { if (error != null) return logger.error(error); write(); }); }); } });
ifaces[ifname].forEach(function (iface) { if ('IPv4' === iface.family) { // && iface.internal == false) { ifshow = (alias > 0) ? `${ifname}:${alias}` : ifname; logger.info(`application started on http://${iface.address}:${port}/ (${ifshow})`); alias++; } });
return helpers.asyncFilter(pkgs, isNotSymlink).then(unmetPkgs => { if (unmetPkgs.length > 0) { logger.info(`Using outdated versions of ${unmetPkgs.join(', ')}, trying to update to match package.json versions`); return application.install(rootPath, 'npm', isProduction).then(() => cfg, () => cfg); } return cfg; });
fs.writeFile(path, existingContents.replace(contents, ''), function(error) { if (error != null) { callback(error); return logger.error("" + error); } logger.info("editing contents of " + path); callback(); });
fs.unlink(path, function(error) { if (error != null) { callback(error); return logger.error("" + error); } logger.info("destroy " + path); callback(); });
fs.writeFile(outputPath, result.image, 'binary', function(err) { if (err) { logger.error('failed to write sprite sheet "' + outputPath + '" to disk'); return callback(err); } logger.info('generated sprite sheet "' + outputPath + '"'); callback(); });
const serverCb = () => { clearTimeout(customServerTimeout); const isCustom = serverPath || serverCommand; logger.info(isCustom ? 'custom server started, initializing watcher' : `application started on http://localhost:${port}/` ); callback(null, server); };
fs.exists(parentDir, function(exists) { if (exists) return write(); logger.info("init " + parentDir); // chmod 755. mkdirp(parentDir, 0x1ed, function(error) { if (error != null) return logger.error(error); write(); }); });
const reWatch = () => { logger.info('Reloading watcher...'); this.plugins.teardownBrunch(); const server = this.server; if (server && typeof server.close === 'function') { return server.close(restart); } return restart(); };
}).then(data => { const generatedFiles = data.changed; const disposed = data.disposed; fileList.emit('bundled'); logger.info(helpers.generateCompilationLog( startTime, fileList.assets, generatedFiles, disposed )); // Pass `fs_utils.GeneratedFile` instances to callbacks. // Does not block the execution. const assets = fileList.assets.filter(a => a.copyTime > startTime); callback(generatedFiles, assets); }, error => {
exports.install = (rootPath, command) => { const prevDir = process.cwd(); logger.info('Installing ' + command + ' packages...'); process.chdir(rootPath); return new Promise((resolve, reject) => { exec(command + ' install', (error, stdout, stderr) => { process.chdir(prevDir); if (error) { const log = stderr.toString(); logger.error(log); return reject(log); } resolve(stdout); }); }); };
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); if ('OPTIONS' == req.method) { res.send(200); } else { next(); } }; app.use('/static', express.static(__dirname + '/public')); app.use(express.logger()); app.use(express.methodOverride()); app.use(allowCrossDomain); logger.info('application started on http://localhost:3000/'); //http://visionmedia.github.io/superagent/ app.get('/api/movies', function (req, res) { var query = req.query || {}; query.apikey = apikey; if (query.q) { request.get('http://api.rottentomatoes.com/api/public/v1.0/movies.json') .query(query).end(function (err, result) { res.send(200, JSON.parse(result.text)); }); } else if (query.type === 'upcoming') { request.get('http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json') .query(query).end(function (err, result) {
const launch = (options, callback) => { if (!callback) callback = Function.prototype; const port = parseInt(options.port, 10); const host = options.hostname || 'localhost'; const serverCommand = options.command; const serverPath = options.path; const publicPath = options.publicPath; const startupLogging = options.startupLogging == null ? true : options.startupLogging; let customServerTimeout; let server; const serverCb = () => { clearTimeout(customServerTimeout); if (startupLogging) { if (serverPath || serverCommand) { logger.info('custom server started, initializing watcher'); } else { let ifshow; // show ipv4 urls if (host === '0.0.0.0') { const os = require('os'); const ifaces = os.networkInterfaces(); Object.keys(ifaces).forEach(function (ifname) { let alias = 0; ifaces[ifname].forEach(function (iface) { if ('IPv4' === iface.family) { // && iface.internal == false) { ifshow = (alias > 0) ? `${ifname}:${alias}` : ifname; logger.info(`application started on http://${iface.address}:${port}/ (${ifshow})`); alias++; } }); }); } // ensure a url is always shown if (!ifshow) logger.info(`application started on http://${host}:${port}/`); } } callback(null, server); }; if (serverPath) { if (startupLogging) logger.info('starting custom server'); try { server = require(sysPath.resolve(serverPath)); } catch (error) { logger.error(`couldn't load server ${serverPath}: ${error}`); } const serverFn = (() => { if (typeof server === 'function') { return server; } else if (server && typeof server.startServer === 'function') { return server.startServer.bind(server); } else { throw new Error('Brunch server file needs to export server function'); } })(); const opts = {port: port, hostname: host, path: publicPath}; const serverConfig = Object.assign(opts, options.config || {}); debug(`Invoking custom startServer with: ${JSON.stringify(serverConfig)}`); customServerTimeout = setTimeout(() => { if (startupLogging) logger.warn('custom server taking a long time to start'); if (startupLogging) logger.warn("**don\'t forget to invoke callback()**"); }, longCallbackTime); switch (serverFn.length) { case 1: return serverFn(serverCb); case 2: return serverFn(serverConfig, serverCb); default: return serverFn(port, publicPath, serverCb); } } else if (serverCommand) { const commandComponents = serverCommand.split(' '); debug(`Invoking custom server command with: ${serverCommand}`); if (!commandComponents.length) { throw new Error('Invalid custom server command'); } /* fn to kill the custom server */ const child = spawn(commandComponents.shift(), commandComponents, { stdio: 'inherit' }); child.close = cb => { child.kill(); return typeof cb === 'function' ? cb() : undefined; }; setImmediate(serverCb); return child; } else { const opts = {noLog: true, path: publicPath}; return pushserve(Object.assign(opts, options), serverCb); } };
const startServer = (config, callback) => { if (callback == null) callback = Function.prototype; const serverOpts = config.server || {}; const port = parseInt(serverOpts.port, 10); const serverCommand = serverOpts.command; const serverPath = serverOpts.path; const publicPath = config.paths.public; let customServerTimeout; let server; const serverCb = () => { clearTimeout(customServerTimeout); const isCustom = serverPath || serverCommand; logger.info(isCustom ? 'custom server started, initializing watcher' : `application started on http://localhost:${port}/` ); callback(null, server); }; if (serverPath) { logger.info('starting custom server'); try { server = require(sysPath.resolve(serverPath)); } catch (error) { logger.error(`couldn't load server ${serverPath}: ${error}`); } const serverFn = (() => { if (typeof server === 'function') { return server; } else if (server && typeof server.startServer === 'function') { return server.startServer.bind(server); } else { throw new Error('Brunch server file needs to export server function'); } })(); const opts = {port: port, path: publicPath}; const serverConfig = Object.assign(opts, serverOpts.config || {}); debug(`Invoking custom startServer with: ${JSON.stringify(serverConfig)}`); customServerTimeout = setTimeout(() => { logger.warn('custom server taking a long time to start'); return logger.warn('**don\'t forget to invoke callback()**'); }, longCallbackTime); switch (serverFn.length) { case 1: return serverFn(serverCb); case 2: return serverFn(serverConfig, serverCb); default: return serverFn(port, publicPath, serverCb); } } else if (serverCommand) { const commandComponents = serverCommand.split(' '); debug(`Invoking custom server command with: ${serverCommand}`); if (!commandComponents.length) { throw new Error('Invalid custom server command'); } /* fn to kill the custom server */ const child = spawn(commandComponents.shift(), commandComponents, { stdio: 'inherit' }); child.close = cb => { child.kill(); return typeof cb === 'function' ? cb() : undefined; }; serverCb(); return child; } else { const opts = {noLog: true, path: publicPath}; return pushserve(Object.assign(opts, serverOpts), serverCb); } };
return helpers.asyncFilter(pkgs, isNotSymlink).then(unmetPkgs => { if (!unmetPkgs.length) return; logger.info(`Using outdated versions of ${unmetPkgs.join(', ')}, trying to update to match package.json versions`); return application.install(packageDir, 'npm', isProduction); });
exitProcessFromFile(reasonFile) { logger.info(`Detected removal of ${reasonFile}\nExiting.`); process.exit(0); }