Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkCode(code) {
var instCode = esnstrument.instrumentCodeDeprecated(code, {wrapProgram: false, dirIIDFile: temp.dir}).code;
// console.log(instCode);
var ast = acorn.parse(instCode);
// NOTE: this is not a robust way to do a deep copy of ASTs,
// just good enough for unit tests
// console.log("init:\n" + JSON.stringify(ast,undefined,2));
var astCopy = JSON.parse(JSON.stringify(ast));
var table = astUtil.serialize(ast);
// assert.deepEqual(ast,astCopy); would fail here
// console.log("serialized:\n" + JSON.stringify(ast,undefined,2));
astUtil.deserialize(table);
// console.log("deserialized:\n" + JSON.stringify(ast,undefined,2));
assert.deepEqual(ast,astCopy);
}
exports.configurate = function () {
if (!lconfig) {
// override from the system temporary directory because of the locker's insane insistence on relative paths.
temp.dir = '.';
process.env.NODE_PATH = path.join(__dirname, '..', '..', 'Common', 'node');
process.env.LOCKER_ROOT = path.join(__dirname, '..', '..');
process.env.LOCKER_CONFIG = path.join(__dirname, '..', 'resources');
process.env.LOCKER_ME = temp.path({prefix : 'Me.',
suffix : '.test'});
lconfig = require(path.join(__dirname, '..', '..', 'Common', 'node', 'lconfig.js'));
lconfig.load(path.join(process.env.LOCKER_CONFIG, 'config.json'));
}
return lconfig;
};
import temp from "temp";
import request from "request";
import url from "url";
import path from "path";
import InputVertex from "./InputVertex";
import SK from "../../sk";
// We want to download the file locally first. FFmpeg will download it over and over when looping
// otherwise.
temp.dir = "/tmp"; // os.tmpDir is set weird in Docker. Hack hack hack.
temp.track();
const fetchFile = function(fileURL) {
return new Promise((resolve, reject) => {
const {pathname} = url.parse(fileURL); // gives /pub/whatever/example.png
const basename = path.basename(pathname); // gives example.png
const writeStream = temp.createWriteStream({suffix: basename});
const outputPath = writeStream.path;
writeStream
.on("error", reject)
.on("finish", () => {
resolve(outputPath);
});
request.get(fileURL)
.on("error", reject)
function instrument(inputFileName, options) {
if (!options) {
options = {};
}
if (!options.relative) {
inputFileName = path.resolve(inputFileName);
}
var outputFileName = getInstOutputFile(options.outputFile);
var iidMapFile, iidMetadataFile;
var inputCode = String(fs.readFileSync(inputFileName));
var dirIIDFile = options.dirIIDFile ? options.dirIIDFile : temp.dir;
var instCodeOptions = {
wrapProgram: true,
filename: inputFileName,
instFileName: outputFileName,
metadata: options.serialize,
initIID: true,
dirIIDFile: dirIIDFile
};
var instResult = esnstrument.instrumentCodeDeprecated(inputCode, instCodeOptions);
var instCode = instResult.code;
fs.writeFileSync(outputFileName, instCode);
if (options.serialize) {
// TODO choose a better file name here
iidMetadataFile = outputFileName + ".ast.json";
writeMetadataToFile(instResult.instAST, iidMetadataFile);
}
function checkCode(code, expectedTopLevel) {
var instResult = esnstrument.instrumentCodeDeprecated(code, {wrapProgram: false, metadata: true, dirIIDFile: temp.dir, initIID: true });
var topLevelResult = collectTopLevel(instResult.instAST);
assert.deepEqual(topLevelResult, expectedTopLevel);
}
function getOrOpenTempFile(callback) {
if (tempFile) {
return callback(null, tempFile);
} else {
if (self.opts.tempDir) {
temp.dir = self.opts.tempDir;
}
return temp.open(TEMP_PREFIX, function(err, newTempFile) {
if (err) {
return callback(err);
}
tempFile = newTempFile;
tempFile.packetCount = 0;
tempFile.capturedLength = 0;
tempFile.createdOn = Date.now();
var globalHeaderBuffer = createGlobalHeader(globalHeader);
return fs.write(tempFile.fd, globalHeaderBuffer, 0, globalHeaderBuffer.length, null, function(err) {
if (err) {
return callback(err);
}
return callback(null, tempFile);
(function () {
log(__('Directory Permissions'));
[
[ '~', __('home directory') ],
[ '~/.titanium', __('titanium config directory') ],
[ cli.env.installPath, __('titanium sdk install directory') ],
[ config.get('app.workspace'), __('workspace directory') ],
[ temp.dir, __('temp directory') ]
].forEach(function (info) {
if (info[0]) {
var dir = afs.resolvePath(info[0]);
if (fs.existsSync(dir)) {
if (afs.isDirWritable(dir)) {
ok(info[1]);
} else {
bad(info[1], __('"%s" not writable, check permissions and owner', dir));
}
} else {
warn(info[1], __('"%s" does not exist', dir));
}
}
});
log();
}());
npm.load(config, function(){
npm.registry.log.level = config.loglevel;
npm.commands.install(temp.dir, [options.module], function(err, data){
if (err) {
cbk(err, data);
} else {
var dir = temp.dir + "/node_modules/" + options.module;
var mod = require(dir);
cbk(void 0, mod);
}
});
});
}
var temp = require('temp')
, path = require('path')
, express = require('express')
, less = require('less-middleware')
, root = __dirname
, tmp = path.join(temp.dir, 'TesselKey')
, views = path.join(root , 'views')
, pub = path.join(root , 'public')
, images = path.join(pub , 'images')
, scripts = path.join(pub , 'scripts')
, app = express()
, trimmer = require('./modules/trimmer.js')
, webp = require('./modules/webp.js')
, port = process.env.PORT || 5000
;
app.disable('X-Powered-By');
app.configure(function() {
app.use(express.compress());
app.use(trimmer());
app.use(webp(pub));