This is an automated email from the ASF dual-hosted git repository. erikdebruin pushed a commit to branch feature/wast in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit cc2785830b9e791c4f5c889ee8e17168b05f0a98 Author: Erik de Bruin <[email protected]> AuthorDate: Wed Nov 15 15:57:30 2017 +0100 Add build scripts Signed-off-by: Erik de Bruin <[email protected]> --- wast/README | 15 +++++++ wast/create.js | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ wast/package.json | 48 ++++++++++++++++++++ wast/resources/build.js | 96 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+) diff --git a/wast/README b/wast/README new file mode 100644 index 0000000..6d17c12 --- /dev/null +++ b/wast/README @@ -0,0 +1,15 @@ +To create a new Royale WAST project, use: + +npm run create-project -- -dir=[root dir] -name=[project name] + +This will create the following project structure: + +[root dir] + | + /src + | | + | - [project name].as + | + - build.js + - package.json + - README diff --git a/wast/create.js b/wast/create.js new file mode 100644 index 0000000..1d5b23c --- /dev/null +++ b/wast/create.js @@ -0,0 +1,113 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +'use strict'; + +let args, createFile, dir, fs, projectName, projectPath, projectSrcPath, royaleHome; + + + +fs = require('fs'); + + + +createFile = function (file, content) { + fs.writeFile(file, content, function(error) { + if (error) { + return console.log(`Error writing file ('${file}'): ` + error + '.'); + } else { + console.log(`Created file ('${file}').`); + } + }); +}; + + + +args = {}; +process.argv.slice(2).forEach(function (value) { + let valueArray; + + valueArray = value.split('='); + if (1 < valueArray.length) { + let name, value; + + name = valueArray[0].substr(1); + value = valueArray[1]; + + args[name] = value; + + console.log('Set arg \'' + name + '\' to \'' + value + '\''); + } +}); + +royaleHome = process.argv[1].split('/'); +royaleHome.pop(); // remove 'create.js' +royaleHome.pop(); // remove 'wast' +royaleHome = royaleHome.join('/'); + +dir = args['dir']; +if (!fs.existsSync(dir)) { + console.log(`The intended target directory ('${dir}') does not exist.`); + + process.exit(); +} + +projectName = args['name']; +projectPath = dir + '/' + projectName; +if (!fs.existsSync(projectPath)) { + fs.mkdirSync(projectPath); +} + +projectSrcPath = projectPath + '/src'; +if (!fs.existsSync(projectSrcPath)) { + fs.mkdirSync(projectSrcPath); +} + +createFile(projectPath + '/README', `To build and run this project, use: + +cd [project dir] +npm run build +`); + +fs.createReadStream('resources/build.js') +.pipe(fs.createWriteStream(projectPath + '/build.js')); + +createFile(projectPath + '/package.json', `{ + "dependencies": { + "http-server" : "0.10.0" + }, + + "scripts": { + "build": "npm install; node build.js -royale-home=${royaleHome} -src=src/${projectName}.as; http-server bin/ -s -o -p3546" + } + +} +`); + +createFile(projectSrcPath + '/' + projectName + '.as', `package { + + public class ${projectName} { + + public function main():void { + trace('Hello world ;-)'); + } + + } + +}`); diff --git a/wast/package.json b/wast/package.json new file mode 100644 index 0000000..7b5faa9 --- /dev/null +++ b/wast/package.json @@ -0,0 +1,48 @@ +{ + + "author": "[email protected]", + + "description": "A Actionscript/MXML to WebAssembly transpiler", + + "eslintConfig": { + "env": { + "browser": true, + "es6": true, + "node": true + }, + + "extends": "eslint:recommended", + + "globals": { + "WebAssembly": true + }, + + "rules": { + "eqeqeq": [ "error", "always" ], + "indent": [ "error", 2, { + "FunctionDeclaration": { "body": 1, "parameters": 2 }, + "FunctionExpression": { "body": 1, "parameters": 2 }, + "MemberExpression": 0, + "SwitchCase": 1, + "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } + } ], + "linebreak-style": [ "error", "unix" ], + "no-console": "off", + "quotes": [ "error", "single" ], + "semi": [ "error", "always" ], + "yoda": [ "error", "always" ] + } + }, + + "license": "Apache-2.0", + + "name": "royale-wast", + + "scripts": { + "dev-build": "ant -f ./dev-build.xml", + "create-project": "node create.js" + }, + + "version": "0.0.1" + +} diff --git a/wast/resources/build.js b/wast/resources/build.js new file mode 100644 index 0000000..b56a753 --- /dev/null +++ b/wast/resources/build.js @@ -0,0 +1,96 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +'use strict'; + +let args, cmd, exec, fs, playerVersion, royaleHome, wastc; + + + +exec = require('child_process').exec; +fs = require('fs'); + + + +args = {}; +process.argv.slice(2).forEach(function (value) { + let valueArray; + + valueArray = value.split('='); + if (1 < valueArray.length) { + let name, value; + + name = valueArray[0].substr(1); + value = valueArray[1]; + + args[name] = value; + + console.log('Set arg \'' + name + '\' to \'' + value + '\''); + } +}); + +royaleHome = args['royale-home']; +if (!royaleHome || '' === royaleHome) { + royaleHome = process.env.ROYALE_HOME; + if (!royaleHome || '' === royaleHome) { + console.log('ROYALE_HOME is not defined. Create an environment variable (ROYALE_HOME) and point it to the skd dir, or use \'npm run build -- -royale-home=[sdk dir]\'.'); + + process.exit(); + } +} +console.log('ROYALE_HOME is ' + royaleHome); + +wastc = royaleHome + '/wast/lib/wastc.jar'; +if (!fs.existsSync(wastc)) { + console.log('Transpiler \'wastc\' not found. This sdk appears not to be an sdk that is compatible with this project.'); + + process.exit(); +} + +playerVersion = args['player-version']; +if (!playerVersion || '' === playerVersion) { + playerVersion = process.env.PLAYERGLOBAL_VERSION; +} +if (!playerVersion || '' === playerVersion) { + playerVersion = '11.1'; + + console.log('PLAYERGLOBAL_VERSION was undefined. It is now set to \'11.1\'. To override this default, create an environment variable (PLAYERGLOBAL_VERSION) and set it to required version, or use \'npm run build -- -player-version=[version]\'.'); +} else { + console.log('PLAYERGLOBAL_VERSION is ' + playerVersion + '.'); +} + +if (!fs.existsSync(royaleHome + '/frameworks/libs/player/' + playerVersion + '/playerglobal.swc')) { + console.log('\'playerglobal.swc\' could not be found. Make sure you have set ROYALE_HOME to a fully built sdk.'); + + process.exit(); +} + +cmd = `/usr/bin/java -Xmx384m -Dsun.io.useCanonCaches=false -jar "${wastc}" -external-library-path="${royaleHome}/frameworks/libs/player/${playerVersion}/playerglobal.swc" ${args['src']}`; + +exec(cmd, function (error, stdout, stderr) { + console.log(stdout); + + if (stderr && '' !== stderr) { + console.log('stderr: ' + stderr); + } + + if (error) { + console.log('exec error: ' + error); + } +}); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
