Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (31 sloc) 2.06 KB
//node executable js file to generate a standalone an documentdb executable stored procedure file
//run this with node in the current directory where this file is stored.
//make sure typescript files are built -> read the README.md file
var Builder = require('systemjs-builder');
var fs = require('fs');
var storedProcedureFileName = 'myStoredProcedure'; //fileName
var standaloneBundleName = storedProcedureFileName + '_temp.js';
var finalStoredProcedureFileName = storedProcedureFileName + "_standalone.js";
var jsFilesDir = './StoredProcedureGenerationWeb/out-js/';
var finalStoredProcedureDir = './StoredProcedureGenerationWeb/generated-procedure';
var tempSystemJSFilePath = jsFilesDir + storedProcedureFileName + '_temp.js';
var finalStandaloneStoredProcedurePath = finalStoredProcedureDir + finalStoredProcedureFileName;
//step1: generate the standalone system-js bundle...
var configFile = './StoredProcedureGenerationWeb/config.js';
var builder = new Builder(jsFilesDir, configFile);
builder.buildStatic(jsFilesDir + storedProcedureFileName, tempSystemJSFilePath, { minify: false }).then(function () {
//step2: patch to have a simple basic entry point function (mandatory for documentdb)
var data = fs.readFileSync(tempSystemJSFilePath, 'utf-8');
var newValue = "/*This code is generated by node script documentdb_storedprocedure_builder.js (root of repository) - DO NOT edit this file MANUALLY !!! */ \n"
newValue += "function entry_point(){ \n"
newValue += "global = this; \n"; //set the global variable for systemjs builder (in documentdb no self or global object)
newValue += "global.storedProcedureArgs = arguments; \n" //take function arguments and pushed them in global object
newValue += data;
newValue += "\n";
newValue += "}"
fs.writeFileSync(finalStandaloneStoredProcedurePath, newValue, 'utf-8');
console.log("Stored procedure generation successful!")
console.log("file location: " + finalStandaloneStoredProcedurePath)
}, function () {
throw Error("Cannot generate systemjs bundle")
});
You can’t perform that action at this time.