Compare commits
22
Commits
e58d63f260
...
2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57f7e88fab | ||
|
|
7f62df2364 | ||
|
|
6622d53167 | ||
|
|
561dd99cba | ||
|
|
bc77380aba | ||
|
|
a20e98d730 | ||
|
|
87fe852f99 | ||
|
|
dfad6d3aba | ||
|
|
bff3cc06ef | ||
|
|
6ff587cb65 | ||
|
|
bf6ff0deb9 | ||
|
|
2605c1bbc8 | ||
|
|
d9e8976e85 | ||
|
|
f417fcac73 | ||
|
|
05be4ab622 | ||
|
|
ce51ab817c | ||
|
|
0672f2a1e0 | ||
|
|
428f9d100e | ||
|
|
fc7f97b520 | ||
|
|
cf3a707a47 | ||
|
|
188fcc8e4c | ||
|
|
c8720102f9 |
@@ -1,199 +1,110 @@
|
||||
# Gulp HaXe Tool
|
||||
# HaXeTool
|
||||
|
||||
[](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions?workflow=test.yaml)
|
||||
|
||||
## Introducing
|
||||
|
||||
### Dignity
|
||||
Tool for simple building and pack HaXe and OpenFl project
|
||||
|
||||
* Automatically download HaXe SDK, Neko, FlashPlayer, Android SDK, +(Adobe AIR SDK).
|
||||
* Universal project config for simple HaXe build and OpenFL build.
|
||||
* Branch project config for many build presets (many OpenFL apps in one project).
|
||||
* Packaging linux output in DEB.
|
||||
* Packaging windows output in exe install with InnoSetup.
|
||||
* Create html wrapper for flash output.
|
||||
## OpenFL Example
|
||||
|
||||
### Flaws
|
||||
[Example project](./example)
|
||||
|
||||
* Hardcode build output in {projectDir}/target (need param in Project.Config).
|
||||
* HTML5 run output not caught.
|
||||
* Adobe AIR Build System in progress.
|
||||
* Windows target depends Visual Studio 2017 build tools
|
||||
[`package.json`](./example/package.json)
|
||||
|
||||
## API
|
||||
|
||||
### Project.Config
|
||||
|
||||
#### constructor
|
||||
|
||||
* **meta**: meta information
|
||||
* **title**: application title
|
||||
* **filename**: application filename
|
||||
* **icon**: path to icon file
|
||||
* **pack**: package name for OpenFL
|
||||
* **author**: author name for DEB packaging
|
||||
* **company**: company name for OpenFL
|
||||
* **version**: application version
|
||||
* **name**: name for output directory
|
||||
* **libs**: list of haxe dependencies
|
||||
* **sources**: list of HaXe sources
|
||||
* **assets**: list of resources
|
||||
* **main**: main class name
|
||||
* **macros**: list of macros
|
||||
|
||||
### Project
|
||||
|
||||
#### constructor
|
||||
|
||||
* **buildSystem**: Project.BuildSystem
|
||||
* **platforms**: Project.Platform (list supported)
|
||||
* **config**: Project.Config
|
||||
|
||||
#### bind
|
||||
|
||||
* **module**
|
||||
|
||||
create gulp tasks in module:
|
||||
|
||||
```
|
||||
<config.name>:<platform>:build
|
||||
<config.name>:<platform>:run
|
||||
<config.name>:<platform>:test
|
||||
|
||||
<config.name>:flash:html
|
||||
|
||||
<config.name>:linux:archive
|
||||
<config.name>:linux:deb
|
||||
|
||||
<config.name>:windows:archive
|
||||
<config.name>:windows:installer
|
||||
```
|
||||
|
||||
eg: ```gulp app:flash:test```
|
||||
|
||||
## Example
|
||||
|
||||
[package.json](example/package.json)
|
||||
```json
|
||||
{
|
||||
"name": "app",
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "^0.1.0"
|
||||
"name": "example",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"tasks": "hxt",
|
||||
"build": "hxt default",
|
||||
"dev": "hxt app:flash:test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-haxetool": "^2.0.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[`haxetool.json`](./example/haxetool.json)
|
||||
|
||||
JSON schema: https://shmyga.ru/public/haxetool.schema.json
|
||||
|
||||
```json
|
||||
{
|
||||
"app": {
|
||||
"buildSystem": "openfl",
|
||||
"platforms": ["flash", "html5", "linux", "windows", "android"],
|
||||
"libs": {
|
||||
"lime": "8.3.2",
|
||||
"openfl": "9.5.2",
|
||||
"hxcpp": "4.2.1"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"lime": "7.6.0",
|
||||
"openfl": "8.9.2",
|
||||
"hxcpp": "4.0.19"
|
||||
"sources": ["src"],
|
||||
"main": "Main"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
### Display tasks list
|
||||
|
||||
```bash
|
||||
npx hxt
|
||||
```
|
||||
|
||||
### Build and pack all platform variants
|
||||
|
||||
Results places in `target` directory
|
||||
|
||||
```bash
|
||||
npx hxt default
|
||||
```
|
||||
|
||||
### Build and run platform target
|
||||
|
||||
```bash
|
||||
npx hxt <preset>:<platform>:test
|
||||
```
|
||||
```bash
|
||||
npx hxt app:flash:test
|
||||
npx hxt app:html5:test
|
||||
npx hxt app:linux:test
|
||||
npx hxt app:android:test
|
||||
npx hxt app:windows:test
|
||||
```
|
||||
|
||||
## Dependencies requiring manual installation
|
||||
|
||||
### Windows
|
||||
|
||||
* Visual Studio 2017 build tools
|
||||
|
||||
### Android
|
||||
|
||||
* Java JDK 17
|
||||
|
||||
## VS Code settings
|
||||
|
||||
### JSON schema for `haxetool.json`
|
||||
|
||||
```json
|
||||
{
|
||||
...
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": [
|
||||
"/haxetool.json"
|
||||
],
|
||||
"url": "https://shmyga.ru/public/haxetool.schema.json"
|
||||
}
|
||||
],
|
||||
"json.schemaDownload.trustedDomains": {
|
||||
"https://shmyga.ru/": true
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
[src/Main.hx](example/src/Main.hx)
|
||||
```haxe
|
||||
import flash.display.Shape;
|
||||
import flash.Lib;
|
||||
|
||||
class Main {
|
||||
|
||||
public static function main() {
|
||||
trace("Hello world!");
|
||||
var shape = new Shape();
|
||||
shape.graphics.beginFill(0x00ff00);
|
||||
shape.graphics.drawCircle(50, 50, 20);
|
||||
shape.graphics.endFill();
|
||||
Lib.current.addChild(shape);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[gulpfile.js](example/gulpfile.js)
|
||||
```javascript
|
||||
const gulp = require('gulp');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const packageInfo = require('./package.json');
|
||||
const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
|
||||
|
||||
//Sdk.dir = '/opt/sdk';
|
||||
|
||||
exports.clean = function clean() {
|
||||
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
||||
};
|
||||
|
||||
exports.install = function install() {
|
||||
const haxe = new Haxe();
|
||||
return haxe.prepare().then(() => haxe.install(packageInfo.haxeDependencies));
|
||||
};
|
||||
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
title: 'Application',
|
||||
filename: 'app',
|
||||
icon: './resources/icon.jpg',
|
||||
pack: 'com.example',
|
||||
author: 'Anonim <anonim@anonim.com>',
|
||||
company: 'Any company',
|
||||
version: packageInfo.version,
|
||||
},
|
||||
name: 'app',
|
||||
libs: packageInfo.haxeDependencies,
|
||||
sources: ['src'],
|
||||
assets: ['resources'],
|
||||
main: 'Main',
|
||||
});
|
||||
|
||||
const project = new Project(
|
||||
Project.BuildSystem.OPENFL,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
Project.Platform.WINDOWS,
|
||||
],
|
||||
config
|
||||
).bind(module);
|
||||
|
||||
|
||||
const defaultSeries = [
|
||||
exports.clean,
|
||||
module.exports['app:flash:build'],
|
||||
module.exports['app:flash:html'],
|
||||
module.exports['app:html5:build'],
|
||||
];
|
||||
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(
|
||||
module.exports['app:linux:build'],
|
||||
module.exports['app:linux:archive'],
|
||||
module.exports['app:linux:deb'],
|
||||
|
||||
module.exports['app:android:build'],
|
||||
);
|
||||
}
|
||||
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(
|
||||
module.exports['app:windows:build'],
|
||||
module.exports['app:windows:archive'],
|
||||
module.exports['app:windows:installer'],
|
||||
);
|
||||
}
|
||||
|
||||
module.exports.default = gulp.series(defaultSeries);
|
||||
```
|
||||
|
||||
Build for all platforms: `gulp default`
|
||||
|
||||
Build app for specific platform: `gulp app:flash:build`
|
||||
|
||||
Build and run flash app in flashplayer: `gulp app:flash:test`
|
||||
|
||||
Build and run html5 app in browser: `gulp app:html5:test`
|
||||
|
||||
Build and run linux app native: `gulp app:linux:test`
|
||||
|
||||
Build and run windows app native: `gulp app:windows:test`
|
||||
|
||||
Build and run android app: `gulp app:android:test`
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"$id": "https://shmyga.ru/public/haxetool.schema.json",
|
||||
"title": "Haxe tool",
|
||||
"description": "Haxe tool presets",
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
".*": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"buildSystem": { "enum": ["haxe", "openfl"] },
|
||||
"platforms": {
|
||||
"type": "array",
|
||||
"items": { "enum": ["flash", "html5", "linux", "windows", "android", "neko", "cpp"] }
|
||||
},
|
||||
"name": { "type": "string" },
|
||||
"main": { "type": "string" },
|
||||
"preloader": { "type": "string" },
|
||||
"sources": { "type": "array", "items": { "type": "string" } },
|
||||
"assets": { "type": "array", "items": { "type": "string" } },
|
||||
"libs": { "type": "object", "patternProperties": { ".*": { "type": "string" } } },
|
||||
"macros": { "type": "array", "items": { "type": "string" } },
|
||||
"flags": { "type": "array", "items": { "type": "string" } },
|
||||
"meta": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": { "type": "string" },
|
||||
"filename": { "type": "string" },
|
||||
"icon": { "type": "string" },
|
||||
"version": { "type": "string" },
|
||||
"pack": { "type": "string" },
|
||||
"author": { "type": "string" },
|
||||
"company": { "type": "string" },
|
||||
"width": { "type": "number" },
|
||||
"height": { "type": "number" },
|
||||
"mobileWidth": { "type": "number" },
|
||||
"mobileHeight": { "type": "number" },
|
||||
"fps": { "type": "number" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"key": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"store": { "type": "string" },
|
||||
"pass": { "type": "string" }
|
||||
},
|
||||
"required": ["store", "pass"]
|
||||
},
|
||||
"android": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": { "type": "string" },
|
||||
"extensions": { "type": "array", "items": { "type": "string" } }
|
||||
}
|
||||
}
|
||||
},
|
||||
"haxe": { "type": "string" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -1,7 +0,0 @@
|
||||
import gulp from "gulp";
|
||||
import { Preset } from "gulp-haxetool";
|
||||
import presetData from "./haxetool.json" with { type: "json" };
|
||||
import packageInfo from "./package.json" with { type: "json" };
|
||||
|
||||
const preset = new Preset(presetData, null, packageInfo);
|
||||
export default preset.register(gulp);
|
||||
+7
-13
@@ -2,18 +2,12 @@
|
||||
"app": {
|
||||
"buildSystem": "openfl",
|
||||
"platforms": ["flash", "html5", "linux", "windows", "android"],
|
||||
"config": {
|
||||
"meta": {
|
||||
"title": "Example",
|
||||
"filename": "example",
|
||||
"icon": "./resources/icon.jpg",
|
||||
"pack": "com.example",
|
||||
"author": "Anonim <anonim@anonim.com>",
|
||||
"company": "Any company",
|
||||
"version": "<%=package.version%>"
|
||||
},
|
||||
"sources": ["src"],
|
||||
"main": "Main"
|
||||
}
|
||||
"libs": {
|
||||
"lime": "8.3.2",
|
||||
"openfl": "9.5.2",
|
||||
"hxcpp": "4.2.1"
|
||||
},
|
||||
"sources": ["src"],
|
||||
"main": "Main"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+2341
-1838
File diff suppressed because it is too large
Load Diff
+5
-11
@@ -3,17 +3,11 @@
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"build": "gulp",
|
||||
"dev": "gulp app:flash:test"
|
||||
"tasks": "hxt",
|
||||
"build": "hxt default",
|
||||
"dev": "hxt app:flash:test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-cli": "^3.1.0",
|
||||
"gulp-haxetool": "^1.2.0"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"lime": "8.0.0",
|
||||
"openfl": "9.2.0",
|
||||
"hxcpp": "4.2.1"
|
||||
},
|
||||
"haxe": "4.2.5"
|
||||
"gulp-haxetool": "file:.."
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+69
-35
@@ -1,14 +1,15 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "gulp-haxetool",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ajv": "^8.20.0",
|
||||
"ansi-colors": "^4.1.3",
|
||||
"async": "^3.2.6",
|
||||
"cli-progress": "^3.12.0",
|
||||
@@ -19,7 +20,7 @@
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-connect": "^5.7.0",
|
||||
"gulp-debian": "^0.3.2",
|
||||
"gulp-debian": "^0.1.9",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-rename": "^2.1.0",
|
||||
"gulp-tar": "^5.0.0",
|
||||
@@ -33,6 +34,9 @@
|
||||
"vinyl": "^3.0.1",
|
||||
"vinyl-fs": "^4.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"hxt": "dist/bin/cli.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async": "^3.2.26",
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
@@ -1762,16 +1766,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "6.15.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz",
|
||||
"integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==",
|
||||
"dev": true,
|
||||
"version": "8.20.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
|
||||
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.4.1",
|
||||
"uri-js": "^4.2.2"
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fast-uri": "^3.0.1",
|
||||
"json-schema-traverse": "^1.0.0",
|
||||
"require-from-string": "^2.0.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
@@ -3520,6 +3523,23 @@
|
||||
"url": "https://opencollective.com/eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/ajv": {
|
||||
"version": "6.15.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz",
|
||||
"integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.4.1",
|
||||
"uri-js": "^4.2.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/epoberezkin"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/glob-parent": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
|
||||
@@ -3533,6 +3553,13 @@
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/json-schema-traverse": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/espree": {
|
||||
"version": "11.2.0",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-11.2.0.tgz",
|
||||
@@ -3695,7 +3722,6 @@
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-fifo": {
|
||||
@@ -3718,6 +3744,22 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-uri": {
|
||||
"version": "3.1.9",
|
||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz",
|
||||
"integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/fastest-levenshtein": {
|
||||
"version": "1.0.16",
|
||||
"resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz",
|
||||
@@ -3803,15 +3845,6 @@
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/find": {
|
||||
"version": "0.2.9",
|
||||
"resolved": "https://registry.npmjs.org/find/-/find-0.2.9.tgz",
|
||||
"integrity": "sha512-7a4/LCiInB9xYMnAUEjLilL9FKclwbwK7VlXw+h5jMvT2TDFeYFCHM24O1XdnC/on/hx8mxVO3FTQkyHZnOghQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"traverse-chain": "~0.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/find-up": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz",
|
||||
@@ -4605,12 +4638,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/gulp-debian": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/gulp-debian/-/gulp-debian-0.3.2.tgz",
|
||||
"integrity": "sha512-P9zqKFQ9xRG1wvcJUYiBxUEypoPcDsFJxmxyJ6PSyfF2iOcsIk1mPTp47Qs0Q36bdWvrauvGTvJxscFIhK1U3A==",
|
||||
"version": "0.1.9",
|
||||
"resolved": "https://registry.npmjs.org/gulp-debian/-/gulp-debian-0.1.9.tgz",
|
||||
"integrity": "sha512-hY16Lj5IdxY213L9Sl6SlEgpCvf8/ny3SQ4S9dyG8MHqRx0fPpui5CRodhQK5lA2oScxP8qi4wfK4fIDr5xF3g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"find": "^0.2.8",
|
||||
"fs-extra": "^5.0.0",
|
||||
"gulp-util": "^3.0.8",
|
||||
"through2": "^2.0.1",
|
||||
@@ -5944,10 +5976,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-traverse": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
|
||||
"dev": true,
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/json-stable-stringify-without-jsonify": {
|
||||
@@ -7137,6 +7168,15 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-from-string": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/resolve": {
|
||||
"version": "1.22.13",
|
||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.13.tgz",
|
||||
@@ -8394,12 +8434,6 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/traverse-chain": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/traverse-chain/-/traverse-chain-0.1.0.tgz",
|
||||
"integrity": "sha512-up6Yvai4PYKhpNp5PkYtx50m3KbwQrqDwbuZP/ItyL64YEWHAvH6Md83LFLV/GRSk/BoUVwwgUzX6SOQSbsfAg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tree-kill": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
|
||||
|
||||
+10
-5
@@ -1,14 +1,18 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"type": "module",
|
||||
"version": "1.2.0",
|
||||
"description": "HaXe Tool for Gulp",
|
||||
"version": "2.0.3",
|
||||
"description": "HaXe Tool with Gulp",
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
"./bin/cli": "./dist/bin/cli.mjs",
|
||||
"./lib": "./dist/lib/index.mjs",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"bin": {
|
||||
"hxt": "./dist/bin/cli.mjs"
|
||||
},
|
||||
"types": "./dist/lib/index.d.mts",
|
||||
"files": [
|
||||
"template",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
@@ -29,6 +33,7 @@
|
||||
"license": "MIT",
|
||||
"homepage": "https://git.shmyga.ru/InfernalGames/gulp-haxetool#readme",
|
||||
"dependencies": {
|
||||
"ajv": "^8.20.0",
|
||||
"ansi-colors": "^4.1.3",
|
||||
"async": "^3.2.6",
|
||||
"cli-progress": "^3.12.0",
|
||||
@@ -39,7 +44,7 @@
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-connect": "^5.7.0",
|
||||
"gulp-debian": "^0.3.2",
|
||||
"gulp-debian": "^0.1.9",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-rename": "^2.1.0",
|
||||
"gulp-tar": "^5.0.0",
|
||||
|
||||
Vendored
+39
-7
@@ -1,14 +1,46 @@
|
||||
declare module "vinyl" {
|
||||
export class File {
|
||||
path: string;
|
||||
import { type Stats } from "fs";
|
||||
import type Stream from "stream";
|
||||
|
||||
export type Contents = Stream | Buffer | null;
|
||||
|
||||
export interface Options<C extends Contents = Contents> {
|
||||
contents?: C;
|
||||
cwd?: string;
|
||||
base?: string;
|
||||
path?: string;
|
||||
stat?: Stats;
|
||||
history?: string[];
|
||||
}
|
||||
|
||||
export class File<C extends Contents = Contents> {
|
||||
contents: C;
|
||||
cwd: string;
|
||||
base: string;
|
||||
contents: any;
|
||||
stat: any;
|
||||
history: any[];
|
||||
constructor(params: any);
|
||||
clone(options?: any);
|
||||
relative: string;
|
||||
dirname: string;
|
||||
basename: string;
|
||||
stem: string;
|
||||
extname: string;
|
||||
path: string;
|
||||
symlink: string;
|
||||
stat: Stats;
|
||||
history: string[];
|
||||
|
||||
constructor(options?: Options<C>);
|
||||
isBuffer(): boolean;
|
||||
isStream(): boolean;
|
||||
isNull(): boolean;
|
||||
isDirectory(): boolean;
|
||||
isSymbolic(): boolean;
|
||||
clone(options?: Options<C>);
|
||||
|
||||
static isCustomProp(key: string): boolean;
|
||||
static isVinyl(file: File | any): boolean;
|
||||
}
|
||||
|
||||
export type StreamFile = File<Stream>;
|
||||
export type BufferFile = File<Buffer>;
|
||||
|
||||
export default File;
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import gulp from "gulp";
|
||||
import { Preset } from ".";
|
||||
import { name, version } from "../package.json" with { type: "json" };
|
||||
|
||||
console.log(`[${name} ${version}]`);
|
||||
|
||||
const showTasks = () => {
|
||||
const tree = gulp.tree({ deep: true });
|
||||
console.log(tree.nodes.map((node) => node.label).join("\n"));
|
||||
};
|
||||
|
||||
const runTask = async (name: string) => {
|
||||
const task = gulp.task(name);
|
||||
if (!task) {
|
||||
throw `task '${name}' not found`;
|
||||
}
|
||||
return await task((error) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const main = async () => {
|
||||
const preset = Preset.loader();
|
||||
Preset.validator(preset);
|
||||
const projects = Preset.compiler(preset);
|
||||
Preset.register(projects);
|
||||
|
||||
if (process.argv.length > 2) {
|
||||
await runTask(process.argv[2]);
|
||||
} else {
|
||||
showTasks();
|
||||
}
|
||||
};
|
||||
|
||||
export default main;
|
||||
|
||||
await main();
|
||||
@@ -0,0 +1,9 @@
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export default (name: string): string => {
|
||||
return path.join(__dirname, "assets", name);
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
import colors from "ansi-colors";
|
||||
|
||||
const _colors = {
|
||||
"[DEBUG]": colors.white,
|
||||
"[INFO]": colors.cyan,
|
||||
"[ERROR]": colors.red,
|
||||
"Called from ": colors.red,
|
||||
"[WARNING]": colors.yellow,
|
||||
};
|
||||
|
||||
export type Color = (v: string) => string;
|
||||
|
||||
export const getColor = (line: string): Color | null => {
|
||||
for (const [tag, color] of Object.entries(_colors)) {
|
||||
if (line.indexOf(tag) > -1) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return null; // colors.reset;
|
||||
};
|
||||
|
||||
export class Debug {
|
||||
public color: Color;
|
||||
|
||||
constructor() {
|
||||
this.color = colors.white;
|
||||
this.log = this.log.bind(this);
|
||||
}
|
||||
|
||||
log(line: string) {
|
||||
const newColor = getColor(line);
|
||||
if (newColor) this.color = newColor;
|
||||
if (line[0] === "\t" || line.startsWith("Called from ")) {
|
||||
console.log(this.color(line));
|
||||
} else {
|
||||
const result = line.split(" ");
|
||||
console.log(colors.gray(result.slice(0, 4).join(" ")) + " " + this.color(result.slice(4).join(" ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const DEBUG = new Debug();
|
||||
+91
-69
@@ -1,84 +1,106 @@
|
||||
import progress from "cli-progress";
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import got from "got";
|
||||
import got, { type Progress, type Request } from "got";
|
||||
import path from "path";
|
||||
import ps from "promise-streams";
|
||||
import type { Stream, Writable } from "stream";
|
||||
import * as tar from "tar";
|
||||
import { x as tarX } from "tar";
|
||||
import unzip from "unzip-stream";
|
||||
|
||||
export class Downloader {
|
||||
static bar: progress.MultiBar | null;
|
||||
export interface DownloadOptions {
|
||||
progress?: boolean;
|
||||
strip?: number;
|
||||
executable?: boolean;
|
||||
}
|
||||
|
||||
static createProgressBar() {
|
||||
if (Downloader.bar == null) {
|
||||
Downloader.bar = new progress.MultiBar(
|
||||
{
|
||||
clearOnComplete: true,
|
||||
},
|
||||
progress.Presets.shades_grey,
|
||||
);
|
||||
}
|
||||
return Downloader.bar.create(0, 0);
|
||||
}
|
||||
const DEFAULT_OPTIONS: DownloadOptions = { progress: true, strip: 1, executable: false };
|
||||
|
||||
static releaseProgressBar(bar: progress.SingleBar) {
|
||||
bar.stop();
|
||||
if (Downloader.bar != null) {
|
||||
Downloader.bar.remove(bar);
|
||||
if (!Downloader.bar.isActive) {
|
||||
Downloader.bar.stop();
|
||||
Downloader.bar = null;
|
||||
type Extractor = (stream: Request, dest: string, options: DownloadOptions) => Stream;
|
||||
|
||||
const ZIP_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
|
||||
return stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
|
||||
const filePath = entry.path.split("/").slice(options.strip).join(path.sep);
|
||||
if (filePath.length > 0) {
|
||||
if (entry.type === "Directory") {
|
||||
fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
|
||||
} else if (entry.type === "File") {
|
||||
const fullFilePath = path.join(dest, path.normalize(filePath));
|
||||
const dirPath = path.dirname(fullFilePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fse.ensureDirSync(dirPath);
|
||||
}
|
||||
entry.pipe(
|
||||
fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
|
||||
// TODO: zip entry file mode?
|
||||
mode: options.executable ? 0o755 : undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static download(url: string, dest: string, strip = 1, executable = false) {
|
||||
fse.ensureDirSync(dest);
|
||||
const bar = Downloader.createProgressBar();
|
||||
let stream: Stream = got.stream(url);
|
||||
stream = stream
|
||||
.on("request", (r: any) => {
|
||||
if (bar) bar.start(1, 0);
|
||||
})
|
||||
.on("downloadProgress", (p: any) => {
|
||||
if (bar) {
|
||||
bar.setTotal(p.total);
|
||||
bar.update(p.transferred);
|
||||
if (p.total === p.transferred) {
|
||||
Downloader.releaseProgressBar(bar);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (url.endsWith(".zip")) {
|
||||
stream = stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
|
||||
const filePath = entry.path.split("/").slice(strip).join(path.sep);
|
||||
if (filePath.length > 0) {
|
||||
if (entry.type === "Directory") {
|
||||
fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
|
||||
} else if (entry.type === "File") {
|
||||
const fullFilePath = path.join(dest, path.normalize(filePath));
|
||||
const dirPath = path.dirname(fullFilePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fse.ensureDirSync(dirPath);
|
||||
}
|
||||
entry.pipe(
|
||||
fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
|
||||
// ToDo: zip entry file mode?
|
||||
mode: executable ? 0o755 : undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
entry.autodrain();
|
||||
}
|
||||
});
|
||||
} else if (url.endsWith("tar.gz")) {
|
||||
stream = stream.pipe(tar.x({ C: dest, strip }) as unknown as Writable);
|
||||
} else {
|
||||
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split("/").pop()!)));
|
||||
entry.autodrain();
|
||||
}
|
||||
return ps.wait(stream);
|
||||
});
|
||||
};
|
||||
|
||||
const QZ_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
|
||||
// TODO: cast tar.Unpack to Writable
|
||||
return stream.pipe(tarX({ C: dest, strip: options.strip }) as unknown as Writable);
|
||||
};
|
||||
|
||||
const DEFAULT_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
|
||||
const filename = String(stream.requestUrl as URL)
|
||||
.split("/")
|
||||
.pop()!;
|
||||
return stream.pipe(fs.createWriteStream(path.join(dest, filename)));
|
||||
};
|
||||
|
||||
const EXTRACTOR_MAP: Record<string, Extractor> = {
|
||||
".zip": ZIP_EXTRACTOR,
|
||||
".gz": QZ_EXTRACTOR,
|
||||
"": DEFAULT_EXTRACTOR,
|
||||
};
|
||||
|
||||
class ProgressBar {
|
||||
private multiBar: progress.MultiBar = new progress.MultiBar(
|
||||
{
|
||||
stopOnComplete: true,
|
||||
},
|
||||
progress.Presets.shades_classic,
|
||||
);
|
||||
|
||||
handle(request: Request): Request {
|
||||
const bar = this.multiBar.create(0, 0);
|
||||
return request
|
||||
.on("request", (request: Request) => {
|
||||
bar.start(1, 0);
|
||||
})
|
||||
.on("downloadProgress", (progress: Progress) => {
|
||||
if (progress.total) {
|
||||
bar.setTotal(progress.total);
|
||||
}
|
||||
bar.update(progress.transferred);
|
||||
if (progress.total === progress.transferred) {
|
||||
bar.render();
|
||||
bar.stop();
|
||||
this.multiBar.remove(bar);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const progressBar = new ProgressBar();
|
||||
|
||||
export const download = async (url: string, dest: string, options?: DownloadOptions): Promise<void> => {
|
||||
options = { ...DEFAULT_OPTIONS, ...options };
|
||||
fse.ensureDirSync(dest);
|
||||
let stream: Request = got.stream(url);
|
||||
if (options.progress) {
|
||||
stream = progressBar.handle(stream);
|
||||
}
|
||||
const ext = path.extname(url);
|
||||
const extractor = EXTRACTOR_MAP[ext] || EXTRACTOR_MAP[""];
|
||||
return ps.wait(extractor(stream, dest, options));
|
||||
};
|
||||
|
||||
export default download;
|
||||
|
||||
+15
-9
@@ -1,19 +1,25 @@
|
||||
import path from "path";
|
||||
|
||||
export class Env {
|
||||
static set(key: string, value: string) {
|
||||
process.env[key] = value;
|
||||
constructor(private target: Record<string, string | undefined>) {}
|
||||
|
||||
set(key: string, value: string) {
|
||||
this.target[key] = value;
|
||||
}
|
||||
|
||||
static get(key: string) {
|
||||
return process.env[key];
|
||||
get(key: string) {
|
||||
return this.target[key];
|
||||
}
|
||||
|
||||
static addPath(value: string, key = "PATH") {
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
} else if (process.env[key].split(path.delimiter).indexOf(value) === -1) {
|
||||
process.env[key] = [process.env[key], value].join(path.delimiter);
|
||||
addPath(value: string, key: string = "PATH") {
|
||||
if (!this.target[key]) {
|
||||
this.target[key] = value;
|
||||
} else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
|
||||
this.target[key] = [this.target[key], value].join(path.delimiter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const env = new Env(process.env);
|
||||
|
||||
export default env;
|
||||
|
||||
+17
-5
@@ -1,10 +1,22 @@
|
||||
import async from "async";
|
||||
import async, { type ErrorCallback } from "async";
|
||||
import child_process from "child_process";
|
||||
import { Log } from "./log";
|
||||
import { Logger } from "./log";
|
||||
|
||||
const log = new Log("exec");
|
||||
const log = new Logger("exec");
|
||||
|
||||
const queue = async.queue((task: any, done: any) => {
|
||||
export interface Result {
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
interface Task {
|
||||
dir: string;
|
||||
command: string;
|
||||
success: (result: Result) => void;
|
||||
failure: (error: string) => void;
|
||||
}
|
||||
|
||||
const queue = async.queue((task: Task, done: ErrorCallback) => {
|
||||
log.d("*%s*", task.command);
|
||||
//process.chdir(task.dir);
|
||||
child_process.exec(task.command, { cwd: task.dir, maxBuffer: 1024 * 10000 }, (err, stdout, stderr) => {
|
||||
@@ -19,7 +31,7 @@ const queue = async.queue((task: any, done: any) => {
|
||||
});
|
||||
});
|
||||
|
||||
export default (dir: string, command: string) => {
|
||||
export default (dir: string, command: string): Promise<Result> => {
|
||||
return new Promise((success, failure) => {
|
||||
queue.push({
|
||||
dir: dir,
|
||||
|
||||
+57
-34
@@ -1,63 +1,86 @@
|
||||
import colors from "ansi-colors";
|
||||
|
||||
const Level = {
|
||||
VERBOSE: -1,
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
};
|
||||
export enum Level {
|
||||
VERBOSE = -1,
|
||||
DEBUG = 0,
|
||||
INFO = 1,
|
||||
WARNING = 2,
|
||||
ERROR = 3,
|
||||
}
|
||||
|
||||
const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
|
||||
export const DEFAULT_LEVEL: Level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
|
||||
|
||||
const formatTime = (date: Date): string => date.toTimeString().split(" ")[0];
|
||||
export type FormatPattern = [string, colors.StyleFunction];
|
||||
|
||||
export class Log {
|
||||
static level = level;
|
||||
static colorPatterns: [string, (m: string) => string][] = [
|
||||
["_", colors.cyan],
|
||||
["\\*", colors.magenta],
|
||||
["!", colors.red],
|
||||
];
|
||||
export const DEFAULT_PATTERNS: FormatPattern[] = [
|
||||
["_", colors.cyan],
|
||||
["\\*", colors.magenta],
|
||||
["!", colors.red],
|
||||
];
|
||||
|
||||
static colorize(pattern: string) {
|
||||
for (const item of this.colorPatterns) {
|
||||
export class Formatter {
|
||||
constructor(
|
||||
private patterns: FormatPattern[] = DEFAULT_PATTERNS,
|
||||
private time: boolean = true,
|
||||
) {}
|
||||
|
||||
colorize(text: string): string {
|
||||
for (const item of this.patterns) {
|
||||
const r = new RegExp(item[0] + "(.*?)" + item[0], "g");
|
||||
pattern = pattern.replace(r, item[1]("$1"));
|
||||
text = text.replace(r, item[1]("$1"));
|
||||
}
|
||||
return pattern;
|
||||
return text;
|
||||
}
|
||||
|
||||
static write(level: number, tag: string, pattern: string, args: any[]) {
|
||||
buildTime(): string {
|
||||
return new Date().toTimeString().split(" ")[0];
|
||||
}
|
||||
|
||||
format(message: string, tag: string, level: Level): string {
|
||||
const values = [];
|
||||
if (this.time) {
|
||||
values.push(`[${colors.gray(this.buildTime())}]`);
|
||||
}
|
||||
if (tag) {
|
||||
values.push(colors.green(tag));
|
||||
}
|
||||
values.push(this.colorize(message));
|
||||
return values.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_FORMATTER = new Formatter();
|
||||
|
||||
export class Logger {
|
||||
constructor(
|
||||
private tag: string,
|
||||
private level: Level = DEFAULT_LEVEL,
|
||||
private formatter: Formatter = DEFAULT_FORMATTER,
|
||||
) {}
|
||||
|
||||
write(level: Level, message: string, args: any[]) {
|
||||
if (level >= this.level) {
|
||||
const message = `[${colors.gray(formatTime(new Date()))}] ${colors.green(tag)} ${this.colorize(pattern)}`;
|
||||
console.log(message, ...args);
|
||||
console.log(this.formatter.format(message, this.tag, level), ...args);
|
||||
}
|
||||
}
|
||||
|
||||
public tag: string;
|
||||
|
||||
constructor(tag: string) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
v(message: string, ...args: any) {
|
||||
Log.write(-1, this.tag, message, args);
|
||||
this.write(Level.VERBOSE, message, args);
|
||||
}
|
||||
|
||||
d(message: string, ...args: any) {
|
||||
Log.write(0, this.tag, message, args);
|
||||
this.write(Level.DEBUG, message, args);
|
||||
}
|
||||
|
||||
i(message: string, ...args: any) {
|
||||
Log.write(1, this.tag, message, args);
|
||||
this.write(Level.INFO, message, args);
|
||||
}
|
||||
|
||||
w(message: string, ...args: any) {
|
||||
Log.write(2, this.tag, message, args);
|
||||
this.write(Level.WARNING, message, args);
|
||||
}
|
||||
|
||||
e(message: string, ...args: any) {
|
||||
Log.write(3, this.tag, message, args);
|
||||
this.write(Level.ERROR, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import colors from "ansi-colors";
|
||||
import { Formatter, Level, Logger } from "./log";
|
||||
|
||||
export class OutputFormatter extends Formatter {
|
||||
private colorMap: Record<Level, colors.StyleFunction> = {
|
||||
[Level.VERBOSE]: colors.white,
|
||||
[Level.DEBUG]: colors.white,
|
||||
[Level.INFO]: colors.cyan,
|
||||
[Level.ERROR]: colors.red,
|
||||
[Level.WARNING]: colors.yellow,
|
||||
};
|
||||
|
||||
format(message: string, tag: string, level: Level): string {
|
||||
const color = this.colorMap[level];
|
||||
if (message[0] === "\t" || message.startsWith("Called from ")) {
|
||||
return color(message);
|
||||
} else {
|
||||
const result = message.split(" ");
|
||||
return colors.gray(result.slice(0, 4).join(" ")) + " " + color(result.slice(4).join(" "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_OUTPUT_FORMATTER = new OutputFormatter();
|
||||
|
||||
export class OutputLogger extends Logger {
|
||||
private levelMap: Record<string, Level> = {
|
||||
"[DEBUG]": Level.DEBUG,
|
||||
"[INFO]": Level.INFO,
|
||||
"[ERROR]": Level.ERROR,
|
||||
"Called from ": Level.ERROR,
|
||||
"[WARNING]": Level.WARNING,
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super("", Level.VERBOSE, DEFAULT_OUTPUT_FORMATTER);
|
||||
}
|
||||
|
||||
detectLevel(line: string): number {
|
||||
for (const [tag, color] of Object.entries(this.levelMap)) {
|
||||
if (line.indexOf(tag) > -1) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return Level.DEBUG;
|
||||
}
|
||||
|
||||
log(line: string) {
|
||||
this.write(this.detectLevel(line), line, []);
|
||||
}
|
||||
}
|
||||
|
||||
export const OUTPUT_LOGGER = new OutputLogger();
|
||||
|
||||
export const output = (line: string) => OUTPUT_LOGGER.log(line);
|
||||
|
||||
export default output;
|
||||
@@ -7,7 +7,7 @@ const __dirname = path.dirname(__filename);
|
||||
|
||||
export default new Eta({
|
||||
autoFilter: true,
|
||||
filterFunction: (val: unknown): string => (val === null ? "" : String(val)),
|
||||
filterFunction: (val: unknown): string => (val === null || val === undefined ? "" : String(val)),
|
||||
useWith: true,
|
||||
views: path.join(__dirname, "..", "template"),
|
||||
views: path.join(__dirname, "template"),
|
||||
});
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@ class BufferingTransform extends Transform {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
export class TailVinyl extends Vinyl {
|
||||
|
||||
export class TailVinyl extends Vinyl<BufferingTransform> {
|
||||
private tail?: Tail;
|
||||
|
||||
constructor(params: WatchParams) {
|
||||
|
||||
+87
-122
@@ -1,134 +1,99 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import asset from "../common/asset";
|
||||
import { BuildSystem, type Config, type ConfigSource } from "./type";
|
||||
|
||||
export interface ConfigParams {
|
||||
name?: string;
|
||||
main?: string;
|
||||
preloader?: string;
|
||||
sources?: string[];
|
||||
assets?: string[];
|
||||
libs?: LibDef[] | Record<string, string>;
|
||||
macros?: string[];
|
||||
flags?: string[];
|
||||
meta?: ConfigMeta;
|
||||
key?: SignKey;
|
||||
android?: AndroidPreset[];
|
||||
}
|
||||
export const DEFAULT_ICON = asset("icon.jpg");
|
||||
|
||||
export interface ConfigMeta {
|
||||
title?: string;
|
||||
filename?: string;
|
||||
icon?: string;
|
||||
version?: string;
|
||||
pack?: string;
|
||||
author?: string;
|
||||
company?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
mobileWidth?: number;
|
||||
mobileHeight?: number;
|
||||
fps?: number;
|
||||
}
|
||||
export const DEFAULT_CONFIG: Config = {
|
||||
buildSystem: BuildSystem.HAXE,
|
||||
platforms: [],
|
||||
name: "",
|
||||
main: "",
|
||||
preloader: null,
|
||||
sources: [],
|
||||
assets: [],
|
||||
libs: [],
|
||||
macros: [],
|
||||
flags: [],
|
||||
icon: DEFAULT_ICON,
|
||||
meta: {
|
||||
width: 800,
|
||||
height: 600,
|
||||
fps: 60,
|
||||
},
|
||||
key: null,
|
||||
android: [],
|
||||
haxe: null,
|
||||
};
|
||||
|
||||
export interface LibDef {
|
||||
name: string;
|
||||
version: string;
|
||||
git?: string;
|
||||
branch?: string;
|
||||
}
|
||||
export const absolutePath = (file: string): string => {
|
||||
const result = path.resolve(process.cwd(), path.normalize(file));
|
||||
return os.type() === "Windows_NT" ? result.split("\\").join("/") : result;
|
||||
};
|
||||
|
||||
export interface AndroidPreset {
|
||||
path: string;
|
||||
extensions: string[];
|
||||
}
|
||||
export const compile = (source: ConfigSource): Config => {
|
||||
return branch(DEFAULT_CONFIG, source);
|
||||
};
|
||||
|
||||
export interface SignKey {
|
||||
store: string;
|
||||
pass: string;
|
||||
}
|
||||
export const branch = (config: Config, source: ConfigSource): Config => {
|
||||
const result = structuredClone(config);
|
||||
|
||||
export class Config {
|
||||
public name: string;
|
||||
public main: string;
|
||||
public preloader: string | null;
|
||||
public sources: string[];
|
||||
public assets: string[];
|
||||
public libs: LibDef[];
|
||||
public macros: string[];
|
||||
public flags: string[];
|
||||
public icon: string | null;
|
||||
public meta: ConfigMeta;
|
||||
public key: SignKey | null;
|
||||
public android: AndroidPreset[];
|
||||
|
||||
private _params: ConfigParams[];
|
||||
|
||||
constructor(params?: ConfigParams) {
|
||||
this._params = [];
|
||||
this.name = "";
|
||||
this.main = "";
|
||||
this.preloader = null;
|
||||
this.sources = [];
|
||||
this.assets = [];
|
||||
this.libs = [];
|
||||
this.macros = [];
|
||||
this.flags = [];
|
||||
this.icon = null;
|
||||
this.meta = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
fps: 60,
|
||||
};
|
||||
this.key = null;
|
||||
this.android = [];
|
||||
if (params) {
|
||||
this.update(params);
|
||||
this.afterUpdate();
|
||||
}
|
||||
if (source.buildSystem !== undefined) {
|
||||
result.buildSystem = source.buildSystem;
|
||||
}
|
||||
if (source.platforms !== undefined) {
|
||||
result.platforms = result.platforms.concat(source.platforms);
|
||||
}
|
||||
if (source.name !== undefined) {
|
||||
result.name = source.name;
|
||||
}
|
||||
if (source.main !== undefined) {
|
||||
result.main = source.main;
|
||||
}
|
||||
if (source.preloader !== undefined) {
|
||||
result.preloader = source.preloader;
|
||||
}
|
||||
if (source.sources !== undefined) {
|
||||
result.sources = result.sources.concat(source.sources.map(absolutePath));
|
||||
}
|
||||
if (source.assets !== undefined) {
|
||||
result.assets = result.assets.concat(source.assets.map(absolutePath));
|
||||
}
|
||||
if (source.libs !== undefined) {
|
||||
result.libs = result.libs.concat(
|
||||
Array.isArray(source.libs) ? source.libs : Object.entries(source.libs).map(([k, v]) => ({ name: k, version: v })),
|
||||
);
|
||||
}
|
||||
if (source.macros !== undefined) {
|
||||
result.macros = result.macros.concat(source.macros);
|
||||
}
|
||||
if (source.flags !== undefined) {
|
||||
result.flags = result.flags.concat(source.flags);
|
||||
}
|
||||
if (source.meta !== undefined) {
|
||||
result.meta = { ...result.meta, ...source.meta };
|
||||
}
|
||||
if (source.key !== undefined) {
|
||||
result.key = source.key;
|
||||
}
|
||||
if (source.android !== undefined) {
|
||||
result.android = result.android.concat(
|
||||
source.android.map((item) => ({ path: absolutePath(item.path), extensions: item.extensions })),
|
||||
);
|
||||
}
|
||||
if (source.haxe !== undefined) {
|
||||
result.haxe = source.haxe;
|
||||
}
|
||||
if (result.meta.icon) {
|
||||
result.icon = absolutePath(result.meta.icon);
|
||||
}
|
||||
|
||||
static absolutePath(file: string): string {
|
||||
const result = path.resolve(process.cwd(), path.normalize(file));
|
||||
return os.type() === "Windows_NT" ? result.split("\\").join("/") : result;
|
||||
if (!result.meta.mobileWidth) {
|
||||
result.meta.mobileWidth = result.meta.width;
|
||||
}
|
||||
|
||||
update(params: ConfigParams) {
|
||||
this._params.push(params);
|
||||
if (params.name !== undefined) this.name = params.name;
|
||||
if (params.main !== undefined) this.main = params.main;
|
||||
if (params.preloader !== undefined) this.preloader = params.preloader;
|
||||
if (params.sources !== undefined) this.sources = this.sources.concat(params.sources.map(Config.absolutePath));
|
||||
if (params.assets !== undefined) this.assets = this.assets.concat(params.assets.map(Config.absolutePath));
|
||||
if (params.libs !== undefined)
|
||||
this.libs = this.libs.concat(
|
||||
Array.isArray(params.libs)
|
||||
? params.libs
|
||||
: Object.entries(params.libs).map(([k, v]) => ({ name: k, version: v })),
|
||||
);
|
||||
if (params.macros !== undefined) this.macros = this.macros.concat(params.macros);
|
||||
if (params.flags !== undefined) this.flags = this.flags.concat(params.flags);
|
||||
if (params.meta !== undefined) this.meta = { ...this.meta, ...params.meta };
|
||||
if (params.key !== undefined) this.key = params.key;
|
||||
if (params.android !== undefined)
|
||||
this.android = this.android.concat(
|
||||
params.android.map((item) => ({ path: Config.absolutePath(item.path), extensions: item.extensions })),
|
||||
);
|
||||
if (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
|
||||
if (!result.meta.mobileHeight && result.meta.mobileWidth) {
|
||||
result.meta.mobileHeight = Math.round(result.meta.mobileWidth / 2.222222222);
|
||||
}
|
||||
|
||||
afterUpdate() {
|
||||
if (this.meta.mobileWidth === null) this.meta.mobileWidth = this.meta.width;
|
||||
if (this.meta.mobileHeight === null && this.meta.mobileWidth)
|
||||
this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 2.222222222);
|
||||
}
|
||||
|
||||
branch(params: ConfigParams) {
|
||||
const result = new Config();
|
||||
for (const params of this._params) {
|
||||
result.update(params);
|
||||
}
|
||||
result.update(params);
|
||||
result.afterUpdate();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Downloader } from "../common/download";
|
||||
import { Log } from "../common/log";
|
||||
import download from "../common/download";
|
||||
import { Logger } from "../common/log";
|
||||
|
||||
export class Sdk {
|
||||
static _dir: string;
|
||||
@@ -20,12 +20,12 @@ export class Sdk {
|
||||
|
||||
public name: string;
|
||||
public version: string;
|
||||
public log: Log;
|
||||
public log: Logger;
|
||||
public path: string;
|
||||
|
||||
constructor(name: string, version: string) {
|
||||
this.name = name;
|
||||
this.log = new Log(name);
|
||||
this.log = new Logger(name);
|
||||
this.version = version;
|
||||
this.path = Sdk.path(name, version);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export class Sdk {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
this.log.i("download: *%s*", this.link);
|
||||
return Downloader.download(this.link, this.path, strip);
|
||||
return download(this.link, this.path, { strip });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+93
-14
@@ -1,15 +1,94 @@
|
||||
export const BuildSystem = {
|
||||
HAXE: "haxe",
|
||||
OPENFL: "openfl",
|
||||
ADOBE_AIR: "adobe_air",
|
||||
};
|
||||
export enum BuildSystem {
|
||||
HAXE = "haxe",
|
||||
OPENFL = "openfl",
|
||||
ADOBE_AIR = "adobe_air",
|
||||
}
|
||||
|
||||
export const Platform = {
|
||||
FLASH: "flash",
|
||||
HTML5: "html5",
|
||||
LINUX: "linux",
|
||||
WINDOWS: "windows",
|
||||
ANDROID: "android",
|
||||
NEKO: "neko",
|
||||
CPP: "cpp",
|
||||
};
|
||||
export enum Platform {
|
||||
FLASH = "flash",
|
||||
HTML5 = "html5",
|
||||
LINUX = "linux",
|
||||
WINDOWS = "windows",
|
||||
ANDROID = "android",
|
||||
NEKO = "neko",
|
||||
CPP = "cpp",
|
||||
}
|
||||
|
||||
export interface LibDef {
|
||||
name: string;
|
||||
version: string;
|
||||
git?: string;
|
||||
branch?: string;
|
||||
}
|
||||
|
||||
export interface ConfigMeta {
|
||||
title?: string;
|
||||
filename?: string;
|
||||
icon?: string;
|
||||
version?: string;
|
||||
pack?: string;
|
||||
author?: string;
|
||||
company?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
mobileWidth?: number;
|
||||
mobileHeight?: number;
|
||||
fps?: number;
|
||||
}
|
||||
|
||||
export interface AndroidPreset {
|
||||
path: string;
|
||||
extensions: string[];
|
||||
}
|
||||
|
||||
export interface SignKey {
|
||||
store: string;
|
||||
pass: string;
|
||||
}
|
||||
|
||||
export interface ConfigSource {
|
||||
buildSystem?: BuildSystem;
|
||||
platforms?: Platform[];
|
||||
name?: string;
|
||||
main?: string;
|
||||
preloader?: string;
|
||||
sources?: string[];
|
||||
assets?: string[];
|
||||
libs?: LibDef[] | Record<string, string>;
|
||||
macros?: string[];
|
||||
flags?: string[];
|
||||
meta?: ConfigMeta;
|
||||
key?: SignKey;
|
||||
android?: AndroidPreset[];
|
||||
haxe?: string;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
buildSystem: BuildSystem;
|
||||
platforms: Platform[];
|
||||
name: string;
|
||||
main: string;
|
||||
preloader: string | null;
|
||||
sources: string[];
|
||||
assets: string[];
|
||||
libs: LibDef[];
|
||||
macros: string[];
|
||||
flags: string[];
|
||||
icon: string | null;
|
||||
meta: ConfigMeta;
|
||||
key: SignKey | null;
|
||||
android: AndroidPreset[];
|
||||
haxe: string | null;
|
||||
}
|
||||
|
||||
export type PackageJson = Record<string, any>;
|
||||
|
||||
export interface ConfigJson {
|
||||
SdkDir?: string;
|
||||
BuildDir?: string;
|
||||
Develop?: boolean;
|
||||
UseRuffle?: boolean;
|
||||
Key?: SignKey;
|
||||
}
|
||||
|
||||
export type PresetJson = Record<string, ConfigSource>;
|
||||
|
||||
+10
-9
@@ -2,8 +2,8 @@ import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Downloader } from "../common/download";
|
||||
import { Env } from "../common/env";
|
||||
import download from "../common/download";
|
||||
import env from "../common/env";
|
||||
import exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import { HandlerWriter } from "../common/tail";
|
||||
@@ -17,7 +17,8 @@ export class Android extends Sdk {
|
||||
static VERSION = Android.VERSION_7302050;
|
||||
|
||||
static NDK_VERSION_R15C = "r15c";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R15C;
|
||||
static NDK_VERSION_R21E = "r21e";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R21E;
|
||||
|
||||
private ndk_version: string;
|
||||
private repository: string;
|
||||
@@ -45,7 +46,7 @@ export class Android extends Sdk {
|
||||
}
|
||||
|
||||
get ndk_home(): string {
|
||||
return path.join(this.path, "ndk-bundle");
|
||||
return Sdk.path('android-ndk', this.ndk_version);
|
||||
}
|
||||
|
||||
get sdkmanager_bin(): string {
|
||||
@@ -62,10 +63,10 @@ export class Android extends Sdk {
|
||||
}
|
||||
|
||||
prepare_ndk(): Promise<any> {
|
||||
// ToDo: support windows
|
||||
// TODO: support windows
|
||||
const url = `${this.repository}/android-ndk-${this.ndk_version}-${System.os}-x86_64.zip`;
|
||||
this.log.d("download: *%s*", url);
|
||||
return Downloader.download(url, this.ndk_home, 1, true);
|
||||
return download(url, this.ndk_home, { executable: true });
|
||||
}
|
||||
|
||||
sdkmanager(packages: string[]) {
|
||||
@@ -101,9 +102,9 @@ export class Android extends Sdk {
|
||||
}
|
||||
|
||||
activate() {
|
||||
Env.set("ANDROID_HOME", this.android_home);
|
||||
Env.set("ANDROID_NDK_HOME", this.ndk_home);
|
||||
Env.set("NDK_HOME", this.ndk_home);
|
||||
env.set("ANDROID_HOME", this.android_home);
|
||||
env.set("ANDROID_NDK_HOME", this.ndk_home);
|
||||
env.set("NDK_HOME", this.ndk_home);
|
||||
}
|
||||
|
||||
get adbBin(): string {
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import env from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { watch } from "../common/watch";
|
||||
import { Sdk } from "../core/sdk";
|
||||
@@ -31,7 +31,7 @@ export class FlashPlayer extends Sdk {
|
||||
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
|
||||
super(playerId, version || FlashPlayer.VERSION);
|
||||
this.debug = debug;
|
||||
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL;
|
||||
this.baseUrl = env.get("FLASHPLAYER_URL") || this.BASE_URL;
|
||||
}
|
||||
|
||||
prepare() {
|
||||
|
||||
+37
-26
@@ -4,12 +4,13 @@ import rename from "gulp-rename";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import vfs from "vinyl-fs";
|
||||
import { Env } from "../common/env";
|
||||
import env from "../common/env";
|
||||
import exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import template from "../common/template";
|
||||
import type { Config, LibDef } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import type { Config, LibDef } from "../core/type";
|
||||
import { Platform } from "../core/type";
|
||||
import { Neko } from "./neko";
|
||||
|
||||
export class Haxe extends Sdk {
|
||||
@@ -25,7 +26,9 @@ export class Haxe extends Sdk {
|
||||
static VERSION_4_0_2 = "4.0.2";
|
||||
static VERSION_4_0_3 = "4.0.3";
|
||||
static VERSION_4_0_5 = "4.0.5";
|
||||
static VERSION_4 = Haxe.VERSION_4_0_5;
|
||||
static VERSION_4_2_5 = "4.2.5";
|
||||
static VERSION_4_3_7 = "4.3.7";
|
||||
static VERSION_4 = Haxe.VERSION_4_2_5;
|
||||
static VERSION = Haxe.VERSION_4;
|
||||
|
||||
static buildDir = path.join(process.cwd(), "build");
|
||||
@@ -68,17 +71,17 @@ export class Haxe extends Sdk {
|
||||
|
||||
activate() {
|
||||
this.neko.activate();
|
||||
Env.set("HAXE_VERSION", this.version);
|
||||
Env.set("HAXE_STD_PATH", path.join(this.path, "std"));
|
||||
Env.set("HAXE_HOME", this.path);
|
||||
Env.addPath(this.path);
|
||||
Env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
env.set("HAXE_VERSION", this.version);
|
||||
env.set("HAXE_STD_PATH", path.join(this.path, "std"));
|
||||
env.set("HAXE_HOME", this.path);
|
||||
env.addPath(this.path);
|
||||
env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
|
||||
fs.copyFileSync(
|
||||
path.resolve(import.meta.dirname, "..", "template/haxe/activate"),
|
||||
path.resolve(import.meta.dirname, "template/haxe/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
@@ -109,7 +112,7 @@ export class Haxe extends Sdk {
|
||||
return path.join(Haxe.buildDir, config.name);
|
||||
}
|
||||
|
||||
openfl(command: string, platform: string, config: Config, debug = false) {
|
||||
openfl(command: string, platform: Platform, config: Config, debug = false) {
|
||||
this.log.i("_openfl_ _build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
@@ -125,35 +128,41 @@ export class Haxe extends Sdk {
|
||||
const target = path.resolve(buildDir, platform, "bin");
|
||||
fse.emptyDirSync(target);
|
||||
const result =
|
||||
{
|
||||
android: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
|
||||
flash: "*.swf",
|
||||
}[platform] || "**/*";
|
||||
(
|
||||
{
|
||||
[Platform.ANDROID]: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
|
||||
[Platform.FLASH]: "*.swf",
|
||||
} as Record<Platform, string>
|
||||
)[platform] || "**/*";
|
||||
return this.haxelib(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "android") {
|
||||
if (platform === Platform.ANDROID) {
|
||||
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
build(platform: string, config: Config, debug = false) {
|
||||
build(platform: Platform, config: Config, debug = false) {
|
||||
this.log.i("_build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const ext =
|
||||
{
|
||||
flash: ".swf",
|
||||
neko: ".n",
|
||||
}[platform] || "";
|
||||
(
|
||||
{
|
||||
[Platform.FLASH]: ".swf",
|
||||
[Platform.NEKO]: ".n",
|
||||
} as Record<Platform, string>
|
||||
)[platform] || "";
|
||||
|
||||
const out =
|
||||
{
|
||||
flash: "swf",
|
||||
}[platform] || platform;
|
||||
(
|
||||
{
|
||||
[Platform.FLASH]: "swf",
|
||||
} as Record<Platform, string>
|
||||
)[platform] || platform;
|
||||
|
||||
const project = template.render("project.hxml", {
|
||||
...config,
|
||||
@@ -177,9 +186,11 @@ export class Haxe extends Sdk {
|
||||
fse.copySync(asset, path.join(target, asset.split("/").pop()!));
|
||||
}
|
||||
const result =
|
||||
{
|
||||
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
|
||||
}[platform] || "**/*";
|
||||
(
|
||||
{
|
||||
[Platform.CPP]: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
|
||||
} as Record<Platform, string>
|
||||
)[platform] || "**/*";
|
||||
return this.haxe(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "cpp") {
|
||||
|
||||
@@ -4,8 +4,8 @@ import os from "os";
|
||||
import path from "path";
|
||||
import exec from "../common/exec";
|
||||
import template from "../common/template";
|
||||
import type { Config } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import type { Config } from "../core/type";
|
||||
|
||||
export class InnoSetup extends Sdk {
|
||||
static ID = "innosetup";
|
||||
|
||||
+8
-6
@@ -1,7 +1,7 @@
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import env from "../common/env";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run/index";
|
||||
|
||||
@@ -44,7 +44,9 @@ export class Neko extends Sdk {
|
||||
static ID = "neko";
|
||||
|
||||
static VERSION_2_2_0 = "2.2.0";
|
||||
static VERSION = Neko.VERSION_2_2_0;
|
||||
static VERSION_2_4_0 = "2.4.0";
|
||||
static VERSION_2_4_1 = "2.4.1";
|
||||
static VERSION = Neko.VERSION_2_4_1;
|
||||
|
||||
constructor(version?: string) {
|
||||
super(Neko.ID, version || Neko.VERSION);
|
||||
@@ -63,15 +65,15 @@ export class Neko extends Sdk {
|
||||
}
|
||||
|
||||
activate() {
|
||||
Env.set("NEKO_INSTPATH", this.path);
|
||||
Env.addPath(this.path);
|
||||
Env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
env.set("NEKO_INSTPATH", this.path);
|
||||
env.addPath(this.path);
|
||||
env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([super.prepare()]).then(() => {
|
||||
fs.copyFileSync(
|
||||
path.resolve(import.meta.dirname, "..", "template/neko/activate"),
|
||||
path.resolve(import.meta.dirname, "template/neko/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import env from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { watch } from "../common/watch";
|
||||
import run from "../run";
|
||||
@@ -14,13 +14,13 @@ export class RufflePlayer extends FlashPlayer {
|
||||
static VERSION_0_5_0 = "0.5.0";
|
||||
static VERSION_0_6_0 = "0.6.0";
|
||||
static VERSION_0_7_1 = "0.7.1";
|
||||
static VERSION = RufflePlayer.VERSION_2026_10_13;
|
||||
static VERSION = RufflePlayer.VERSION_0_7_1;
|
||||
|
||||
BASE_URL = "https://github.com/ruffle-rs/ruffle/releases/download";
|
||||
|
||||
constructor(debug: boolean, version: string) {
|
||||
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
|
||||
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL;
|
||||
this.baseUrl = env.get("RUFFLE_URL") || this.BASE_URL;
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
|
||||
+4
-2
@@ -1,6 +1,8 @@
|
||||
export * from "./common/download";
|
||||
export * from "./common/log";
|
||||
export * from "./common/output";
|
||||
export * from "./common/system";
|
||||
export * from "./core/config";
|
||||
export * from "./common/download";
|
||||
export * from "./core/sdk";
|
||||
export * from "./core/type";
|
||||
export * from "./impl/android";
|
||||
@@ -9,6 +11,6 @@ export * from "./impl/haxe";
|
||||
export * from "./impl/innosetup";
|
||||
export * from "./impl/neko";
|
||||
export * from "./impl/ruffle";
|
||||
export * from "./preset";
|
||||
export * from "./project";
|
||||
export * from "./project/impl";
|
||||
export * from "./project/preset";
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { branch, compile } from "../core/config";
|
||||
import type { Config, PresetJson } from "../core/type";
|
||||
import { Project } from "../project";
|
||||
|
||||
export default (preset: PresetJson): Project[] => {
|
||||
const config: Config = compile(preset["default"] || {});
|
||||
const projects: Project[] = [];
|
||||
for (const [k, v] of Object.entries(preset)) {
|
||||
if (k == "default") {
|
||||
continue;
|
||||
}
|
||||
const projectConfig = branch(config, { ...v, name: k });
|
||||
projects.push(new Project(projectConfig));
|
||||
}
|
||||
return projects;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import compiler from "./compiler";
|
||||
import loader from "./loader";
|
||||
import register from "./register";
|
||||
import validator from "./validator";
|
||||
|
||||
export const Preset = {
|
||||
compiler,
|
||||
loader,
|
||||
register,
|
||||
validator,
|
||||
};
|
||||
|
||||
export default Preset;
|
||||
@@ -0,0 +1,63 @@
|
||||
import dateformat from "dateformat";
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import template from "../common/template";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import type { ConfigJson, ConfigSource, PackageJson, PresetJson } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Project } from "../project";
|
||||
|
||||
export const DEFAULT_CONFIG_JSON: ConfigJson = {
|
||||
SdkDir: "$HOME/sdk",
|
||||
};
|
||||
|
||||
export const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
|
||||
|
||||
export const applyConfig = (config: ConfigJson) => {
|
||||
if (config.UseRuffle) {
|
||||
Project.useRuffle();
|
||||
}
|
||||
if (config.SdkDir) {
|
||||
Sdk.dir = resolvePath(config.SdkDir);
|
||||
}
|
||||
if (config.BuildDir) {
|
||||
Haxe.buildDir = resolvePath(config.BuildDir);
|
||||
}
|
||||
};
|
||||
|
||||
export default (basedir: string = "."): PresetJson => {
|
||||
const presetFile = path.join(basedir, "haxetool.json");
|
||||
const configFile = path.join(basedir, "config.json");
|
||||
const packageFile = path.join(basedir, "package.json");
|
||||
const presetJson: PresetJson = JSON.parse(fs.readFileSync(presetFile, "utf8"));
|
||||
const configJson: ConfigJson = {
|
||||
...DEFAULT_CONFIG_JSON,
|
||||
...(fs.existsSync(configFile) ? JSON.parse(fs.readFileSync(configFile, "utf8")) : {}),
|
||||
};
|
||||
applyConfig(configJson);
|
||||
const packageJson: PackageJson = fs.existsSync(packageFile) ? JSON.parse(fs.readFileSync(packageFile, "utf8")) : {};
|
||||
for (const [k, v] of Object.entries(presetJson)) {
|
||||
presetJson[k] = JSON.parse(
|
||||
template.renderString(JSON.stringify(v), {
|
||||
config: configJson,
|
||||
package: packageJson,
|
||||
env: process.env,
|
||||
dateformat: dateformat,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const defaultConfig: ConfigSource = presetJson["default"] || {};
|
||||
defaultConfig.meta = {
|
||||
...{
|
||||
title: packageJson.name,
|
||||
filename: packageJson.name,
|
||||
version: packageJson.version,
|
||||
pack: `com.${packageJson.name}`,
|
||||
author: packageJson.author as string,
|
||||
},
|
||||
...(defaultConfig.meta || {}),
|
||||
};
|
||||
presetJson["default"] = defaultConfig;
|
||||
return presetJson;
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
import gulp from "gulp";
|
||||
import gulpClean from "gulp-clean";
|
||||
import type { Task } from "undertaker";
|
||||
import { System } from "../common/system";
|
||||
import { Platform } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Builder, type Project } from "../project";
|
||||
|
||||
export default (projects: Project[]): Task => {
|
||||
gulp.task("clean", () => {
|
||||
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||
});
|
||||
|
||||
const project = projects[0];
|
||||
|
||||
gulp.task("setup", () => {
|
||||
return Promise.all(
|
||||
project.config.platforms.map((platform) =>
|
||||
Builder.new(project.config, platform, project.config.buildSystem).prepare(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
const protohx = project.hasLib("protohx");
|
||||
if (protohx) {
|
||||
gulp.task("protohx:generate", () =>
|
||||
new Haxe().haxelib(["run", "protohx", "generate", "protohx.json"]).then((result: any) => {
|
||||
if (result.stdout.indexOf("FAIL") > -1) {
|
||||
throw result.stdout;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
project.register(gulp);
|
||||
}
|
||||
|
||||
const defaultSeries: Task[] = [gulp.task("clean")!, gulp.task("setup")!];
|
||||
|
||||
if (protohx) {
|
||||
defaultSeries.push(gulp.task("protohx:generate")!);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
for (const platform of project.config.platforms) {
|
||||
switch (platform) {
|
||||
case Platform.FLASH:
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:html`)!);
|
||||
break;
|
||||
case Platform.HTML5:
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
break;
|
||||
case Platform.LINUX:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:deb`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.CPP:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.NEKO:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.ANDROID:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.WINDOWS:
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:installer`)!);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultTask = gulp.series(defaultSeries);
|
||||
gulp.task("default", defaultTask);
|
||||
return defaultTask;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import Ajv from "ajv";
|
||||
import fs from "fs";
|
||||
import asset from "../common/asset";
|
||||
import type { PresetJson } from "../core/type";
|
||||
|
||||
export default (preset: PresetJson) => {
|
||||
const ajv = new Ajv();
|
||||
const presetSchema = ajv.compile(JSON.parse(fs.readFileSync(asset("haxetool.schema.json"), "utf-8")));
|
||||
const valid = presetSchema(preset);
|
||||
if (!valid) {
|
||||
throw presetSchema.errors;
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Config } from "../../core/config";
|
||||
import { BuildSystem, type Config, Platform } from "../../core/type";
|
||||
import { Target } from "./target";
|
||||
|
||||
export class Builder extends Target {
|
||||
@@ -7,7 +7,7 @@ export class Builder extends Target {
|
||||
public buildSystem: string;
|
||||
public debug: boolean;
|
||||
|
||||
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
|
||||
constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
|
||||
super(config, platform);
|
||||
this.buildSystem = buildSystem;
|
||||
this.debug = debug;
|
||||
@@ -17,7 +17,7 @@ export class Builder extends Target {
|
||||
Builder.factory[buildSystem] = builder;
|
||||
}
|
||||
|
||||
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder {
|
||||
static new(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false): Builder {
|
||||
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import type { Config } from "../../core/config";
|
||||
import { type Config, Platform } from "../../core/type";
|
||||
import { Target } from "./target";
|
||||
|
||||
export type PackerFactory = new (config: Config) => Packer;
|
||||
|
||||
export class Packer extends Target {
|
||||
static factory: Record<string, Record<string, PackerFactory>> = {};
|
||||
static factory: Partial<Record<Platform, Record<string, PackerFactory>>> = {};
|
||||
|
||||
call() {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
static register(platform: string, name: string, packer: PackerFactory) {
|
||||
static register(platform: Platform, name: string, packer: PackerFactory) {
|
||||
if (!Packer.factory[platform]) Packer.factory[platform] = {};
|
||||
Packer.factory[platform][name] = packer;
|
||||
}
|
||||
|
||||
static new(config: Config, platform: string, name: string): Packer {
|
||||
return new Packer.factory[platform][name](config);
|
||||
static new(config: Config, platform: Platform, name: string): Packer {
|
||||
return new Packer.factory[platform];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import gulp from "gulp";
|
||||
import rename from "gulp-rename";
|
||||
import { DEBUG } from "../../common/debug";
|
||||
import output from "../../common/output";
|
||||
import { tail } from "../../common/tail";
|
||||
import { Config } from "../../core/config";
|
||||
import { type Config, Platform } from "../../core/type";
|
||||
import { Target } from "./target";
|
||||
|
||||
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
|
||||
@@ -12,13 +12,13 @@ export class Runner extends Target {
|
||||
|
||||
public debug: boolean;
|
||||
|
||||
constructor(config: Config, platform: string, debug: boolean) {
|
||||
constructor(config: Config, platform: Platform, debug: boolean) {
|
||||
super(config, platform);
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
log(stream: any) {
|
||||
return stream.pipe(tail(DEBUG.log)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath));
|
||||
return stream.pipe(tail(output)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath));
|
||||
}
|
||||
|
||||
static register(platform: string, runner: RunnerFactory) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import path from "path";
|
||||
import type { Config } from "../../core/config";
|
||||
import { type Config, Platform } from "../../core/type";
|
||||
|
||||
export class Target {
|
||||
public config: Config;
|
||||
public platform: string;
|
||||
public platform: Platform;
|
||||
public target: string;
|
||||
|
||||
constructor(config: Config, platform: string) {
|
||||
constructor(config: Config, platform: Platform) {
|
||||
this.config = config;
|
||||
this.platform = platform;
|
||||
this.target = "target";
|
||||
@@ -20,7 +20,7 @@ export class Target {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
resolveTargetPath(platform = this.platform): string {
|
||||
resolveTargetPath(platform: Platform | string = this.platform): string {
|
||||
return path.resolve(this.target, this.config.name, platform);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import vfs from "vinyl-fs";
|
||||
import exec from "../../../common/exec";
|
||||
import { streamToPromise } from "../../../common/util";
|
||||
import { Config } from "../../../core/config";
|
||||
import { BuildSystem, Platform } from "../../../core/type";
|
||||
import { BuildSystem, type Config, Platform } from "../../../core/type";
|
||||
import { Android } from "../../../impl/android";
|
||||
import { Haxe } from "../../../impl/haxe";
|
||||
import { Builder } from "../../core/builder";
|
||||
@@ -11,14 +10,14 @@ export class HaxeBuilder extends Builder {
|
||||
public haxe: Haxe;
|
||||
public android: Android;
|
||||
|
||||
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
|
||||
constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
|
||||
super(config, platform, buildSystem, debug);
|
||||
this.haxe = new Haxe();
|
||||
this.haxe = new Haxe(config.haxe ? config.haxe : undefined);
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
|
||||
let result: Promise<any> = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
|
||||
if (this.buildSystem === BuildSystem.OPENFL) {
|
||||
if (this.platform === Platform.ANDROID) {
|
||||
result = result
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import template from "../../../common/template";
|
||||
import type { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import { Packer } from "../../core/packer";
|
||||
|
||||
export class FlashHTMLPacker extends Packer {
|
||||
@@ -16,7 +15,7 @@ export class FlashHTMLPacker extends Packer {
|
||||
const target = this.targetPath;
|
||||
const index = template.render("flash/index.html", this.config);
|
||||
fs.writeFileSync(path.resolve(target, "index.html"), index);
|
||||
fs.copyFileSync(path.resolve(import.meta.dirname, "..", "template/flash/swf.js"), path.resolve(target, "swf.js"));
|
||||
fs.copyFileSync(path.resolve(import.meta.dirname, "template/flash/swf.js"), path.resolve(target, "swf.js"));
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import gulp from "gulp";
|
||||
import gzip from "gulp-gzip";
|
||||
import tar from "gulp-tar";
|
||||
import type { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { type Config, Platform } from "../../../../core/type";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class LinuxArchivePacker extends Packer {
|
||||
|
||||
@@ -5,8 +5,7 @@ import deb from "gulp-debian";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import template from "../../../../common/template";
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { type Config, Platform } from "../../../../core/type";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class LinuxDEBPacker extends Packer {
|
||||
@@ -19,12 +18,13 @@ export class LinuxDEBPacker extends Packer {
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian");
|
||||
const iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`;
|
||||
const desktop = template.render("linux/app.desktop", Object.assign({ iconfile: iconfile }, this.config));
|
||||
const icon = this.config.meta.icon!;
|
||||
const iconfile = `${this.config.meta.filename}${path.extname(icon)}`;
|
||||
const desktop = template.render("linux/app.desktop", { iconfile: iconfile, ...this.config });
|
||||
fse.ensureDirSync(`${buildDir}/usr/share/applications`);
|
||||
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
|
||||
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
|
||||
fse.copySync(this.config.meta.icon!, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
|
||||
fse.copySync(icon, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
|
||||
return gulp.src(`${buildDir}/*`).pipe(
|
||||
deb({
|
||||
package: this.config.meta.filename!,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import gulp from "gulp";
|
||||
import zip from "gulp-zip";
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { type Config, Platform } from "../../../../core/type";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class WindowsArchivePacker extends Packer {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { type Config, Platform } from "../../../../core/type";
|
||||
import { InnoSetup } from "../../../../impl/innosetup";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import gulp from "gulp";
|
||||
import type { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import { Android } from "../../../impl/android";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import { FlashPlayer } from "../../../impl/flashplayer";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import connect from "gulp-connect";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class Html5Runner extends Runner {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import run from "../../../run";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import { Neko } from "../../../impl/neko";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Config } from "../../../core/config";
|
||||
import type { Config } from "../../../core/type";
|
||||
import { RufflePlayer } from "../../../impl/ruffle";
|
||||
import { FlashRunner } from "./flash";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { type Config, Platform } from "../../../core/type";
|
||||
import run from "../../../run";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
|
||||
+9
-19
@@ -1,27 +1,17 @@
|
||||
import gulp from "gulp";
|
||||
import type { Task, TaskFunction } from "undertaker";
|
||||
import { Config } from "../core/config";
|
||||
import { BuildSystem, Platform } from "../core/type";
|
||||
import { Platform, type Config } from "../core/type";
|
||||
import { Builder } from "./core/builder";
|
||||
import { Packer } from "./core/packer";
|
||||
import { Runner } from "./core/runner";
|
||||
import { RuffleRunner } from "./impl/runner/ruffle";
|
||||
export * from "./core";
|
||||
export * from "./impl";
|
||||
|
||||
export class Project {
|
||||
// TODO: compatibility
|
||||
static Config = Config;
|
||||
static BuildSystem = BuildSystem;
|
||||
static Platform = Platform;
|
||||
static Builder = Builder;
|
||||
|
||||
public buildSystem: string;
|
||||
public platforms: string[];
|
||||
public config: Config;
|
||||
|
||||
constructor(buildSystem: string, platforms: string[] | string, config: Config) {
|
||||
this.buildSystem = buildSystem;
|
||||
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
|
||||
constructor(config: Config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -34,23 +24,23 @@ export class Project {
|
||||
return false;
|
||||
}
|
||||
|
||||
build(platform: string, debug: boolean = false): Task[] {
|
||||
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
|
||||
build(platform: Platform, debug: boolean = false): Task[] {
|
||||
const builder = Builder.new(this.config, platform, this.config.buildSystem, debug);
|
||||
const tasks: Task[] = [builder.prepare.bind(builder)];
|
||||
tasks.push(builder.call.bind(builder));
|
||||
return tasks;
|
||||
}
|
||||
|
||||
run(platform: string, debug: boolean = false): Task[] {
|
||||
run(platform: Platform, debug: boolean = false): Task[] {
|
||||
const runner = Runner.new(this.config, platform, debug);
|
||||
return [runner.prepare.bind(runner), runner.call.bind(runner)];
|
||||
}
|
||||
|
||||
test(platform: string, debug: boolean = true): Task[] {
|
||||
test(platform: Platform, debug: boolean = true): Task[] {
|
||||
return this.build(platform, debug).concat(this.run(platform, debug));
|
||||
}
|
||||
|
||||
pack(platform: string, name: string) {
|
||||
pack(platform: Platform, name: string) {
|
||||
const packer = Packer.new(this.config, platform, name);
|
||||
return [packer.prepare.bind(packer), packer.call.bind(packer)];
|
||||
}
|
||||
@@ -58,7 +48,7 @@ export class Project {
|
||||
compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
|
||||
const result: Record<string, TaskFunction> = {};
|
||||
const _gulp = external_gulp || gulp;
|
||||
for (const platform of this.platforms) {
|
||||
for (const platform of this.config.platforms) {
|
||||
result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
|
||||
if (Runner.factory[platform]) {
|
||||
result[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
import dateformat from "dateformat";
|
||||
import gulp from "gulp";
|
||||
import gulpClean from "gulp-clean";
|
||||
import os from "os";
|
||||
import type { Task } from "undertaker";
|
||||
import { Builder, Project } from ".";
|
||||
import { System } from "../common/system";
|
||||
import template from "../common/template";
|
||||
import { Config, type ConfigParams, type SignKey } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Platform } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
|
||||
export interface PresetConfig {
|
||||
SdkDir?: string;
|
||||
BuildDir?: string;
|
||||
Develop?: boolean;
|
||||
UseRuffle?: boolean;
|
||||
Key?: SignKey;
|
||||
}
|
||||
|
||||
export const DEFAULT_CONFIG: PresetConfig = {
|
||||
SdkDir: "$HOME/sdk",
|
||||
};
|
||||
|
||||
export interface ProjectPreset {
|
||||
buildSystem?: string;
|
||||
platforms?: string[];
|
||||
config: ConfigParams;
|
||||
}
|
||||
|
||||
export class Preset {
|
||||
public options: Record<string, ProjectPreset>;
|
||||
public config: PresetConfig;
|
||||
public packageInfo: Record<string, any>;
|
||||
|
||||
constructor(options: Record<string, ProjectPreset>, config?: PresetConfig, packageInfo?: Record<string, any>) {
|
||||
this.config = Object.assign(DEFAULT_CONFIG, config || {});
|
||||
this.packageInfo = packageInfo || {};
|
||||
for (const [k, v] of Object.entries(options)) {
|
||||
options[k] = this.fillPreset(v);
|
||||
}
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
private fillPreset(preset: ProjectPreset): ProjectPreset {
|
||||
return JSON.parse(
|
||||
template.renderString(JSON.stringify(preset), {
|
||||
config: this.config,
|
||||
package: this.packageInfo,
|
||||
env: process.env,
|
||||
dateformat: dateformat,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
compile(): Project[] {
|
||||
const config = new Config(this.options["default"]?.config);
|
||||
if (this.packageInfo.haxeDependencies) {
|
||||
config.update({ libs: this.packageInfo.haxeDependencies });
|
||||
}
|
||||
const projects: Project[] = [];
|
||||
for (const [k, v] of Object.entries(this.options)) {
|
||||
if (k == "default") {
|
||||
continue;
|
||||
}
|
||||
const projectConfig = config.branch(Object.assign(v.config, { name: k }));
|
||||
projects.push(new Project(v.buildSystem!, v.platforms!, projectConfig));
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
register(external_gulp?: gulp.Gulp, additional_tasks?: string[]) {
|
||||
const _gulp = external_gulp || gulp;
|
||||
|
||||
const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
|
||||
|
||||
if (this.config.UseRuffle) {
|
||||
Project.useRuffle();
|
||||
}
|
||||
|
||||
if (this.packageInfo.haxe) {
|
||||
Haxe.VERSION = this.packageInfo.haxe;
|
||||
}
|
||||
|
||||
if (this.config.SdkDir) {
|
||||
Sdk.dir = resolvePath(this.config.SdkDir);
|
||||
}
|
||||
|
||||
if (this.config.BuildDir) {
|
||||
Haxe.buildDir = resolvePath(this.config.BuildDir);
|
||||
}
|
||||
|
||||
_gulp.task("clean", () => {
|
||||
return _gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||
});
|
||||
|
||||
const projects = this.compile();
|
||||
const project = projects[0];
|
||||
|
||||
_gulp.task("setup", () => {
|
||||
return Promise.all(
|
||||
project.platforms.map((platform) => Builder.new(project.config, platform, project.buildSystem).prepare()),
|
||||
);
|
||||
});
|
||||
|
||||
const protohx = project.hasLib("protohx");
|
||||
if (protohx) {
|
||||
_gulp.task("protohx:generate", () =>
|
||||
new Haxe().haxelib(["run", "protohx", "generate", "protohx.json"]).then((result: any) => {
|
||||
if (result.stdout.indexOf("FAIL") > -1) {
|
||||
throw result.stdout;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
project.register(_gulp);
|
||||
}
|
||||
|
||||
const defaultSeries: Task[] = [_gulp.task("clean")!, _gulp.task("setup")!];
|
||||
|
||||
if (protohx) {
|
||||
defaultSeries.push(_gulp.task("protohx:generate")!);
|
||||
}
|
||||
|
||||
if (additional_tasks) {
|
||||
for (const task of additional_tasks) {
|
||||
defaultSeries.push(_gulp.task(task)!);
|
||||
}
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
for (const platform of project.platforms) {
|
||||
switch (platform) {
|
||||
case Platform.FLASH:
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:html`)!);
|
||||
break;
|
||||
case Platform.HTML5:
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
break;
|
||||
case Platform.LINUX:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:deb`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.CPP:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.NEKO:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.ANDROID:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.WINDOWS:
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:installer`)!);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _gulp.series(defaultSeries);
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -14,12 +14,13 @@ export class Command {
|
||||
constructor(command: string, options?: any) {
|
||||
this.command = command;
|
||||
this.isWindows = process.platform.lastIndexOf("win") === 0;
|
||||
this.options = Object.assign(options || {}, {
|
||||
this.options = {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
verbosity: options && options.silent ? 1 : 2,
|
||||
verbosity: options?.silent ? 1 : 2,
|
||||
usePowerShell: false,
|
||||
});
|
||||
...(options || {}),
|
||||
};
|
||||
|
||||
let previousPath;
|
||||
previousPath = this.options.env.PATH;
|
||||
@@ -28,7 +29,7 @@ export class Command {
|
||||
this.options.env.PATH += previousPath;
|
||||
}
|
||||
|
||||
exec(stdin?: any, callback?: any) {
|
||||
exec(stdin?: any, callback?: any): Vinyl<stream.Stream> {
|
||||
let fileName;
|
||||
let directory;
|
||||
let subShell;
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
-D <%=item%><% }); %>
|
||||
|
||||
-main <%=main%>
|
||||
|
||||
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=meta.filename%><%=ext%>"
|
||||
|
||||
@@ -3,7 +3,7 @@ import { existsSync, mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
import { Downloader } from "../dist/index.mjs";
|
||||
import { download } from "../dist/lib/index.mjs";
|
||||
|
||||
const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
|
||||
|
||||
@@ -16,7 +16,7 @@ const TEST_DATA = {
|
||||
for (const [url, file] of Object.entries(TEST_DATA)) {
|
||||
test(`Test download: ${url}`, async () => {
|
||||
const target = resolveTargetDir();
|
||||
await Downloader.download(url, target);
|
||||
await download(url, target);
|
||||
assert(existsSync(join(target, file)));
|
||||
});
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,9 +1,18 @@
|
||||
import { defineConfig } from "tsdown";
|
||||
|
||||
export default defineConfig({
|
||||
entry: {
|
||||
"bin/cli": "src/cli.ts",
|
||||
"lib/index": "src/index.ts",
|
||||
},
|
||||
copy: ["assets", "template"],
|
||||
dts: {
|
||||
tsgo: true,
|
||||
},
|
||||
exports: true,
|
||||
exports: {
|
||||
bin: {
|
||||
hxt: "src/cli.ts",
|
||||
},
|
||||
},
|
||||
sourcemap: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user