Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import "tslib";
import * as moduleAlias from "module-alias";
import * as path from "path";
const tnsCoreModules = path.resolve(__dirname, "..", "nativescript-core");
moduleAlias.addPath(tnsCoreModules);
moduleAlias.addAliases({
// NOTE: require("@nativescript/core/platform") with these aliases will work in node but fail in Angular AoT
"@nativescript/core/platform": path.resolve(__dirname, "polyfills", "platform"),
"@nativescript/core/file-system/file-system-access": path.resolve(__dirname, "polyfills", "file-system-access"),
"@nativescript/core/utils/utils": path.resolve(tnsCoreModules, "utils/utils-common"),
"./mainthread-helper": path.resolve(__dirname, "polyfills", "mainthread-helper"),
"@nativescript/core/color": path.resolve(tnsCoreModules, "color/color-common"),
"@nativescript/core/ui/styling/font": path.resolve(tnsCoreModules, "ui/styling/font-common"),
"@nativescript/core/ui/styling/background": path.resolve(tnsCoreModules, "ui/styling/background-common"),
"@nativescript/core": tnsCoreModules,
"~": __dirname
});
const chai = require('chai');
const chaiHttp = require('chai-http');
const sinon = require('sinon');
var path = require('path');
// manager startup mocks
require('module-alias/register');
require('module-alias').addPath('.');
// For mocking all dates established at manager boot time. Specifically lastImagePulled in logic/application.js.
// Clock mock must be before applicationStartup mock.
global.clock = sinon.useFakeTimers({
now: 1546329600000, // January 1, 2019 Midnight PST
shouldAdvanceTime: false,
});
global.uuidSerialId = sinon.stub(require('../utils/UUID.js'), 'fetchSerial')
.resolves('fake_serial_id');
global.applicationStartup = sinon.stub(require('../logic/application.js'), 'startup')
.resolves({});
global.uuidBootId = sinon.stub(require('../utils/UUID.js'), 'fetchBootUUID')
.returns('fake_boot_id');
global.appRoot = path.resolve(__dirname);
;(() => {
if (SETUP_DONE) return
// Let's save us from the work ASAP
const [, ...mhyIfStr] = (process.argv.find(a => a.startsWith('--mhy-if')) || '').split('=')
if (mhyIfStr.length && !eval(mhyIfStr.join('='))) {
console.info(`Skipping command due to falsy expression: ${mhyIfStr.join('=')}`)
process.exit(0)
}
// Register dist with alias and mhy's node_modules as module source so custom JS files can use it loaded through mhy
addAlias('@/mhy', path.resolve(__dirname, '../'))
addPath(path.resolve(__dirname, '../../node_modules'))
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
process.env.MHY_ENV = 'cli'
process.env.MHY_ENVS = [process.env.NODE_ENV]
process.env.MHY_LOCAL_DIR = '.mhy'
const envsMap = {
prod: 'production',
dev: 'development'
}
const [, mhyEnvsStr = ''] = (process.argv.find(a => a.startsWith('--mhy-env')) || '').split('=')
const mhyEnvsList = mhyEnvsStr.split(':').filter(a => a)
if (mhyEnvsList.length) {
const NODE_ENV = (mhyEnvsList[0] = envsMap[mhyEnvsList[0]] || mhyEnvsList[0])
process.env.MHY_ENVS = mhyEnvsList
process.env.NODE_ENV = NODE_ENV
require('module-alias/register');
require('module-alias').addPath('.');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const passport = require('passport');
const cors = require('cors');
// Keep requestCorrelationId middleware as the first middleware. Otherwise we risk losing logs.
const requestCorrelationMiddleware = require('middlewares/requestCorrelationId.js'); // eslint-disable-line id-length
const errorHandleMiddleware = require('middlewares/errorHandling.js');
const onionOriginMiddleware = require('middlewares/onionOrigin.js');
const corsOptions = require('middlewares/cors.js').corsOptions;
require('middlewares/auth.js');
const logger = require('utils/logger.js');
const applicationLogic = require('logic/application.js');
require('module-alias/register');
require('module-alias').addPath('.');
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');
// Keep requestCorrelationId middleware as the first middleware. Otherwise we risk losing logs.
const requestCorrelationMiddleware = require('middlewares/requestCorrelationId.js'); // eslint-disable-line id-length
const camelCaseReqMiddleware = require('middlewares/camelCaseRequest.js').camelCaseRequest;
const onionOriginMiddleware = require('middlewares/onionOrigin.js');
const corsOptions = require('middlewares/cors.js').corsOptions;
const errorHandleMiddleware = require('middlewares/errorHandling.js');
require('middlewares/auth.js');
const logger = require('utils/logger.js');
import babelConfig from '@/configs/babel'
import register from '@babel/register'
babelConfig.presets.find(p => p[0].includes('preset-env'))[1] = {
modules: 'commonjs',
targets: {
node: true,
browsers: false,
esmodules: true
}
}
babelConfig.extensions = ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
babelConfig.cache = false
register(babelConfig)
addPath(path.resolve(process.cwd(), 'node_modules'))
addPath(path.resolve(__dirname, '../../node_modules'))
const alias = { ...mhyConfig.defaultAliases }
for (const [key, entry] of Object.entries(alias)) {
if (!fs.existsSync(entry)) {
alias[key] = path.resolve(process.cwd(), entry)
} else {
// Make sure it's a resolved path indeed
alias[key] = path.resolve(entry)
}
}
addAliases(alias)
const scriptKey = '--mhy-script'
const scriptIndex = process.argv.findIndex(v => v.includes(scriptKey))
const scriptValue = process.argv[scriptIndex]
#!/usr/bin/env node
import path from 'path'
import yargs from 'yargs'
import { loadCommands } from '@/processes'
import { addPath, addAlias } from 'module-alias'
// Register dist with alias and mhy's node_modules as module source so custom JS files can use it loaded through mhy
addAlias('@/mhy', path.resolve(__dirname, '../'))
addPath(path.resolve(__dirname, '../../node_modules'))
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
process.env.MHY_ENV = 'cli'
process.env.MHY_LOCAL_DIR = '.mhy'
global.MHY_UI_ACTION = 'action'
global.MHY_UI_ACTION_CLEAR = 'clear'
global.MHY_UI_ACTION_DATA = 'data'
global.MHY_UI_ACTION_UPDATE = 'update'
global.MHY_UI_ACTION_FUNCTION = 'function'
if (process.argv.includes('--mhy-prod')) {
process.env.NODE_ENV = 'production'
}
if (process.argv.includes('--mhy-verbose')) {
const moduleAlias = require('module-alias');
moduleAlias.addPath(__dirname);
moduleAlias.addAliases({
'@leaa/common': '_dist/_leaa-common',
'@leaa/api': '_dist/leaa-api',
});
moduleAlias({});
console.log('\n\n\n\n---- hello, leaa-api-server. ----\n\n');
require('./_dist/leaa-api/src/main');
const moduleAlias = require('module-alias');
moduleAlias.addPath(__dirname);
moduleAlias.addAliases({
'@leaa/common': '_dist/_leaa-common',
'@leaa/www': '_dist/leaa-www',
});
moduleAlias({});
require('./_dist/leaa-www/server');