-
-
Save anonymous/2632b00bf51bc77565657569217c75a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var fs = require('fs'); | |
const uuidV1 = require('uuid/v1'); | |
const fsRootPath = 'D:/Daten/tmp/'; | |
const urlRoot = 'http://localhost:3000/'; | |
var app = express(); | |
// Make directories available through localhost | |
app.use(express.static('D:/Daten/apps/flexjsnow/target/javascript/bin/js-debug')); | |
app.use(express.static(fsRootPath)); | |
// parse application/json | |
app.use(bodyParser.json()); | |
app.post('/flexjs/_compile', function (req, res) { | |
console.log(req.body.source); | |
// Create UUID for directory naming | |
var tmpDir = uuidV1(); | |
var rootPath = 'C:/Daten/tmp/'; | |
var projectPath = rootPath.concat(tmpDir, '/'); | |
var projectSrcPath = projectPath.concat('src/'); | |
var mainFilePath = projectSrcPath.concat('Main.mxml'); | |
var projectUrl = urlRoot.concat(tmpDir, '/target/javascript/bin/js-debug/index.html'); | |
// Create tmp dir where the compiled Flex code lives | |
if (!fs.existsSync(projectPath)){ | |
fs.mkdirSync(projectPath); | |
} | |
if (!fs.existsSync(projectSrcPath)){ | |
fs.mkdirSync(projectSrcPath); | |
} | |
// Copy asconfig.json to tmp dir | |
var asconfigSrcPath = rootPath.concat('asconfig.json'); | |
console.log(asconfigSrcPath); | |
var asconfigDestPath = projectPath.concat('asconfig.json'); | |
fs.createReadStream(asconfigSrcPath).pipe(fs.createWriteStream(asconfigDestPath)); | |
// Create file 'Main.mxml' including source code from payload | |
fs.appendFileSync(mainFilePath, req.body.source); | |
var exec = require('child_process').exec; | |
var cmd = 'asconfigc -p '; | |
cmd = cmd.concat(projectPath, ' --flexHome --flexHome=C:/Daten/flex_sdks/flexjs_0_8_0_nightly_latest'); | |
exec(cmd, function(error, stdout, stderr) { | |
// command output is in stdout | |
var obj = new Object(); | |
obj.projectUrl = projectUrl; | |
obj.compilerOutput = stdout; | |
var jsonString= JSON.stringify(obj); | |
res.send(jsonString); | |
}); | |
}); | |
app.listen(3000, function () { | |
console.log('Example app listening on port 3000!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment