fs.readdirSync(CUSTOM_PLUGIN_PATH).forEach(function(name) { if (!name.indexOf('whistle.')) { newPath.push(path.join(CUSTOM_PLUGIN_PATH, name, 'node_modules/.bin')); } else if (name[0] === '@') { try { fs.readdirSync(path.join(CUSTOM_PLUGIN_PATH, name)).forEach(function(modName) { newPath.push(path.join(CUSTOM_PLUGIN_PATH, name, modName, 'node_modules/.bin')); }); } catch (e) {} } });
function getDataDir(dirname) { var dir = path.join(getWhistlePath(), dirname || '.' + config.name); fse.ensureDirSync(dir); return dir; }
function getSocketPath (socketPathSuffix) { /* istanbul ignore if */ /* only running tests on Linux; Window support is for local dev only */ if (/^win/.test(process.platform)) { const path = require('path') return path.join('\\\\?\\pipe', process.cwd(), `server-${socketPathSuffix}`) } else { return `/tmp/server-${socketPathSuffix}.sock` } }
fs.unlink(path.join(LOCAL_FILES, name), function(err) { var index = indexOfUploadFiles(name); if (index === -1 || !err || err.code === 'ENOENT') { if (index !== -1) { uploadFiles.splice(index, 1); } return callback(); } callback(err); });
function getAbsolutePath(pathToCheck, rootDir = process.cwd()) { if (!pathToCheck) { return rootDir; } return path.isAbsolute(pathToCheck) ? pathToCheck : path.join(rootDir, pathToCheck); }
process.on('uncaughtException', function(err){ if (!err || err.code !== 'ERR_IPC_CHANNEL_CLOSED') { var stack = util.getErrorStack(err); fs.writeFileSync(path.join(process.cwd(), config.name + '.log'), '\r\n' + stack + '\r\n', {flag: 'a'}); /*eslint no-console: "off"*/ console.error(stack); } process.exit(1); });
function cgiHandler(req, res) { try { if (req.headers.origin) { res.setHeader('Access-Control-Allow-Origin', req.headers.origin); res.setHeader('Access-Control-Allow-Credentials', true); } require(path.join(__dirname, '..' + req.path))(req, res); } catch(err) { res.status(500).send(config.debugMode ? '<pre>' + util.getErrorStack(err) + '</pre>' : 'Internal Server Error'); } }
function convertSlash(filePath) { if (LOCAL_FILE_PATH_RE.test(filePath)) { filePath = LOCAL_FILES + '/' + filePath.substring(RegExp.$1.length); } else if (HOME_DIR_RE.test(filePath)) { filePath = path.join(config.getHomedir(), '.' + filePath.substring(1)); } return isWin32 ? filePath : filePath.replace(RSLASH_RE, '/'); }
function readConfig(storage) { var dataDir = getDataDir(); var configFile = path.join(dataDir, encodeURIComponent('#' + (storage ? storage + '#' : ''))); if (!fs.existsSync(configFile)) { return; } try { return fse.readJsonSync(configFile); } catch(e) {} }
describe(`Typescript`, () => { describe(`build`, () => { it(`must build without error`, done => { exec(`tsc`, {cwd: path.join(`test`, `typescript`)}, error => { expect(error).toBe(null); done(); }); }); }); });
function loadService(callback) { fork({ script: path.join(__dirname, 'service.js'), debugMode: config.debugMode }, callback); }
test(`coverage is ignored if it's ${JSON.stringify(arg)}`, function (t) { t.plan(2) const cwd = tempy.directory() const nyc = path.join(cwd, '.nyc_output') cc.write(cwd, arg, function (err) { t.ifError(err) fs.readdir(nyc, function (err) { t.is(err.code, 'ENOENT') }) }) })
test('getSocketPath', () => { const socketPath = awsServerlessExpress.getSocketPath('12345abcdef') const isWin = process.platform === 'win32' const expectedSocketPath = isWin ? path.join('\\\\?\\\\pipe\\\\', process.cwd(), 'server-12345abcdef') : '/tmp/server-12345abcdef.sock' expect(socketPath).toBe(expectedSocketPath) })
function readReqRules(dir, callback) { fs.readFile(path.join(path.join(dir, '_rules.txt')), UTF8_OPTIONS, function(err, rulesText) { if (err) { fs.readFile(path.join(path.join(dir, 'reqRules.txt')), UTF8_OPTIONS, function(_, rulesText) { callback(util.trim(rulesText)); }); return; } callback(util.trim(rulesText)); }); }