Compare commits
24
Commits
0.1.5
..
1339ba0c98
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1339ba0c98 | ||
|
|
c63417cefa | ||
|
|
a25f223b61 | ||
|
|
84d905dbb3 | ||
|
|
a421d56ec1 | ||
|
|
079cf9d52d | ||
|
|
0edfb12473 | ||
|
|
c3c0b07d32 | ||
|
|
ec3d3b547c | ||
|
|
3f23c6973b | ||
|
|
dba24a2c68 | ||
|
|
78804036ab | ||
|
|
f735be8bf9 | ||
|
|
be54ce5d25 | ||
|
|
305681beaf | ||
|
|
f7df429e9d | ||
|
|
d0c5fbe8da | ||
|
|
7a11c858d1 | ||
|
|
961766a37c | ||
|
|
ca61b68cd9 | ||
|
|
715f6807d8 | ||
|
|
e0eddbcab5 | ||
|
|
1bd18caa9a | ||
|
|
90f1a9b77f |
@@ -0,0 +1,6 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
max_line_length = 120
|
||||
@@ -0,0 +1,20 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["*"]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: echo '' > requirements.txt
|
||||
- uses: https://git.shmyga.ru/InfernalGames/project-manager@master
|
||||
with:
|
||||
setup-nodejs: true
|
||||
- run: pm build -vv
|
||||
#- run: npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
|
||||
- run: npm publish --provenance --access public
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -0,0 +1,16 @@
|
||||
name: test
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: echo '' > requirements.txt
|
||||
- uses: https://git.shmyga.ru/InfernalGames/project-manager@master
|
||||
with:
|
||||
setup-nodejs: true
|
||||
- run: pm build -vv
|
||||
- run: pm lint -vv
|
||||
- run: pm test -vv
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
/.idea
|
||||
node_modules/
|
||||
target/
|
||||
package-lock.json
|
||||
*.iml
|
||||
dist/
|
||||
+20
-38
@@ -1,47 +1,29 @@
|
||||
0.1.5
|
||||
-----
|
||||
* Haxe: default version 4.0.5
|
||||
## v0.2.0 (2026-05-15)
|
||||
|
||||
0.1.4
|
||||
-----
|
||||
* Config: android extensions params
|
||||
### Feat
|
||||
|
||||
0.1.3
|
||||
-----
|
||||
* Android: installed packages list
|
||||
* Haxe: buildDir static property
|
||||
- **ruffle**: add alternative ruffle flash target runner
|
||||
|
||||
0.1.2
|
||||
-----
|
||||
* Haxe: move build dir from tmp to project dir
|
||||
## 0.1.9 (2021-05-24)
|
||||
|
||||
0.1.1
|
||||
-----
|
||||
* Android sign apk (config.key.store and config.key.pass params)
|
||||
### Feat
|
||||
|
||||
0.1.0
|
||||
------
|
||||
* Android build
|
||||
* Windows build
|
||||
* Windows innosetup packer
|
||||
- **android**: up android sdk version
|
||||
|
||||
0.0.18
|
||||
------
|
||||
* Add meta.fps project param
|
||||
## 0.1.8 (2020-03-30)
|
||||
|
||||
0.0.12
|
||||
-----
|
||||
* Openfl android platform support
|
||||
* Android sdk module
|
||||
## 0.1.7 (2020-03-25)
|
||||
|
||||
0.0.11
|
||||
------
|
||||
* Added Neko module
|
||||
* FlashPlayer output with stream
|
||||
* Verbose output mode (--verbose)
|
||||
## 0.1.6 (2020-02-19)
|
||||
|
||||
0.0.10
|
||||
------
|
||||
* Windows compatibility
|
||||
* Change FlashPlayer download link
|
||||
* Use 'fs-extra' without 'mkdirp' and 'rmdir'
|
||||
## 0.1.5 (2020-02-18)
|
||||
|
||||
## 0.1.0 (2019-09-03)
|
||||
|
||||
## 0.0.18 (2019-05-20)
|
||||
|
||||
## 0.0.17 (2019-03-28)
|
||||
|
||||
## 0.0.16 (2019-03-14)
|
||||
|
||||
## 0.0.15 (2019-03-14)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Gulp HaXe Tool
|
||||
|
||||
[](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions?workflow=test.yaml)
|
||||
|
||||
## Introducing
|
||||
|
||||
### Dignity
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const tmp = require('tmp-file');
|
||||
const exec = require('./exec');
|
||||
const gulp = require('gulp');
|
||||
const through = require('through2');
|
||||
//const mark = require('gulp-mark');
|
||||
//const replace = require('gulp-replace-task');
|
||||
const Sdk = require('./sdk');
|
||||
|
||||
|
||||
// ToDo: remove gutil
|
||||
class AdobeAir extends Sdk {
|
||||
|
||||
get adtBin() {
|
||||
return `${this.path}/bin/adt.bat`;
|
||||
}
|
||||
|
||||
get adlBin() {
|
||||
return `${this.path}/bin/adl.exe`;
|
||||
}
|
||||
|
||||
static buildAdtArgs(params, descriptor, keystore, files, output) {
|
||||
//const quote = (value) => `"${value}"`;
|
||||
const quote = (value) => value; // ToDo:
|
||||
const command = ['-package'];
|
||||
const target = params.target || 'native';
|
||||
if (target !== 'native') command.push('-target', target); //ToDo: adobe bleat' (target param position in native and apk-captive-runtime targets)
|
||||
if (params.useLegacyAOT) {
|
||||
command.push('-useLegacyAOT', 'yes');
|
||||
}
|
||||
if (params.profile) {
|
||||
command.push('-provisioning-profile', quote(params.profile));
|
||||
}
|
||||
if (keystore) {
|
||||
command.push('-storetype', 'PKCS12');
|
||||
command.push('-keystore', keystore.path);
|
||||
command.push('-storepass', keystore.storepass);
|
||||
}
|
||||
if (params.target === 'native') {
|
||||
command.push('-tsa', 'http://sha256timestamp.ws.symantec.com/sha256/timestamp');
|
||||
command.push('-target', target);
|
||||
}
|
||||
command.push(quote(output), quote(descriptor.path));
|
||||
if (params.extdir) {
|
||||
command.push('-extdir', quote(params.extdir));
|
||||
}
|
||||
if (params.content) {
|
||||
for (let k in params.content) if (params.content.hasOwnProperty(k)) {
|
||||
command.push('-C', quote(k), quote(params.content[k]));
|
||||
}
|
||||
}
|
||||
for (let file of files) {
|
||||
command.push('-C', quote(file.base), quote(file.path.split(file.base)[1]));
|
||||
}
|
||||
return command;
|
||||
};
|
||||
|
||||
constructor(version) {
|
||||
super(AdobeAir.ID, version || AdobeAir.VERSION);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
return fs.existsSync(`${this.path}/air-sdk-description.xml`);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return `http://airdownload.adobe.com/air/win/download/${this.version}/AIRSDK_Compiler.zip`;
|
||||
}
|
||||
|
||||
adt(path, args) {
|
||||
return exec(path, [this.adtBin].concat(args).join(' '));
|
||||
}
|
||||
|
||||
adl(path, args) {
|
||||
return exec(path, [this.adlBin].concat(args).join(' '));
|
||||
}
|
||||
|
||||
pack(params) {
|
||||
const files = [];
|
||||
let descriptor = null;
|
||||
let keystore = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case 'descriptor':
|
||||
descriptor = file;
|
||||
break;
|
||||
case 'keystore':
|
||||
keystore = file;
|
||||
break;
|
||||
default:
|
||||
files.push(file);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback) => {
|
||||
gutil.log(this.tag, col.cyan('adt', 'build', params.target), '=>', col.magenta(params.outputFile));
|
||||
if (!descriptor) {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: 'descriptor is not defined'}));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
const tmpFile = tmp.generateFile();
|
||||
const command = AdobeAir.buildAdtArgs(params, descriptor, keystore, files, tmpFile.path);
|
||||
this.adt('.', command)
|
||||
.then(() => {
|
||||
stream.push(new gutil.File({
|
||||
path: params.outputFile,
|
||||
contents: fs.createReadStream(tmpFile.path)
|
||||
}));
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
return stream = through.obj(bufferContents, endStream);
|
||||
}
|
||||
|
||||
install() {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan('adt', 'install'), col.magenta(file.name));
|
||||
const command = ['-installApp', '-platform', 'android', '-package', file.path];
|
||||
this.adt('.', command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return stream = through.obj(bufferContents);
|
||||
}
|
||||
|
||||
launch(appid) {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan('adt', 'launch'), col.magenta(appid));
|
||||
const command = ['-launchApp', '-platform', 'android', '-appid', appid];
|
||||
this.adt('.', command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return stream = through.obj(bufferContents);
|
||||
}
|
||||
|
||||
test(params) {
|
||||
let root = null;
|
||||
let descriptor = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case 'descriptor':
|
||||
descriptor = file;
|
||||
break;
|
||||
default:
|
||||
root = file;
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback) => {
|
||||
gutil.log(this.tag, col.cyan('adl'));
|
||||
//const command = AdobeAir.buildAdtArgs(params, files, tmpFile.path);
|
||||
const command = [];
|
||||
if (params.profile) command.push('-profile', params.profile);
|
||||
if (params.extdir) command.push('-extdir', params.extdir);
|
||||
if (!descriptor) {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: 'descriptor is not defined'}));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
command.push(descriptor.path);
|
||||
command.push(root.path);
|
||||
if (params.args) {
|
||||
command.push('--');
|
||||
for (let key of Object.keys(params.args)) {
|
||||
const value = params.args[key];
|
||||
if (value === true) {
|
||||
command.push(`-${key}`);
|
||||
} else if (value) {
|
||||
command.push(`-${key}`, `${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.adl('.', command)
|
||||
.then(() => {
|
||||
stream.emit('end');
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
|
||||
//callback();
|
||||
stream.push(root);
|
||||
};
|
||||
|
||||
return stream = through.obj(bufferContents, endStream);
|
||||
}
|
||||
|
||||
static descriptor(template, values) {
|
||||
const tmpFile = tmp.generateFile();
|
||||
const patterns = [];
|
||||
for (let k in values) if (values.hasOwnProperty(k)) {
|
||||
patterns.push({match: k, replacement: values[k]});
|
||||
}
|
||||
return gulp.src(template)
|
||||
.pipe(replace({patterns: patterns}))
|
||||
.pipe(mark.set('descriptor'))
|
||||
.pipe(gulp.dest(tmpFile.path));
|
||||
}
|
||||
|
||||
static keystore(keystore, storepass) {
|
||||
return gulp.src(keystore).pipe(through.obj((file, enc, callback) => {
|
||||
file.mark = 'keystore';
|
||||
file.storepass = storepass;
|
||||
callback(null, file);
|
||||
}));
|
||||
}
|
||||
|
||||
static pack(params) {
|
||||
return new AdobeAir().pack(params);
|
||||
}
|
||||
|
||||
static test(params) {
|
||||
return new AdobeAir().test(params);
|
||||
}
|
||||
}
|
||||
|
||||
AdobeAir.ID = 'adobe-air';
|
||||
|
||||
AdobeAir.VERSION_26 = '26.0';
|
||||
AdobeAir.VERSION_25 = '25.0';
|
||||
AdobeAir.VERSION_24 = '24.0';
|
||||
AdobeAir.VERSION = AdobeAir.VERSION_26;
|
||||
|
||||
module.exports = AdobeAir;
|
||||
@@ -1,251 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const exec = require('./exec');
|
||||
const {StringWritable} = require('./tail');
|
||||
const System = require('./system');
|
||||
const Command = require('../run/command');
|
||||
const through = require('through2');
|
||||
const Sdk = require('./sdk');
|
||||
const Env = require('./env');
|
||||
|
||||
|
||||
class Android extends Sdk {
|
||||
|
||||
constructor(version) {
|
||||
super(Android.ID, version || Android.VERSION);
|
||||
this.ndk_version = 'r15c';
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(`${this.path}/tools/bin/sdkmanager`);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link() {
|
||||
const system = System.isWindows ? 'windows' : System.isLinux ? 'linux' : null;
|
||||
if (!system) throw 'Unsupported system';
|
||||
if (this.version.indexOf('.') > -1) {
|
||||
return `https://dl.google.com/android/repository/tools_r${this.version}-${system}.zip`;
|
||||
} else {
|
||||
return `https://dl.google.com/android/repository/sdk-tools-${system}-${this.version}.zip`;
|
||||
}
|
||||
}
|
||||
|
||||
get android_home() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
get ndk_home() {
|
||||
return path.join(this.path, 'ndk-bundle')
|
||||
}
|
||||
|
||||
prepare() {
|
||||
const result = [];
|
||||
result.push(super.prepare(0));
|
||||
if (!fs.existsSync(path.join(this.ndk_home))) {
|
||||
result.push(this.prepare_ndk());
|
||||
}
|
||||
return Promise.all(result);
|
||||
}
|
||||
|
||||
prepare_ndk() {
|
||||
// ToDo: support windows
|
||||
const url = `https://dl.google.com/android/repository/android-ndk-${this.ndk_version}-linux-x86_64.zip`;
|
||||
this.log.d('download: *%s*', url);
|
||||
return Sdk.Downloader.download(url, this.ndk_home, 1, true);
|
||||
}
|
||||
|
||||
sdkmanager(packages) {
|
||||
this.log.i('sdkmanager: *%s*', packages.join(', '));
|
||||
const installedFile = path.join(this.path, '.installed');
|
||||
const installed = new Set(
|
||||
fs.existsSync(installedFile) ?
|
||||
fs.readFileSync(installedFile, {encoding: 'utf8'}).split('\n') :
|
||||
[]
|
||||
);
|
||||
const install = new Set(packages);
|
||||
for (const key of installed) {
|
||||
if (install.has(key)) {
|
||||
install.delete(key);
|
||||
}
|
||||
}
|
||||
if (install.size === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const androidBin = path.join(this.path, 'tools/bin/sdkmanager');
|
||||
if (fs.existsSync(androidBin)) {
|
||||
fs.chmodSync(androidBin, 0o755);
|
||||
}
|
||||
const yes = '(while sleep 3; do echo "y"; done)';
|
||||
const command = [yes, '|', androidBin].concat(Array.from(install).map(name => `"${name}"`)).join(' ');
|
||||
return exec('.', command).then(() => {
|
||||
for (const key of install) {
|
||||
installed.add(key);
|
||||
}
|
||||
fs.writeFileSync(installedFile, Array.from(installed).join('\n'), {encoding: 'utf8'});
|
||||
});
|
||||
}
|
||||
|
||||
activate() {
|
||||
Env.set('ANDROID_HOME', this.android_home);
|
||||
Env.set('ANDROID_NDK_HOME', this.ndk_home);
|
||||
Env.set('NDK_HOME', this.ndk_home);
|
||||
}
|
||||
|
||||
get adbBin() {
|
||||
return path.join(this.path, 'platform-tools/adb');
|
||||
}
|
||||
|
||||
adb(args) {
|
||||
return exec('.', [this.adbBin].concat(args).join(' ')).then(data => {
|
||||
for (let line of data.stderr.split('\n')) {
|
||||
if (line.indexOf('Error') > -1) {
|
||||
throw line;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
buildTool(name) {
|
||||
let buildToolsVersion = null;
|
||||
fs.readdirSync(path.join(this.path, 'build-tools')).forEach(file => {
|
||||
buildToolsVersion = file;
|
||||
});
|
||||
return path.join(this.path, 'build-tools', buildToolsVersion, name);
|
||||
}
|
||||
|
||||
aapt(args) {
|
||||
const aaptBin = this.buildTool('aapt');
|
||||
return exec('.', [aaptBin].concat(args).join(' '));
|
||||
}
|
||||
|
||||
apk() {
|
||||
const self = this;
|
||||
return through.obj(function(file, enc, callback) {
|
||||
self.aapt(['l', '-a', file.path]).then(data => {
|
||||
let activity = false;
|
||||
for (let line of data.stdout.split('\n')) {
|
||||
if (line.indexOf('package') > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) file.package = value[1]
|
||||
}
|
||||
if (line.indexOf('activity') > -1) {
|
||||
activity = true;
|
||||
}
|
||||
if (activity && line.indexOf('name') > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) {
|
||||
file.activity = value[1];
|
||||
activity = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_installApk(filename, pack) {
|
||||
this.log.i('install *%s*', filename);
|
||||
return this.adb(['install', '-r', '-d', filename])
|
||||
.then(() => {
|
||||
return false;
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.includes('INSTALL_FAILED_UPDATE_INCOMPATIBLE')) {
|
||||
this.log.w('!INSTALL FAILED UPDATE INCOMPATIBLE!');
|
||||
return true;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.then(reinstall => {
|
||||
if (reinstall) {
|
||||
this.log.i('uninstall *%s*', pack);
|
||||
return this.adb(['uninstall', pack]).then(() => {
|
||||
this.log.i('install *%s*', filename);
|
||||
return this.adb(['install', '-r', '-d', filename]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
install() {
|
||||
const self = this;
|
||||
return through.obj(function(file, enc, callback) {
|
||||
self._installApk(file.path, file.package).then(() => {
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
const self = this;
|
||||
return through.obj(function(file, enc, callback) {
|
||||
const name = `${file.package}/${file.activity}`;
|
||||
self.log.i('start *%s*', name);
|
||||
self.adb(['shell', 'am', 'start', '-n', name]).then(() => {
|
||||
setTimeout(() => {
|
||||
self.adb(['shell', `"ps | grep ${file.package}"`]).then(result => {
|
||||
file.pid = result.stdout.split(/\s+/)[1];
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
logcat() {
|
||||
const self = this;
|
||||
return through.obj(function(file, enc, callback) {
|
||||
const cmd = `${self.adbBin} logcat --pid ${file.pid}`;
|
||||
const command = new Command(cmd).exec();
|
||||
this.push(command);
|
||||
command.contents.pipe(new StringWritable(line => {
|
||||
if (line.includes('SDL') && (line.includes('onDestroy()') || line.includes('onStop()'))) {
|
||||
callback();
|
||||
throw 'Exit'; // ToDo:
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
sign(keystore, keypass) {
|
||||
const self = this;
|
||||
return through.obj(function(file, enc, callback) {
|
||||
self.log.i('sign *%s*', file.path);
|
||||
const filename = path.join(os.tmpdir(), 'tmp.apk');
|
||||
fs.writeFileSync(filename, file.contents);
|
||||
const cmd = [
|
||||
self.buildTool('apksigner'),
|
||||
'sign',
|
||||
'--ks', keystore,
|
||||
'--ks-pass', `pass:${keypass}`,
|
||||
filename
|
||||
].join(' ');
|
||||
exec('.', cmd).then(() => {
|
||||
file.contents = fs.readFileSync(filename);
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Android.ID = 'android';
|
||||
|
||||
Android.VERSION_25_2_3 = '25.2.3';
|
||||
Android.VERSION_3859397 = '3859397';
|
||||
Android.VERSION_4333796 = '4333796';
|
||||
|
||||
Android.VERSION = Android.VERSION_4333796;
|
||||
|
||||
module.exports = Android;
|
||||
@@ -1,99 +0,0 @@
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
|
||||
const BuildSystem = {
|
||||
HAXE: 'haxe',
|
||||
OPENFL: 'openfl',
|
||||
ADOBE_AIR: 'adobe_air',
|
||||
};
|
||||
|
||||
|
||||
const Platform = {
|
||||
FLASH: 'flash',
|
||||
HTML5: 'html5',
|
||||
LINUX: 'linux',
|
||||
WINDOWS: 'windows',
|
||||
ANDROID: 'android',
|
||||
NEKO: 'neko',
|
||||
};
|
||||
|
||||
|
||||
class Config {
|
||||
|
||||
constructor(params) {
|
||||
this._params = [];
|
||||
this.name = null;
|
||||
this.main = null;
|
||||
this.preloader = null;
|
||||
this.sources = [];
|
||||
this.assets = [];
|
||||
this.libs = [];
|
||||
this.macros = [];
|
||||
this.flags = [];
|
||||
this.icon = null;
|
||||
this.meta = {
|
||||
title: null,
|
||||
filename: null,
|
||||
icon: null,
|
||||
version: null,
|
||||
pack: null,
|
||||
author: null,
|
||||
company: null,
|
||||
width: 800,
|
||||
height: 600,
|
||||
mobileWidth: null,
|
||||
mobileHeight: null,
|
||||
fps: 60,
|
||||
};
|
||||
this.key = null;
|
||||
this.android = [];
|
||||
if (params) {
|
||||
this.update(params);
|
||||
this.afterUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
static absolutePath(file) {
|
||||
const result = path.resolve(process.cwd(), path.normalize(file));
|
||||
return os.type() === 'Windows_NT' ? result.split('\\').join('/') : result;
|
||||
}
|
||||
|
||||
update(params) {
|
||||
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);
|
||||
}
|
||||
|
||||
afterUpdate() {
|
||||
if (this.meta.mobileWidth === null) this.meta.mobileWidth = this.meta.width;
|
||||
if (this.meta.mobileHeight === null) this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 1.777777778);
|
||||
}
|
||||
|
||||
branch(params) {
|
||||
const result = new Config();
|
||||
for (const params of this._params) {
|
||||
result.update(params);
|
||||
}
|
||||
result.update(params);
|
||||
result.afterUpdate();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
BuildSystem: BuildSystem,
|
||||
Platform: Platform,
|
||||
Config: Config,
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
const colors = require('ansi-colors');
|
||||
|
||||
|
||||
const _colors = {
|
||||
'[DEBUG]': colors.white,
|
||||
'[INFO]': colors.cyan,
|
||||
'[ERROR]': colors.red,
|
||||
'Called from ': colors.red,
|
||||
'[WARNING]': colors.yellow,
|
||||
};
|
||||
|
||||
const getColor = (line) => {
|
||||
for (const [tag, color] of Object.entries(_colors)) {
|
||||
if (line.indexOf(tag) > -1) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return null;// colors.reset;
|
||||
};
|
||||
|
||||
|
||||
class Debug {
|
||||
|
||||
constructor() {
|
||||
this.color = colors.white;
|
||||
this.log = this.log.bind(this);
|
||||
}
|
||||
|
||||
log(line) {
|
||||
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(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Debug();
|
||||
@@ -1,24 +0,0 @@
|
||||
const path = require('path');
|
||||
|
||||
|
||||
class Env {
|
||||
|
||||
static set(key, value) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
static get(key) {
|
||||
return process.env[key];
|
||||
}
|
||||
|
||||
static addPath(value, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = Env;
|
||||
@@ -1,30 +0,0 @@
|
||||
const child_process = require('child_process');
|
||||
const async = require('async');
|
||||
const log = require('./log')('exec');
|
||||
|
||||
|
||||
const queue = async.queue((task, done) => {
|
||||
log.d('*%s*', task.command);
|
||||
//process.chdir(task.dir);
|
||||
child_process.exec(task.command, {cwd: task.dir, maxBuffer: 1024 * 10000}, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
log.v('!%s!', err);
|
||||
task.failure('\n' + (stderr || stdout || err));
|
||||
} else {
|
||||
log.v('%s', stdout);
|
||||
task.success({stdout: stdout, stderr: stderr});
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = (dir, command) => {
|
||||
return new Promise((success, failure) => {
|
||||
queue.push({
|
||||
dir: dir,
|
||||
command: command,
|
||||
success: success,
|
||||
failure: failure,
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,128 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const os = require('os');
|
||||
const through = require('through2');
|
||||
const Sdk = require('./sdk');
|
||||
const System = require('./system');
|
||||
const run = require('../run/index');
|
||||
const {TailVinyl} = require('./tail');
|
||||
|
||||
|
||||
class FlashPlayer extends Sdk {
|
||||
|
||||
constructor(debug, version) {
|
||||
super(FlashPlayer.ID, version || FlashPlayer.VERSION);
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return super.prepare(0)
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.flashPlayerBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link() {
|
||||
const baseUrl = `https://fpdownload.macromedia.com/pub/flashplayer/updaters/${this.version}/`;
|
||||
if (System.isWindows) {
|
||||
return baseUrl + `flashplayer_${this.version}_sa${this.debug ? '_debug' : ''}.exe`;
|
||||
} else if (System.isLinux) {
|
||||
return baseUrl + `flash_player_sa_linux${this.debug ? '_debug' : ''}.x86_64.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
get flashPlayerBin() {
|
||||
if (os.type() === 'Windows_NT') {
|
||||
const v = this.version.split('.');
|
||||
const playerName = `flashplayer_${this.version}_sa${this.debug ? '_debug' : ''}.exe`;
|
||||
return path.join(this.path, playerName);
|
||||
} else if (os.type() === 'Linux') {
|
||||
const binPath = path.join(this.path, `flashplayer${this.debug ? 'debugger' : ''}`);
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
return binPath;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
static get flashPlayerDir() {
|
||||
if (os.type() === 'Windows_NT') {
|
||||
return path.join(process.env.APPDATA, 'Macromedia', 'Flash Player');
|
||||
} else if (os.type() === 'Linux') {
|
||||
return path.join(os.homedir(), '.macromedia', 'Flash_Player');
|
||||
}
|
||||
}
|
||||
|
||||
static get log() {
|
||||
return path.join(this.flashPlayerDir, 'Logs', 'flashlog.txt');
|
||||
}
|
||||
|
||||
static enableLog() {
|
||||
const filename = path.join(os.homedir(), 'mm.cfg');
|
||||
const value = 'TraceOutputFileEnable=1';
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
fse.ensureDirSync(path.join(this.flashPlayerDir, 'Logs'));
|
||||
fs.writeFileSync(FlashPlayer.log, '');
|
||||
}
|
||||
|
||||
static trust(value) {
|
||||
const filename = path.join(this.flashPlayerDir, '#Security', 'FlashPlayerTrust', 'gulp.cfg');
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
if (!fs.existsSync(path.dirname(filename))) {
|
||||
fse.ensureDirSync(path.dirname(filename));
|
||||
}
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
run(filename, params) {
|
||||
this.log.i('_run_ *%s*', filename);
|
||||
FlashPlayer.trust(filename);
|
||||
FlashPlayer.enableLog();
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params).exec()
|
||||
.pipe(through.obj(function (file, enc, callback) {
|
||||
const log = new TailVinyl({
|
||||
path: FlashPlayer.log,
|
||||
});
|
||||
this.on('end', () => log.dispose());
|
||||
this.push(log);
|
||||
callback();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
FlashPlayer.ID = 'flashplayer';
|
||||
|
||||
FlashPlayer.VERSION_24 = '24';
|
||||
FlashPlayer.VERSION_25 = '25';
|
||||
FlashPlayer.VERSION_26 = '26';
|
||||
FlashPlayer.VERSION_27 = '27';
|
||||
FlashPlayer.VERSION_28 = '28';
|
||||
FlashPlayer.VERSION_29 = '29';
|
||||
FlashPlayer.VERSION_30 = '30';
|
||||
FlashPlayer.VERSION_31 = '31';
|
||||
FlashPlayer.VERSION_32 = '32';
|
||||
|
||||
FlashPlayer.VERSION = FlashPlayer.VERSION_32;
|
||||
|
||||
module.exports = FlashPlayer;
|
||||
@@ -1,222 +0,0 @@
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const path = require('path');
|
||||
const exec = require('./exec');
|
||||
const Sdk = require('./sdk');
|
||||
const System = require('./system');
|
||||
const Env = require('./env');
|
||||
const Neko = require('./neko');
|
||||
const vfs = require('vinyl-fs');
|
||||
const template = require('lodash.template');
|
||||
const rename = require('gulp-rename');
|
||||
|
||||
class Haxe extends Sdk {
|
||||
|
||||
getBin(name) {
|
||||
if (System.isWindows) {
|
||||
return path.join(this.path, name + '.exe');
|
||||
} else if (System.isLinux) {
|
||||
const binPath = path.join(this.path, name);
|
||||
if (fs.existsSync(binPath)) {
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
}
|
||||
return binPath;
|
||||
}
|
||||
throw `Unsupported OS: ${os.type()}`;
|
||||
}
|
||||
|
||||
get haxeBin() {
|
||||
return this.getBin('haxe');
|
||||
}
|
||||
|
||||
get haxelibBin() {
|
||||
return this.getBin('haxelib');
|
||||
}
|
||||
|
||||
constructor(version) {
|
||||
super(Haxe.ID, version || Haxe.VERSION);
|
||||
this.neko = new Neko();
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.haxeBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
|
||||
fs.copyFileSync(path.resolve(__dirname, '..', 'template/haxe/activate'), path.resolve(this.path, 'activate'));
|
||||
});
|
||||
}
|
||||
|
||||
get link() {
|
||||
if (System.isWindows) {
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-win.zip`;
|
||||
} else if (System.isLinux) {
|
||||
let arch = System.archInt;
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-linux${arch}.tar.gz`;
|
||||
}
|
||||
}
|
||||
|
||||
haxe(args) {
|
||||
this.activate();
|
||||
return exec('.', [this.haxeBin].concat(args).join(' '));
|
||||
}
|
||||
|
||||
haxelib(args) {
|
||||
this.activate();
|
||||
return exec('.', [this.haxelibBin].concat(args).join(' '));
|
||||
}
|
||||
|
||||
resolveBuildDir(config) {
|
||||
return path.join(Haxe.buildDir, config.name);
|
||||
}
|
||||
|
||||
openfl(command, platform, config, debug=false) {
|
||||
this.log.i('_openfl_ _build_ *%s*', platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.xml')));
|
||||
const project = projectTemplate({...config, buildDir: buildDir});
|
||||
fs.writeFileSync(path.resolve(buildDir, 'project.xml'), project);
|
||||
|
||||
const args = ['-cwd', buildDir, 'run', 'openfl', command, platform];
|
||||
if (config.flags.dom) {
|
||||
args.push('-Ddom');
|
||||
}
|
||||
if (debug) {
|
||||
args.push('-debug');
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, 'bin');
|
||||
fse.emptyDirSync(target);
|
||||
const result = {
|
||||
'android': 'app/build/outputs/apk/*-debug.apk',
|
||||
'flash': '*.swf',
|
||||
}[platform] || '**/*';
|
||||
return this.haxelib(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`);
|
||||
if (platform === 'android') {
|
||||
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
build(platform, config, debug=false) {
|
||||
this.log.i('_build_ *%s*', platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.hxml')));
|
||||
|
||||
const ext = {
|
||||
flash: '.swf',
|
||||
neko: '.n',
|
||||
}[platform] || '';
|
||||
|
||||
const out = {
|
||||
flash: 'swf'
|
||||
}[platform] || platform;
|
||||
|
||||
const project = projectTemplate({...config, buildDir: buildDir, platform: platform, ext: ext, out: out});
|
||||
const projectHXML = path.resolve(buildDir, 'project.hxml');
|
||||
fs.writeFileSync(projectHXML, project);
|
||||
|
||||
const args = [projectHXML];
|
||||
if (debug) {
|
||||
args.push('-debug');
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, 'bin');
|
||||
fse.emptyDirSync(target);
|
||||
for (const asset of config.assets) {
|
||||
fse.copySync(asset, path.join(target, asset.split("/").pop()));
|
||||
}
|
||||
return this.haxe(args).then(() => vfs.src(`${target}/**/*`));
|
||||
}
|
||||
|
||||
install(packages) {
|
||||
this.activate();
|
||||
let promise = this.haxelib(['setup', path.join(this.path, 'lib')]);
|
||||
const next = (args) => () => {
|
||||
this.log.i('_haxelib_ _install_ *%s:%s*', args[1], args[2]);
|
||||
return this.haxelib(args);
|
||||
};
|
||||
|
||||
if (!Array.isArray(packages)) {
|
||||
packages = Object.entries(packages).map(([k, v]) => ({name: k, version: v}));
|
||||
}
|
||||
|
||||
for (let pack of packages) {
|
||||
const args = [];
|
||||
let version = null;
|
||||
if (typeof pack === 'string') {
|
||||
args.push('install', pack);
|
||||
} else if (typeof pack === 'object') {
|
||||
version = pack.version;
|
||||
if (version.substr(0, 3) === 'git') {
|
||||
pack.git = version;
|
||||
version = null;
|
||||
}
|
||||
if (pack.git) {
|
||||
args.push('git', pack.name, pack.git);
|
||||
if (pack.branch) args.push(pack.branch);
|
||||
} else {
|
||||
args.push('install', pack.name);
|
||||
if (version) args.push(version);
|
||||
}
|
||||
args.push('--always');
|
||||
}
|
||||
let path = `${this.path}/lib/${args[1]}`;
|
||||
if (version) {
|
||||
path += `/${version.replace(/\./g, ',')}`;
|
||||
} else if (pack.git) {
|
||||
path += '/git';
|
||||
}
|
||||
if (!fs.existsSync(path)) {
|
||||
promise = promise.then(next(args));
|
||||
}
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
let promise = this.haxelib(['setup', path.join(this.path, 'lib')]);
|
||||
promise = promise.then(() => this.haxelib(['upgrade', '--always']));
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
Haxe.buildDir = path.join(process.cwd(), 'build');
|
||||
|
||||
Haxe.ID = 'haxe';
|
||||
|
||||
Haxe.VERSION_3_4_0 = '3.4.0';
|
||||
Haxe.VERSION_3_4_2 = '3.4.2';
|
||||
Haxe.VERSION_3_4_3 = '3.4.3';
|
||||
Haxe.VERSION_3_4_7 = '3.4.7';
|
||||
Haxe.VERSION_3 = Haxe.VERSION_3_4_7;
|
||||
Haxe.VERSION_4_0_0 = '4.0.0';
|
||||
Haxe.VERSION_4_0_1 = '4.0.1';
|
||||
Haxe.VERSION_4_0_2 = '4.0.2';
|
||||
Haxe.VERSION_4_0_3 = '4.0.3';
|
||||
Haxe.VERSION_4_0_5 = '4.0.5';
|
||||
Haxe.VERSION_4 = Haxe.VERSION_4_0_5;
|
||||
Haxe.VERSION = Haxe.VERSION_4;
|
||||
|
||||
module.exports = Haxe;
|
||||
@@ -1,57 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const Sdk = require('./sdk');
|
||||
const exec = require('./exec');
|
||||
const template = require('lodash.template');
|
||||
|
||||
class InnoSetup extends Sdk {
|
||||
|
||||
constructor(version) {
|
||||
super(InnoSetup.ID, version || InnoSetup.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return 'http://www.jrsoftware.org/download.php/is.exe';
|
||||
}
|
||||
|
||||
prepare(strip = 1) {
|
||||
let result = super.prepare(strip);
|
||||
if (!this.prepared) {
|
||||
result = result.then(() => {
|
||||
return exec(this.path, `is.exe /VERYSILENT /SUPPRESSMSGBOXES /DIR=${this.path}`);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
get isccBin() {
|
||||
return path.join(this.path, 'ISCC.exe')
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.isccBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pack(config, source, output) {
|
||||
const buildDir = path.join(os.tmpdir(), 'build', config.name, 'innosetup');
|
||||
const appTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/windows/app.iss')));
|
||||
const app = appTemplate({...config, buildDir: buildDir, output: output});
|
||||
|
||||
fse.ensureDirSync(buildDir);
|
||||
fse.copySync(`${source}`, `${buildDir}`);
|
||||
|
||||
fs.writeFileSync(path.resolve(buildDir, 'app.iss'), app);
|
||||
return exec(buildDir, [`"${this.isccBin}"`, 'app.iss'].join(' '));
|
||||
}
|
||||
}
|
||||
|
||||
InnoSetup.ID = 'innosetup';
|
||||
InnoSetup.VERSION = '6';
|
||||
|
||||
module.exports = InnoSetup;
|
||||
@@ -1,64 +0,0 @@
|
||||
const colors = require('ansi-colors');
|
||||
const timestamp = require('time-stamp');
|
||||
|
||||
|
||||
const Level = {
|
||||
VERBOSE: -1,
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
};
|
||||
|
||||
const level = process.argv.indexOf('--verbose') > -1 ? Level.VERBOSE : Level.INFO;
|
||||
|
||||
|
||||
class Log {
|
||||
|
||||
static colorize(pattern) {
|
||||
for (const item of [
|
||||
['_', colors.cyan],
|
||||
['\\*', colors.magenta],
|
||||
['!', colors.red],
|
||||
]) {
|
||||
const r = new RegExp(item[0] + "(.*?)" + item[0], 'g');
|
||||
pattern = pattern.replace(r, item[1]('$1'));
|
||||
}
|
||||
return pattern
|
||||
}
|
||||
|
||||
static write(level, tag, pattern, ...args) {
|
||||
if (level >= this.level) {
|
||||
const message = `[${colors.gray(timestamp('HH:mm:ss'))}] ${colors.green(tag)} ${this.colorize(pattern)}`;
|
||||
console.log(message, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
v(...args) {
|
||||
Log.write(-1, this.tag, ...args);
|
||||
}
|
||||
|
||||
d(...args) {
|
||||
Log.write(0, this.tag, ...args);
|
||||
}
|
||||
|
||||
i(...args) {
|
||||
Log.write(1, this.tag, ...args);
|
||||
}
|
||||
|
||||
w(...args) {
|
||||
Log.write(2, this.tag, ...args);
|
||||
}
|
||||
|
||||
e(...args) {
|
||||
Log.write(3, this.tag, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
Log.level = level;
|
||||
|
||||
module.exports = (tag) => new Log(tag);
|
||||
@@ -1,88 +0,0 @@
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const run = require('../run/index');
|
||||
const Sdk = require('./sdk');
|
||||
const Env = require('./env');
|
||||
|
||||
|
||||
class NekoLink {
|
||||
|
||||
static get type() {
|
||||
switch (os.type()) {
|
||||
case 'Linux': return 'linux';
|
||||
case 'Windows_NT': return 'win';
|
||||
}
|
||||
}
|
||||
|
||||
static get arch() {
|
||||
switch (os.arch()) {
|
||||
case 'ia32': return '';
|
||||
case 'x64': return '64';
|
||||
}
|
||||
}
|
||||
|
||||
static get ext() {
|
||||
switch (os.type()) {
|
||||
case 'Linux': return 'tar.gz';
|
||||
case 'Windows_NT': return 'zip';
|
||||
}
|
||||
}
|
||||
|
||||
static get(version) {
|
||||
const vv = version.split('\.').join('-');
|
||||
const filename = `neko-${version}-${NekoLink.type}${NekoLink.arch}.${NekoLink.ext}`;
|
||||
return `https://github.com/HaxeFoundation/neko/releases/download/v${vv}/${filename}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Neko extends Sdk {
|
||||
|
||||
constructor(version) {
|
||||
super(Neko.ID, version || Neko.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return NekoLink.get(this.version);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.nekoBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
activate() {
|
||||
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(__dirname, '..', 'template/neko/activate'), path.resolve(this.path, 'activate'));
|
||||
});
|
||||
}
|
||||
|
||||
get nekoBin() {
|
||||
let binname = 'neko';
|
||||
if (os.type() === 'Windows_NT') binname += '.exe';
|
||||
return path.join(this.path, binname);
|
||||
}
|
||||
|
||||
run(filename, params) {
|
||||
this.log.i('_run_ *%s*', filename);
|
||||
this.activate();
|
||||
return run(`${this.nekoBin} ${filename}`, params).exec();
|
||||
}
|
||||
}
|
||||
|
||||
Neko.ID = 'neko';
|
||||
|
||||
Neko.VERSION_2_2_0 = '2.2.0';
|
||||
Neko.VERSION = Neko.VERSION_2_2_0;
|
||||
|
||||
module.exports = Neko;
|
||||
@@ -1,531 +0,0 @@
|
||||
const gulp = require('gulp');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const Haxe = require('./haxe');
|
||||
const FlashPlayer = require('./flashplayer');
|
||||
const Android = require('./android');
|
||||
const Neko = require('./neko');
|
||||
const InnoSetup = require('./innosetup');
|
||||
const Env = require('./env');
|
||||
const debug = require('./debug');
|
||||
const webserver = require('gulp-webserver');
|
||||
const run = require('../run/index');
|
||||
const tail = require('./tail');
|
||||
const exec = require('./exec');
|
||||
const deb = require('gulp-debian');
|
||||
const {BuildSystem, Platform, Config} = require('./core');
|
||||
const vfs = require('vinyl-fs');
|
||||
const rename = require('gulp-rename');
|
||||
const template = require('lodash.template');
|
||||
const tar = require('gulp-tar');
|
||||
const gzip = require('gulp-gzip');
|
||||
const zip = require('gulp-zip');
|
||||
|
||||
const streamToPromise = (stream) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", resolve);
|
||||
stream.on("error", reject);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Target {
|
||||
|
||||
constructor(config, platform) {
|
||||
this.config = config;
|
||||
this.platform = platform;
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
call() {
|
||||
throw 'Not Implemented';
|
||||
}
|
||||
|
||||
resolveTargetPath(platform = this.platform) {
|
||||
return path.resolve(this.target, this.config.name, platform)
|
||||
}
|
||||
|
||||
get targetPath() {
|
||||
return this.resolveTargetPath();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Builder extends Target {
|
||||
|
||||
constructor(config, platform, buildSystem, debug) {
|
||||
super(config, platform);
|
||||
this.buildSystem = buildSystem;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
static register(buildSystem, builder) {
|
||||
Builder.factory[buildSystem] = builder;
|
||||
}
|
||||
|
||||
static new(config, platform, buildSystem, debug) {
|
||||
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
|
||||
}
|
||||
}
|
||||
|
||||
Builder.factory = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class HaxeBuilder extends Builder {
|
||||
|
||||
constructor(config, platform, buildSystem, debug) {
|
||||
super(config, platform, buildSystem, debug);
|
||||
this.haxe = new Haxe();
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
|
||||
if (this.buildSystem === BuildSystem.OPENFL) {
|
||||
if (this.platform === Platform.ANDROID) {
|
||||
result = result
|
||||
.then(() => this.android.prepare())
|
||||
.then(() => this.android.activate())
|
||||
.then(() => this.android.sdkmanager([
|
||||
// ToDo: android sdk dependencies config?
|
||||
'tools',
|
||||
'platform-tools',
|
||||
'build-tools;27.0.3',
|
||||
'platforms;android-28', //ToDo: lime version 7.6.0 -> 28; 7.0.0 -> 26
|
||||
//'ndk-bundle',
|
||||
'lldb;3.1',
|
||||
'cmake;3.6.4111459',
|
||||
]));
|
||||
const AndroidSDK = this.android.android_home;
|
||||
const AndroidNDK = this.android.ndk_home;
|
||||
const answer = `echo "${[AndroidSDK, AndroidNDK].join('\n')}"`;
|
||||
result = result.then(() => {
|
||||
return exec('.', [answer, '|', this.haxe.haxelibBin, 'run', 'openfl', 'setup', this.platform].join(' '));
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
switch (this.buildSystem) {
|
||||
case BuildSystem.OPENFL:
|
||||
return this.haxe.openfl('build', this.platform, this.config, this.debug)
|
||||
.then(result => {
|
||||
if (this.platform === Platform.ANDROID && this.config.key) {
|
||||
result = result.pipe(this.android.sign(this.config.key.store, this.config.key.pass));
|
||||
}
|
||||
return streamToPromise(result.pipe(vfs.dest(target)));
|
||||
});
|
||||
case BuildSystem.HAXE:
|
||||
return this.haxe.build(this.platform, this.config, this.debug)
|
||||
.then(result => streamToPromise(result.pipe(vfs.dest(target))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Builder.register(BuildSystem.HAXE, HaxeBuilder);
|
||||
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Packer extends Target {
|
||||
|
||||
call() {
|
||||
throw 'Not Implemented';
|
||||
}
|
||||
|
||||
static register(platform, name, packer) {
|
||||
if (!Packer.factory[platform]) Packer.factory[platform] = {};
|
||||
Packer.factory[platform][name] = packer;
|
||||
}
|
||||
|
||||
static new(config, platform, name) {
|
||||
return new Packer.factory[platform][name](config);
|
||||
}
|
||||
}
|
||||
|
||||
Packer.factory = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FlashHTMLPacker extends Packer {
|
||||
|
||||
constructor(config) {
|
||||
super(config, Platform.FLASH);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const indexTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/flash/index.html')));
|
||||
const index = indexTemplate(this.config);
|
||||
fs.writeFileSync(path.resolve(target, 'index.html'), index);
|
||||
fs.copyFileSync(path.resolve(__dirname, '..', 'template/flash/swf.js'), path.resolve(target, 'swf.js'));
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
FlashHTMLPacker.NAME = 'html';
|
||||
|
||||
Packer.register(Platform.FLASH, FlashHTMLPacker.NAME, FlashHTMLPacker);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class LinuxDEBPacker extends Packer {
|
||||
|
||||
constructor(config) {
|
||||
super(config, Platform.LINUX);
|
||||
}
|
||||
|
||||
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 desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop')));
|
||||
const desktop = desktopTemplate(Object.assign({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}`);
|
||||
return gulp.src(`${buildDir}/*`)
|
||||
.pipe(deb({
|
||||
package: this.config.meta.filename,
|
||||
version: this.config.meta.version,
|
||||
section: 'base',
|
||||
priority: 'optional',
|
||||
architecture: 'all',
|
||||
maintainer: this.config.meta.author,
|
||||
description: this.config.meta.title,
|
||||
changelog: [],
|
||||
postinst: [
|
||||
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
|
||||
' update-menus\n' +
|
||||
'fi'
|
||||
],
|
||||
_target: '/',
|
||||
_out: this.resolveTargetPath('debian'),
|
||||
_clean: true,
|
||||
_verbose: false
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
LinuxDEBPacker.NAME = 'deb';
|
||||
|
||||
Packer.register(Platform.LINUX, LinuxDEBPacker.NAME, LinuxDEBPacker);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class LinuxArchivePacker extends Packer {
|
||||
|
||||
constructor(config) {
|
||||
super(config, Platform.LINUX);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_linux.tar`;
|
||||
return gulp.src(`${target}/**/*`)
|
||||
.pipe(tar(archiveName))
|
||||
.pipe(gzip())
|
||||
.pipe(gulp.dest(this.resolveTargetPath('archive')))
|
||||
}
|
||||
}
|
||||
|
||||
LinuxArchivePacker.NAME = 'archive';
|
||||
|
||||
Packer.register(Platform.LINUX, LinuxArchivePacker.NAME, LinuxArchivePacker);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class WindowsInstallerPacker extends Packer {
|
||||
|
||||
constructor(config) {
|
||||
super(config, Platform.WINDOWS);
|
||||
this.innosetup = new InnoSetup();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.innosetup.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
return this.innosetup.pack(this.config, this.targetPath, this.resolveTargetPath('installer'));
|
||||
}
|
||||
}
|
||||
|
||||
WindowsInstallerPacker.NAME = 'installer';
|
||||
|
||||
Packer.register(Platform.WINDOWS, WindowsInstallerPacker.NAME, WindowsInstallerPacker);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class WindowsArchivePacker extends Packer {
|
||||
|
||||
constructor(config) {
|
||||
super(config, Platform.WINDOWS);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_win.zip`;
|
||||
return gulp.src(`${target}/**/*`)
|
||||
.pipe(zip(archiveName))
|
||||
.pipe(gulp.dest(this.resolveTargetPath('archive')))
|
||||
}
|
||||
}
|
||||
|
||||
WindowsArchivePacker.NAME = 'archive';
|
||||
|
||||
Packer.register(Platform.WINDOWS, WindowsArchivePacker.NAME, WindowsArchivePacker);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Runner extends Target {
|
||||
|
||||
constructor(config, platform, debug) {
|
||||
super(config, platform);
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
log(stream) {
|
||||
return stream
|
||||
.pipe(tail(debug.log))
|
||||
.pipe(rename('out.log'))
|
||||
.pipe(gulp.dest(this.targetPath));
|
||||
}
|
||||
|
||||
static register(platform, runner) {
|
||||
Runner.factory[platform] = runner;
|
||||
}
|
||||
|
||||
static new(config, platform, debug) {
|
||||
return new Runner.factory[platform](config, debug);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.factory = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class FlashRunner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.FLASH, debug);
|
||||
this.player = new FlashPlayer(debug);
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.player.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename+'.swf');
|
||||
const result = this.player.run(filename, {cwd: target, verbosity: 0});
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.FLASH, FlashRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Html5Runner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.HTML5, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
return gulp.src(this.targetPath)
|
||||
.pipe(webserver({
|
||||
// ToDo: config?
|
||||
host: '0.0.0.0', port: 3000,
|
||||
open: true,
|
||||
fallback: 'index.html'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.HTML5, Html5Runner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class LinuxRunner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.LINUX, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename);
|
||||
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", {cwd: target, verbosity: 0}));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.LINUX, LinuxRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class WindowsRunner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.WINDOWS, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename + '.exe');
|
||||
const result = gulp.src(filename).pipe(run("<%=file.basename%>", {cwd: target, verbosity: 0}));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.WINDOWS, WindowsRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class NekoRunner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.NEKO, debug);
|
||||
this.neko = new Neko();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.neko.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename+'.n');
|
||||
const result = this.neko.run(filename, {cwd: target, verbosity: 0});
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.NEKO, NekoRunner);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class AndroidRunner extends Runner {
|
||||
|
||||
constructor(config, debug) {
|
||||
super(config, Platform.ANDROID, debug);
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.android.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
return this.log(gulp.src(`${target}/${this.config.meta.filename}_${this.config.meta.version}.apk`)
|
||||
.pipe(this.android.apk())
|
||||
.pipe(this.android.install())
|
||||
.pipe(this.android.start())
|
||||
.pipe(this.android.logcat())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.ANDROID, AndroidRunner);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Project {
|
||||
|
||||
constructor(buildSystem, platforms, config, prepare) {
|
||||
this.buildSystem = buildSystem;
|
||||
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
|
||||
this.config = config;
|
||||
this.prepare = prepare;
|
||||
}
|
||||
|
||||
build(platform, debug) {
|
||||
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
|
||||
const tasks = [builder.prepare.bind(builder)];
|
||||
if (this.prepare) tasks.push(this.prepare);
|
||||
tasks.push(builder.call.bind(builder));
|
||||
return tasks;
|
||||
}
|
||||
|
||||
run(platform, debug) {
|
||||
const runner = Runner.new(this.config, platform, debug);
|
||||
return [
|
||||
runner.prepare.bind(runner),
|
||||
runner.call.bind(runner),
|
||||
];
|
||||
}
|
||||
|
||||
test(platform) {
|
||||
return this.build(platform, debug).concat(this.run(platform, debug));
|
||||
}
|
||||
|
||||
pack(platform, name) {
|
||||
const packer = Packer.new(this.config, platform, name);
|
||||
return [
|
||||
packer.prepare.bind(packer),
|
||||
packer.call.bind(packer),
|
||||
];
|
||||
}
|
||||
|
||||
bind(module, external_gulp /* ToDo: spike */) {
|
||||
const _gulp = (external_gulp || gulp);
|
||||
for (const platform of this.platforms) {
|
||||
module.exports[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
|
||||
if (Runner.factory[platform]) {
|
||||
module.exports[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
|
||||
module.exports[`${this.config.name}:${platform}:test`] = _gulp.series(this.test(platform));
|
||||
}
|
||||
if (Packer.factory[platform]) {
|
||||
for (const name of Object.keys(Packer.factory[platform])) {
|
||||
module.exports[`${this.config.name}:${platform}:${name}`] = _gulp.series(this.pack(platform, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Project.BuildSystem = BuildSystem;
|
||||
Project.Platform = Platform;
|
||||
Project.Config = Config;
|
||||
Project.Builder = Builder;
|
||||
Project.Runner = Runner;
|
||||
|
||||
|
||||
module.exports = Project;
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const ps = require('promise-streams');
|
||||
const got = require('got');
|
||||
const unzip = require('unzip-stream');
|
||||
const tar = require('tar');
|
||||
const progress = require('cli-progress');
|
||||
const fse = require('fs-extra');
|
||||
const Log = require('./log');
|
||||
|
||||
class Downloader {
|
||||
|
||||
static createProgressBar() {
|
||||
if (Downloader.bar == null) {
|
||||
Downloader.bar = new progress.MultiBar({
|
||||
clearOnComplete: true,
|
||||
}, progress.Presets.shades_grey);
|
||||
}
|
||||
return Downloader.bar.create();
|
||||
}
|
||||
|
||||
static releaseProgressBar(bar) {
|
||||
bar.stop();
|
||||
if (Downloader.bar != null) {
|
||||
Downloader.bar.remove(bar);
|
||||
if (Downloader.bar.bars.length === 0) {
|
||||
Downloader.bar.stop();
|
||||
Downloader.bar = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static download(url, dest, strip = 1, executable = false) {
|
||||
fse.ensureDirSync(dest);
|
||||
const bar = Downloader.createProgressBar();
|
||||
let stream = got.stream(url);
|
||||
stream = stream
|
||||
.on('request', r => {
|
||||
if (bar) bar.start(1, 0);
|
||||
})
|
||||
.on('downloadProgress', p => {
|
||||
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 => {
|
||||
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') {
|
||||
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: strip}));
|
||||
} else {
|
||||
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split('/').pop())));
|
||||
}
|
||||
return ps.wait(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Sdk {
|
||||
static set dir(value) {
|
||||
Sdk._dir = value
|
||||
}
|
||||
|
||||
static get dir() {
|
||||
return Sdk._dir || path.join(os.homedir(), 'sdk');
|
||||
}
|
||||
|
||||
static path(name, version) {
|
||||
return path.join(this.dir, name, version);
|
||||
}
|
||||
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.log = Log(name);
|
||||
this.version = version;
|
||||
this.path = Sdk.path(name, version);
|
||||
}
|
||||
|
||||
get intVersion() {
|
||||
const vArr = this.version.split('\.').reverse();
|
||||
let m = 1;
|
||||
let r = 0;
|
||||
for (let v of vArr) {
|
||||
r += parseInt(v) * m;
|
||||
m *= 10;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
get link() {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
prepare(strip = 1) {
|
||||
this.log.i('version: *%s*', this.version);
|
||||
if (this.prepared) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
this.log.d('download: *%s*', this.link);
|
||||
return Downloader.download(this.link, this.path, strip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sdk.Downloader = Downloader;
|
||||
|
||||
module.exports = Sdk;
|
||||
@@ -1,27 +0,0 @@
|
||||
const os = require('os');
|
||||
|
||||
class System {
|
||||
|
||||
static get isWindows() {
|
||||
return os.type() === 'Windows_NT';
|
||||
}
|
||||
|
||||
static get isLinux() {
|
||||
return os.type() === 'Linux';
|
||||
}
|
||||
|
||||
static get archInt() {
|
||||
if (os.arch() === 'ia32') return 32;
|
||||
if (os.arch() === 'x64') return 64;
|
||||
}
|
||||
|
||||
static get isArch32() {
|
||||
return this.archInt === 32;
|
||||
}
|
||||
|
||||
static get isArch64() {
|
||||
return this.archInt === 64;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = System;
|
||||
@@ -1,70 +0,0 @@
|
||||
const through = require('through2');
|
||||
const {Writable} = require('stream');
|
||||
const {StringDecoder} = require('string_decoder');
|
||||
const Vinyl = require('vinyl');
|
||||
const {Tail} = require('tail');
|
||||
const {Transform} = require('stream');
|
||||
|
||||
|
||||
class TailVinyl extends Vinyl {
|
||||
|
||||
constructor(params) {
|
||||
params.contents = new Transform();
|
||||
super(params);
|
||||
if (params.path) {
|
||||
this.tail = new Tail(params.path);
|
||||
this.tail.on('line', data => this.contents.write(data + '\n'));
|
||||
this.tail.on('error', error => this.contents.write('error: ' + error));
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (this.tail) {
|
||||
this.tail.unwatch();
|
||||
}
|
||||
this.contents.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StringWritable extends Writable {
|
||||
|
||||
constructor(handler, options) {
|
||||
super(options);
|
||||
this.handler = handler;
|
||||
const state = this._writableState;
|
||||
this._decoder = new StringDecoder(state.defaultEncoding);
|
||||
this.data = '';
|
||||
}
|
||||
|
||||
_write(chunk, encoding, callback) {
|
||||
if (encoding === 'buffer') {
|
||||
chunk = this._decoder.write(chunk);
|
||||
for (const line of chunk.split('\n')) if (line.length) {
|
||||
this.handler(line);
|
||||
}
|
||||
}
|
||||
this.data += chunk;
|
||||
callback();
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
this.data += this._decoder.end();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = (handler) => {
|
||||
return through.obj(function (file, enc, callback) {
|
||||
if (file.contents && file.contents.pipe) {
|
||||
file.contents.pipe(new StringWritable(handler));
|
||||
}
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.TailVinyl = TailVinyl;
|
||||
module.exports.StringWritable = StringWritable;
|
||||
@@ -1,9 +0,0 @@
|
||||
module.exports = {
|
||||
System: require('./haxetool/system'),
|
||||
Sdk: require('./haxetool/sdk'),
|
||||
Haxe: require('./haxetool/haxe'),
|
||||
FlashPlayer: require('./haxetool/flashplayer'),
|
||||
Android: require('./haxetool/android'),
|
||||
AdobeAir: require('./haxetool/adobe_air'),
|
||||
Project: require('./haxetool/project'),
|
||||
};
|
||||
Generated
+9291
File diff suppressed because it is too large
Load Diff
+69
-32
@@ -1,47 +1,84 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"version": "0.1.5",
|
||||
"type": "module",
|
||||
"version": "1.2.0",
|
||||
"description": "HaXe Tool for Gulp",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"ansi-colors": "^1.1.0",
|
||||
"async": "^2.6.0",
|
||||
"cli-progress": "^3.0.0",
|
||||
"fancy-log": "^1.3.2",
|
||||
"fs-extra": "^5.0.0",
|
||||
"got": "^9.6.0",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-debian": "^0.1.9",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-spawn": "^0.4.0",
|
||||
"gulp-tar": "^3.0.0",
|
||||
"gulp-webserver": "^0.9.1",
|
||||
"gulp-zip": "^5.0.0",
|
||||
"lodash.defaults": "^4.2.0",
|
||||
"lodash.template": "^4.4.0",
|
||||
"plugin-error": "^1.0.1",
|
||||
"promise-streams": "^2.1.1",
|
||||
"tail": "^1.2.3",
|
||||
"tar": "^4.4.10",
|
||||
"through2": "^2.0.3",
|
||||
"tmp-file": "^2.0.1",
|
||||
"unzip-stream": "^0.3.0",
|
||||
"vinyl": "^2.1.0",
|
||||
"vinyl-fs": "^3.0.2"
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"template",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"build": "tsdown",
|
||||
"dev": "tsdown --watch",
|
||||
"lint": "tsc --noEmit",
|
||||
"test": "node --test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@bitbucket.org/shmyga/gulp-haxetool.git"
|
||||
"url": "https://git.shmyga.ru/InfernalGames/gulp-haxetool.git"
|
||||
},
|
||||
"keywords": [
|
||||
"gulp",
|
||||
"haxe"
|
||||
],
|
||||
"author": "shmyga",
|
||||
"license": "ISC",
|
||||
"homepage": "https://bitbucket.org/shmyga/gulp-haxetool#readme"
|
||||
"license": "MIT",
|
||||
"homepage": "https://git.shmyga.ru/InfernalGames/gulp-haxetool#readme",
|
||||
"dependencies": {
|
||||
"ansi-colors": "^1.1.0",
|
||||
"async": "^2.6.0",
|
||||
"cli-progress": "^3.12.0",
|
||||
"dateformat": "^5.0.4",
|
||||
"fancy-log": "^1.3.2",
|
||||
"fs-extra": "^5.0.0",
|
||||
"got": "^16.1.0",
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-connect": "^5.7.0",
|
||||
"gulp-debian": "^0.1.9",
|
||||
"gulp-gzip": "^1.4.2",
|
||||
"gulp-rename": "^2.1.0",
|
||||
"gulp-tar": "^5.0.0",
|
||||
"gulp-zip": "^6.1.0",
|
||||
"lodash.defaults": "^4.2.0",
|
||||
"lodash.template": "^4.4.0",
|
||||
"plugin-error": "^1.0.1",
|
||||
"promise-streams": "^2.1.1",
|
||||
"tail": "^2.2.6",
|
||||
"tar": "^7.5.22",
|
||||
"through2": "^5.0.12",
|
||||
"tmp-file": "^2.0.1",
|
||||
"unzip-stream": "^0.3.4",
|
||||
"vinyl": "^3.0.1",
|
||||
"vinyl-fs": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async": "^3.2.26",
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
"@types/dateformat": "^5.0.3",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/gulp": "^4.0.18",
|
||||
"@types/gulp-connect": "^5.0.10",
|
||||
"@types/gulp-gzip": "^0.0.36",
|
||||
"@types/gulp-rename": "^2.0.7",
|
||||
"@types/gulp-tar": "^4.0.1",
|
||||
"@types/gulp-zip": "^4.0.4",
|
||||
"@types/lodash.template": "^4.5.3",
|
||||
"@types/node": "^26.6.5",
|
||||
"@types/tail": "^2.2.3",
|
||||
"@types/tar": "^7.0.87",
|
||||
"@types/through2": "^5.0.0",
|
||||
"@types/unzip-stream": "^0.3.4",
|
||||
"eslint": "^10.13.0",
|
||||
"prettier": "^3.9.10",
|
||||
"tsdown": "0.22.14",
|
||||
"typescript": "^7.0.2"
|
||||
},
|
||||
"inlinedDependencies": {
|
||||
"lodash": "4.18.1"
|
||||
}
|
||||
}
|
||||
|
||||
-195
@@ -1,195 +0,0 @@
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var stream = require('stream');
|
||||
var util = require('util');
|
||||
var defaults = require('lodash.defaults');
|
||||
var applyTemplate = require('lodash.template');
|
||||
var Vinyl = require('vinyl');
|
||||
var colors = require('ansi-colors');
|
||||
|
||||
/**
|
||||
* Creates a new `gulp-run` command.
|
||||
*
|
||||
* @param {string} command
|
||||
* @param {object} options
|
||||
*/
|
||||
function Command(command, options) {
|
||||
var previousPath;
|
||||
|
||||
this.command = command;
|
||||
|
||||
// We're on Windows if `process.platform` starts with "win", i.e. "win32".
|
||||
this.isWindows = (process.platform.lastIndexOf('win') === 0);
|
||||
|
||||
// the cwd and environment of the command are the same as the main node
|
||||
// process by default.
|
||||
this.options = defaults(options || {}, {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
verbosity: (options && options.silent) ? 1 : 2,
|
||||
usePowerShell: false
|
||||
});
|
||||
|
||||
// include node_modules/.bin on the path when we execute the command.
|
||||
previousPath = this.options.env.PATH;
|
||||
this.options.env.PATH = path.join(this.options.cwd, 'node_modules', '.bin');
|
||||
this.options.env.PATH += path.delimiter;
|
||||
this.options.env.PATH += previousPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command, invoking the callback when the command exits.
|
||||
* Returns a Vinyl file wrapping the command's stdout.
|
||||
*
|
||||
* @param {string} stdin
|
||||
* @param {function} callback
|
||||
* @return {Stream}
|
||||
*/
|
||||
Command.prototype.exec = function exec(stdin, callback) {
|
||||
var self = this;
|
||||
var command;
|
||||
var fileName;
|
||||
var directory;
|
||||
var subShell;
|
||||
var log;
|
||||
var err;
|
||||
var stdout;
|
||||
|
||||
// parse the arguments, both are optional.
|
||||
// after parsing, stdin is a vinyl file to use as standard input to
|
||||
// the command (possibly empty), and callback is a function.
|
||||
if (typeof stdin === 'function') {
|
||||
callback = stdin;
|
||||
stdin = undefined;
|
||||
} else if (typeof callback !== 'function') {
|
||||
callback = function noop() {};
|
||||
}
|
||||
|
||||
if (!(stdin instanceof Vinyl)) {
|
||||
fileName = this.command.split(' ')[0];
|
||||
directory = path.join(this.options.cwd, fileName);
|
||||
|
||||
if (typeof stdin === 'string') {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: new Buffer(stdin)
|
||||
});
|
||||
} else if (stdin instanceof Buffer || stdin instanceof stream.Readable) {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: stdin
|
||||
});
|
||||
} else {
|
||||
stdin = new Vinyl(stdin);
|
||||
|
||||
if (!stdin.path) {
|
||||
stdin.path = directory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute the command.
|
||||
// we spawn the command in a subshell, so things like i/o redirection
|
||||
// just work. e.g. `echo hello world >> ./hello.txt` works as expected.
|
||||
command = applyTemplate(this.command)({
|
||||
file: stdin
|
||||
});
|
||||
|
||||
if (this.isWindows && this.options.usePowerShell) {
|
||||
// windows powershell
|
||||
subShell = cp.spawn('powershell.exe', ['-NonInteractive', '-NoLogo', '-Command', command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd
|
||||
});
|
||||
} else if (this.isWindows) {
|
||||
// windows cmd.exe
|
||||
subShell = cp.spawn('cmd.exe', ['/c', command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd
|
||||
});
|
||||
} else {
|
||||
// POSIX shell
|
||||
subShell = cp.spawn('sh', ['-c', command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd
|
||||
});
|
||||
}
|
||||
|
||||
// setup the output
|
||||
//
|
||||
// - if verbosity equals to 3, the command prints directly to the terminal.
|
||||
// - if verbosity equals to 2, the command's stdout and stderr are buffered
|
||||
// and printed to the user's terminal after the command exits (this
|
||||
// prevents overlaping output of multiple commands)
|
||||
// - if verbosity equals to 1, the command's stderr is buffered as in 2, but
|
||||
// the stdout is silenced.
|
||||
log = new stream.PassThrough();
|
||||
|
||||
function sendLog(context) {
|
||||
var title = util.format(
|
||||
'$ %s%s',
|
||||
colors.blue(command),
|
||||
(self.options.verbosity < 2) ? colors.grey(' # Silenced\n') : '\n'
|
||||
);
|
||||
|
||||
context.write(title);
|
||||
}
|
||||
|
||||
switch (this.options.verbosity) {
|
||||
case 3:
|
||||
sendLog(process.stdout);
|
||||
subShell.stdout.pipe(process.stdout);
|
||||
subShell.stderr.pipe(process.stderr);
|
||||
break;
|
||||
case 2:
|
||||
subShell.stdout.pipe(log);
|
||||
// fallthrough
|
||||
case 1:
|
||||
subShell.stderr.pipe(log);
|
||||
sendLog(log);
|
||||
break;
|
||||
}
|
||||
|
||||
// setup the cleanup proceedure for when the command finishes.
|
||||
subShell.once('close', function handleSubShellClose() {
|
||||
// write the buffered output to stdout
|
||||
var content = log.read();
|
||||
|
||||
if (content !== null) {
|
||||
process.stdout.write(content);
|
||||
}
|
||||
});
|
||||
|
||||
subShell.once('exit', function handleSubShellExit(code) {
|
||||
// report an error if the command exited with a non-zero exit code.
|
||||
if (code !== 0) {
|
||||
err = new Error(util.format('Command `%s` exited with code %s', command, code));
|
||||
err.status = code;
|
||||
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
|
||||
// the file wrapping stdout is as the one wrapping stdin (same metadata)
|
||||
// with different contents.
|
||||
stdout = stdin.clone();
|
||||
stdout.contents = subShell.stdout.pipe(new stream.PassThrough());
|
||||
|
||||
// finally, write the input to the process's stdin.
|
||||
//stdin.pipe(subShell.stdin); //ToDo:
|
||||
|
||||
return stdout;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the command template.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
Command.prototype.toString = function toString() {
|
||||
return this.command;
|
||||
};
|
||||
|
||||
module.exports = Command;
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* Pipe shell commands in gulp.
|
||||
* @module gulp-run
|
||||
*/
|
||||
|
||||
var inherit = require('util').inherits;
|
||||
var Transform = require('stream').Transform;
|
||||
var Command = require('./command');
|
||||
|
||||
/**
|
||||
* Creates a GulpRunner.
|
||||
*
|
||||
* A GulpRunner is a Vinyl transform stream that spawns a child process to
|
||||
* transform the file. A separate process is spawned to handle each file
|
||||
* passing through the stream.
|
||||
*
|
||||
* @param {string} template
|
||||
* @param {object} options
|
||||
*/
|
||||
function GulpRunner(template, options) {
|
||||
if (!(this instanceof GulpRunner)) {
|
||||
return new GulpRunner(template, options);
|
||||
}
|
||||
|
||||
this.command = new Command(template, options || {});
|
||||
Transform.call(this, { objectMode: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* @extends {Stream.Transform}
|
||||
*/
|
||||
inherit(GulpRunner, Transform);
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @param {string} encoding
|
||||
* @param {function} callback
|
||||
* @return {void}
|
||||
*/
|
||||
GulpRunner.prototype._transform = function _transform(file, encoding, callback) {
|
||||
var newfile = this.command.exec(file, callback);
|
||||
this.push(newfile);
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes `stdin` to itself and returns itself.
|
||||
*
|
||||
* Whenever an object is written into the GulpRunner, a new process is
|
||||
* spawned taking that data as standard input, and a Vinyl file wrapping the
|
||||
* process's standard output is pushed downstream.
|
||||
*
|
||||
* `stdin` may be a String, Buffer, Readable stream, or Vinyl file.
|
||||
*
|
||||
* @param {mixed} stdin
|
||||
* @param {function} callback
|
||||
* @return {GulpRunner}
|
||||
*/
|
||||
GulpRunner.prototype.exec = function exec(stdin, callback) {
|
||||
this.write(stdin, callback);
|
||||
this.end();
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @type {Command}
|
||||
*/
|
||||
GulpRunner.Command = Command;
|
||||
|
||||
module.exports = GulpRunner;
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
declare module "gulp-clean" {
|
||||
import type { WritableStream } from "stream";
|
||||
|
||||
export interface Options {
|
||||
force?: boolean;
|
||||
}
|
||||
|
||||
export default (options?: Options) => WritableStream;
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
declare module "gulp-debian" {
|
||||
import type { WritableStream } from "stream";
|
||||
|
||||
export interface Options {
|
||||
package: string;
|
||||
version: string;
|
||||
section: string;
|
||||
priority: string;
|
||||
architecture: string;
|
||||
maintainer?: string;
|
||||
description?: string;
|
||||
preinst?: string[];
|
||||
postinst?: string[];
|
||||
prerm?: string[];
|
||||
postrm?: string[];
|
||||
conffiles?: string;
|
||||
changelog?: {
|
||||
version: string;
|
||||
distribution: string;
|
||||
urgency: string;
|
||||
date: Date;
|
||||
changes: string[];
|
||||
}[];
|
||||
_target?: string;
|
||||
_out?: string;
|
||||
_copyright?: string;
|
||||
_clean?: boolean;
|
||||
_verbose?: boolean;
|
||||
}
|
||||
|
||||
export default (options: Options) => WritableStream;
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
declare module "vinyl" {
|
||||
export class File {
|
||||
path: string;
|
||||
cwd: string;
|
||||
base: string;
|
||||
contents: any;
|
||||
stat: any;
|
||||
history: any[];
|
||||
constructor(params: any);
|
||||
clone(options?: any);
|
||||
}
|
||||
|
||||
export default File;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
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();
|
||||
@@ -0,0 +1,84 @@
|
||||
import progress from "cli-progress";
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import got from "got";
|
||||
import path from "path";
|
||||
import ps from "promise-streams";
|
||||
import type { Stream, Writable } from "stream";
|
||||
import * as tar from "tar";
|
||||
import unzip from "unzip-stream";
|
||||
|
||||
export class Downloader {
|
||||
static bar: progress.MultiBar | null;
|
||||
|
||||
static createProgressBar() {
|
||||
if (Downloader.bar == null) {
|
||||
Downloader.bar = new progress.MultiBar(
|
||||
{
|
||||
clearOnComplete: true,
|
||||
},
|
||||
progress.Presets.shades_grey,
|
||||
);
|
||||
}
|
||||
return Downloader.bar.create(0, 0);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()!)));
|
||||
}
|
||||
return ps.wait(stream);
|
||||
}
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
import path from "path";
|
||||
|
||||
export class Env {
|
||||
static set(key: string, value: string) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
static get(key: string) {
|
||||
return process.env[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
import async from "async";
|
||||
import child_process from "child_process";
|
||||
import { Log } from "./log";
|
||||
|
||||
const log = new Log("exec");
|
||||
|
||||
const queue = async.queue((task: any, done: any) => {
|
||||
log.d("*%s*", task.command);
|
||||
//process.chdir(task.dir);
|
||||
child_process.exec(task.command, { cwd: task.dir, maxBuffer: 1024 * 10000 }, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
log.v("!%s!", err);
|
||||
task.failure("\n" + (stderr || stdout || err));
|
||||
} else {
|
||||
log.v("%s", stdout);
|
||||
task.success({ stdout: stdout, stderr: stderr });
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
export default (dir: string, command: string) => {
|
||||
return new Promise((success, failure) => {
|
||||
queue.push({
|
||||
dir: dir,
|
||||
command: command,
|
||||
success: success,
|
||||
failure: failure,
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import colors from "ansi-colors";
|
||||
|
||||
const Level = {
|
||||
VERBOSE: -1,
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
};
|
||||
|
||||
const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
|
||||
|
||||
const formatTime = (date: Date): string => date.toTimeString().split(" ")[0];
|
||||
|
||||
export class Log {
|
||||
static level = level;
|
||||
static colorPatterns: [string, (m: string) => string][] = [
|
||||
["_", colors.cyan],
|
||||
["\\*", colors.magenta],
|
||||
["!", colors.red],
|
||||
];
|
||||
|
||||
static colorize(pattern: string) {
|
||||
for (const item of this.colorPatterns) {
|
||||
const r = new RegExp(item[0] + "(.*?)" + item[0], "g");
|
||||
pattern = pattern.replace(r, item[1]("$1"));
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
|
||||
static write(level: number, tag: string, pattern: string, args: any[]) {
|
||||
if (level >= this.level) {
|
||||
const message = `[${colors.gray(formatTime(new Date()))}] ${colors.green(tag)} ${this.colorize(pattern)}`;
|
||||
console.log(message, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
public tag: string;
|
||||
|
||||
constructor(tag: string) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
v(message: string, ...args: any) {
|
||||
Log.write(-1, this.tag, message, args);
|
||||
}
|
||||
|
||||
d(message: string, ...args: any) {
|
||||
Log.write(0, this.tag, message, args);
|
||||
}
|
||||
|
||||
i(message: string, ...args: any) {
|
||||
Log.write(1, this.tag, message, args);
|
||||
}
|
||||
|
||||
w(message: string, ...args: any) {
|
||||
Log.write(2, this.tag, message, args);
|
||||
}
|
||||
|
||||
e(message: string, ...args: any) {
|
||||
Log.write(3, this.tag, message, args);
|
||||
}
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
import os from "os";
|
||||
|
||||
export class System {
|
||||
static get isWindows() {
|
||||
return os.type() === "Windows_NT";
|
||||
}
|
||||
|
||||
static get isLinux() {
|
||||
return os.type() === "Linux";
|
||||
}
|
||||
|
||||
static get os() {
|
||||
return this.isWindows ? "windows" : this.isLinux ? "linux" : undefined;
|
||||
}
|
||||
|
||||
static get archInt() {
|
||||
if (os.arch() === "ia32") return 32;
|
||||
if (os.arch() === "x64") return 64;
|
||||
}
|
||||
|
||||
static get isArch32() {
|
||||
return this.archInt === 32;
|
||||
}
|
||||
|
||||
static get isArch64() {
|
||||
return this.archInt === 64;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Transform, Writable, type TransformCallback, type WritableOptions } from "stream";
|
||||
import { StringDecoder } from "string_decoder";
|
||||
|
||||
export type TailHandler = (line: string) => void;
|
||||
|
||||
export class HandlerWriter extends Writable {
|
||||
private handler: any;
|
||||
private decoder: StringDecoder;
|
||||
private data: string;
|
||||
|
||||
constructor(handler: TailHandler, options?: WritableOptions) {
|
||||
if (!options) options = {};
|
||||
options.objectMode = true;
|
||||
super(options);
|
||||
this.handler = handler;
|
||||
this.decoder = new StringDecoder(options?.defaultEncoding);
|
||||
this.data = "";
|
||||
}
|
||||
|
||||
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
||||
chunk = this.decoder.write(chunk);
|
||||
for (const line of chunk.split("\n")) {
|
||||
if (line.length) {
|
||||
this.handler(line);
|
||||
}
|
||||
}
|
||||
this.data += chunk;
|
||||
callback();
|
||||
}
|
||||
|
||||
_final(callback: (error?: Error | null) => void): void {
|
||||
this.data += this.decoder.end();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export class TailTransform extends Transform {
|
||||
constructor(private handler: TailHandler) {
|
||||
super({ objectMode: true });
|
||||
}
|
||||
|
||||
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
|
||||
if (chunk.contents && chunk.contents.pipe) {
|
||||
chunk.contents.pipe(new HandlerWriter(this.handler));
|
||||
}
|
||||
this.push(chunk);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export const tail = (handler: TailHandler) => new TailTransform(handler);
|
||||
@@ -0,0 +1,6 @@
|
||||
export const streamToPromise = (stream: any) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", resolve);
|
||||
stream.on("error", reject);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Transform, type TransformCallback } from "stream";
|
||||
import { Tail } from "tail";
|
||||
import Vinyl from "vinyl";
|
||||
|
||||
export type WatchHandler = (line: string) => string | undefined;
|
||||
|
||||
export interface WatchParams {
|
||||
source: string;
|
||||
handler?: WatchHandler;
|
||||
}
|
||||
|
||||
class BufferingTransform extends Transform {
|
||||
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
|
||||
this.push(chunk);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
export class TailVinyl extends Vinyl {
|
||||
private tail?: Tail;
|
||||
|
||||
constructor(params: WatchParams) {
|
||||
super({ path: "out.log", contents: new BufferingTransform() });
|
||||
if (params.source) {
|
||||
this.tail = new Tail(params.source);
|
||||
this.tail.on("line", (line) => {
|
||||
if (params.handler) {
|
||||
line = params.handler(line);
|
||||
}
|
||||
if (line) {
|
||||
this.contents.write(line + "\n");
|
||||
}
|
||||
});
|
||||
this.tail.on("error", (error) => this.contents.write("error: " + error));
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
return new Vinyl({
|
||||
cwd: this.cwd,
|
||||
base: this.base,
|
||||
history: this.history.slice(),
|
||||
contents: this.contents,
|
||||
});
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.tail?.unwatch();
|
||||
this.contents.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
export class WatchVinylTransform extends Transform {
|
||||
constructor(private params: WatchParams) {
|
||||
super({ objectMode: true });
|
||||
}
|
||||
|
||||
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
|
||||
const log = new TailVinyl(this.params);
|
||||
this.on("end", () => log.dispose());
|
||||
this.push(log);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export const watch = (source: string, handler?: WatchHandler) => new WatchVinylTransform({ source, handler });
|
||||
@@ -0,0 +1,134 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
|
||||
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 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 LibDef {
|
||||
name: string;
|
||||
version: string;
|
||||
git?: string;
|
||||
branch?: string;
|
||||
}
|
||||
|
||||
export interface AndroidPreset {
|
||||
path: string;
|
||||
extensions: string[];
|
||||
}
|
||||
|
||||
export interface SignKey {
|
||||
store: string;
|
||||
pass: string;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
static absolutePath(file: string): string {
|
||||
const result = path.resolve(process.cwd(), path.normalize(file));
|
||||
return os.type() === "Windows_NT" ? result.split("\\").join("/") : result;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Downloader } from "../common/download";
|
||||
import { Log } from "../common/log";
|
||||
|
||||
export class Sdk {
|
||||
static _dir: string;
|
||||
|
||||
static set dir(value) {
|
||||
Sdk._dir = value;
|
||||
}
|
||||
|
||||
static get dir() {
|
||||
return Sdk._dir || path.join(os.homedir(), "sdk");
|
||||
}
|
||||
|
||||
static path(name: string, version: string) {
|
||||
return path.join(this.dir, name, version);
|
||||
}
|
||||
|
||||
public name: string;
|
||||
public version: string;
|
||||
public log: Log;
|
||||
public path: string;
|
||||
|
||||
constructor(name: string, version: string) {
|
||||
this.name = name;
|
||||
this.log = new Log(name);
|
||||
this.version = version;
|
||||
this.path = Sdk.path(name, version);
|
||||
}
|
||||
|
||||
get intVersion() {
|
||||
const vArr = this.version.split("\.").reverse();
|
||||
let m = 1;
|
||||
let r = 0;
|
||||
for (let v of vArr) {
|
||||
r += parseInt(v) * m;
|
||||
m *= 10;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
get prepared(): boolean {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
prepare(strip = 1): Promise<any> {
|
||||
this.log.i("version: *%s*", this.version);
|
||||
if (this.prepared) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
this.log.i("download: *%s*", this.link);
|
||||
return Downloader.download(this.link, this.path, strip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export const 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",
|
||||
};
|
||||
Executable
+263
@@ -0,0 +1,263 @@
|
||||
// @ts-nocheck
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import through from "through2";
|
||||
import tmp from "tmp-file";
|
||||
import exec from "../common/exec";
|
||||
import { Sdk } from "../core/sdk";
|
||||
|
||||
// TODO: refactor or remove
|
||||
export class AdobeAir extends Sdk {
|
||||
static ID = "adobe-air";
|
||||
|
||||
static VERSION_26 = "26.0";
|
||||
static VERSION_25 = "25.0";
|
||||
static VERSION_24 = "24.0";
|
||||
static VERSION = AdobeAir.VERSION_26;
|
||||
|
||||
get adtBin(): string {
|
||||
return `${this.path}/bin/adt.bat`;
|
||||
}
|
||||
|
||||
get adlBin(): string {
|
||||
return `${this.path}/bin/adl.exe`;
|
||||
}
|
||||
|
||||
static buildAdtArgs(
|
||||
params: any,
|
||||
descriptor: { path: string },
|
||||
keystore: { path: string; storepass: string },
|
||||
files: { path: string; base: string }[],
|
||||
output: string,
|
||||
) {
|
||||
//const quote = (value) => `"${value}"`;
|
||||
const quote = (value: string): string => value; // TODO:
|
||||
const command = ["-package"];
|
||||
const target = params.target || "native";
|
||||
if (target !== "native") command.push("-target", target); //TODO: adobe bleat' (target param position in native and apk-captive-runtime targets)
|
||||
if (params.useLegacyAOT) {
|
||||
command.push("-useLegacyAOT", "yes");
|
||||
}
|
||||
if (params.profile) {
|
||||
command.push("-provisioning-profile", quote(params.profile));
|
||||
}
|
||||
if (keystore) {
|
||||
command.push("-storetype", "PKCS12");
|
||||
command.push("-keystore", keystore.path);
|
||||
command.push("-storepass", keystore.storepass);
|
||||
}
|
||||
if (params.target === "native") {
|
||||
command.push("-tsa", "http://sha256timestamp.ws.symantec.com/sha256/timestamp");
|
||||
command.push("-target", target);
|
||||
}
|
||||
command.push(quote(output), quote(descriptor.path));
|
||||
if (params.extdir) {
|
||||
command.push("-extdir", quote(params.extdir));
|
||||
}
|
||||
if (params.content) {
|
||||
for (let k in params.content)
|
||||
if (params.content.hasOwnProperty(k)) {
|
||||
command.push("-C", quote(k), quote(params.content[k]));
|
||||
}
|
||||
}
|
||||
for (let file of files) {
|
||||
command.push("-C", quote(file.base), quote(file.path.split(file.base)[1]));
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
constructor(version?: string) {
|
||||
super(AdobeAir.ID, version || AdobeAir.VERSION);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
return fs.existsSync(`${this.path}/air-sdk-description.xml`);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return `http://airdownload.adobe.com/air/win/download/${this.version}/AIRSDK_Compiler.zip`;
|
||||
}
|
||||
|
||||
adt(path: string, args: any) {
|
||||
return exec(path, [this.adtBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
adl(path: string, args: any) {
|
||||
return exec(path, [this.adlBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
pack(params: any) {
|
||||
const files = [];
|
||||
let descriptor = null;
|
||||
let keystore = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case "descriptor":
|
||||
descriptor = file;
|
||||
break;
|
||||
case "keystore":
|
||||
keystore = file;
|
||||
break;
|
||||
default:
|
||||
files.push(file);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback: any) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "build", params.target), "=>", col.magenta(params.outputFile));
|
||||
if (!descriptor) {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: "descriptor is not defined" }));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
const tmpFile = tmp.generateFile();
|
||||
const command = AdobeAir.buildAdtArgs(params, descriptor, keystore, files, tmpFile.path);
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(
|
||||
new gutil.File({
|
||||
path: params.outputFile,
|
||||
contents: fs.createReadStream(tmpFile.path),
|
||||
}),
|
||||
);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
return (stream = through.obj(bufferContents, endStream));
|
||||
}
|
||||
|
||||
install() {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "install"), col.magenta(file.name));
|
||||
const command = ["-installApp", "-platform", "android", "-package", file.path];
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return (stream = through.obj(bufferContents));
|
||||
}
|
||||
|
||||
launch(appid) {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "launch"), col.magenta(appid));
|
||||
const command = ["-launchApp", "-platform", "android", "-appid", appid];
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return (stream = through.obj(bufferContents));
|
||||
}
|
||||
|
||||
test(params) {
|
||||
let root = null;
|
||||
let descriptor = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case "descriptor":
|
||||
descriptor = file;
|
||||
break;
|
||||
default:
|
||||
root = file;
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback) => {
|
||||
gutil.log(this.tag, col.cyan("adl"));
|
||||
//const command = AdobeAir.buildAdtArgs(params, files, tmpFile.path);
|
||||
const command = [];
|
||||
if (params.profile) command.push("-profile", params.profile);
|
||||
if (params.extdir) command.push("-extdir", params.extdir);
|
||||
if (!descriptor) {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: "descriptor is not defined" }));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
command.push(descriptor.path);
|
||||
command.push(root.path);
|
||||
if (params.args) {
|
||||
command.push("--");
|
||||
for (let key of Object.keys(params.args)) {
|
||||
const value = params.args[key];
|
||||
if (value === true) {
|
||||
command.push(`-${key}`);
|
||||
} else if (value) {
|
||||
command.push(`-${key}`, `${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.adl(".", command)
|
||||
.then(() => {
|
||||
stream.emit("end");
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
|
||||
//callback();
|
||||
stream.push(root);
|
||||
};
|
||||
|
||||
return (stream = through.obj(bufferContents, endStream));
|
||||
}
|
||||
|
||||
static descriptor(template, values) {
|
||||
const tmpFile = tmp.generateFile();
|
||||
const patterns = [];
|
||||
for (let k in values)
|
||||
if (values.hasOwnProperty(k)) {
|
||||
patterns.push({ match: k, replacement: values[k] });
|
||||
}
|
||||
return gulp
|
||||
.src(template)
|
||||
.pipe(replace({ patterns: patterns }))
|
||||
.pipe(mark.set("descriptor"))
|
||||
.pipe(gulp.dest(tmpFile.path));
|
||||
}
|
||||
|
||||
static keystore(keystore, storepass) {
|
||||
return gulp.src(keystore).pipe(
|
||||
through.obj((file, enc, callback) => {
|
||||
file.mark = "keystore";
|
||||
file.storepass = storepass;
|
||||
callback(null, file);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
static pack(params) {
|
||||
return new AdobeAir().pack(params);
|
||||
}
|
||||
|
||||
static test(params) {
|
||||
return new AdobeAir().test(params);
|
||||
}
|
||||
}
|
||||
Executable
+258
@@ -0,0 +1,258 @@
|
||||
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 exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import { HandlerWriter } from "../common/tail";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Command } from "../run/command";
|
||||
|
||||
export class Android extends Sdk {
|
||||
static ID = "android";
|
||||
|
||||
static VERSION_7302050 = "7302050";
|
||||
static VERSION = Android.VERSION_7302050;
|
||||
|
||||
static NDK_VERSION_R15C = "r15c";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R15C;
|
||||
|
||||
private ndk_version: string;
|
||||
private repository: string;
|
||||
|
||||
constructor(version?: string, ndkVersion?: string) {
|
||||
super(Android.ID, version || Android.VERSION);
|
||||
this.ndk_version = ndkVersion || Android.NDK_VERSION;
|
||||
this.repository = "https://dl.google.com/android/repository";
|
||||
}
|
||||
|
||||
get prepared(): boolean {
|
||||
try {
|
||||
return fs.existsSync(this.sdkmanager_bin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
return `${this.repository}/commandlinetools-${System.os}-${this.version}_latest.zip`;
|
||||
}
|
||||
|
||||
get android_home(): string {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
get ndk_home(): string {
|
||||
return path.join(this.path, "ndk-bundle");
|
||||
}
|
||||
|
||||
get sdkmanager_bin(): string {
|
||||
return path.join(this.path, "cmdline-tools/bin/sdkmanager");
|
||||
}
|
||||
|
||||
prepare(): Promise<any> {
|
||||
const result = [];
|
||||
result.push(super.prepare(0));
|
||||
if (!fs.existsSync(path.join(this.ndk_home))) {
|
||||
result.push(this.prepare_ndk());
|
||||
}
|
||||
return Promise.all(result);
|
||||
}
|
||||
|
||||
prepare_ndk(): Promise<any> {
|
||||
// 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);
|
||||
}
|
||||
|
||||
sdkmanager(packages: string[]) {
|
||||
this.log.i("sdkmanager: *%s*", packages.join(", "));
|
||||
const installedFile = path.join(this.path, ".installed");
|
||||
const installed = new Set(
|
||||
fs.existsSync(installedFile) ? fs.readFileSync(installedFile, { encoding: "utf8" }).split("\n") : [],
|
||||
);
|
||||
const install = new Set(packages);
|
||||
for (const key of installed) {
|
||||
if (install.has(key)) {
|
||||
install.delete(key);
|
||||
}
|
||||
}
|
||||
if (install.size === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const sdkmanagerBin = this.sdkmanager_bin;
|
||||
if (fs.existsSync(sdkmanagerBin)) {
|
||||
fs.chmodSync(sdkmanagerBin, 0o755);
|
||||
}
|
||||
const yes = '(while sleep 3; do echo "y"; done)';
|
||||
const command = [yes, "|", sdkmanagerBin]
|
||||
.concat(Array.from(install).map((name) => `"${name}"`))
|
||||
.concat([`--sdk_root="${this.path}"`])
|
||||
.join(" ");
|
||||
return exec(".", command).then(() => {
|
||||
for (const key of install) {
|
||||
installed.add(key);
|
||||
}
|
||||
fs.writeFileSync(installedFile, Array.from(installed).join("\n"), { encoding: "utf8" });
|
||||
});
|
||||
}
|
||||
|
||||
activate() {
|
||||
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 {
|
||||
return path.join(this.path, "platform-tools/adb");
|
||||
}
|
||||
|
||||
adb(args: any) {
|
||||
return exec(".", [this.adbBin].concat(args).join(" ")).then((data: any) => {
|
||||
for (let line of data.stderr.split("\n")) {
|
||||
if (line.indexOf("Error") > -1) {
|
||||
throw line;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
buildTool(name: string) {
|
||||
let buildToolsVersion = ""; // TODO: default build-tools version value
|
||||
fs.readdirSync(path.join(this.path, "build-tools")).forEach((file) => {
|
||||
buildToolsVersion = file;
|
||||
});
|
||||
return path.join(this.path, "build-tools", buildToolsVersion, name);
|
||||
}
|
||||
|
||||
aapt(args: any) {
|
||||
const aaptBin = this.buildTool("aapt");
|
||||
return exec(".", [aaptBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
apk() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self.aapt(["l", "-a", file.path]).then((data: any) => {
|
||||
let activity = false;
|
||||
for (let line of data.stdout.split("\n")) {
|
||||
if (line.indexOf("package") > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) file.package = value[1];
|
||||
}
|
||||
if (line.indexOf("activity") > -1) {
|
||||
activity = true;
|
||||
}
|
||||
if (activity && line.indexOf("name") > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) {
|
||||
file.activity = value[1];
|
||||
activity = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_installApk(filename: string, pack: string) {
|
||||
this.log.i("install *%s*", filename);
|
||||
return this.adb(["install", "-r", "-d", filename])
|
||||
.then(() => {
|
||||
return false;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")) {
|
||||
this.log.w("!INSTALL FAILED UPDATE INCOMPATIBLE!");
|
||||
return true;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.then((reinstall) => {
|
||||
if (reinstall) {
|
||||
this.log.i("uninstall *%s*", pack);
|
||||
return this.adb(["uninstall", pack]).then(() => {
|
||||
this.log.i("install *%s*", filename);
|
||||
return this.adb(["install", "-r", "-d", filename]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
install() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self._installApk(file.path, file.package).then(() => {
|
||||
// ToDo: kludge: delay before start
|
||||
setTimeout(() => {
|
||||
this.push(file);
|
||||
callback();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
const name = `${file.package}/${file.activity}`;
|
||||
self.log.i("start *%s*", name);
|
||||
self.adb(["shell", "am", "start", "-n", name]).then(() => {
|
||||
setTimeout(() => {
|
||||
self.adb(["shell", `"ps | grep ${file.package}"`]).then((result) => {
|
||||
file.pid = result.stdout.split(/\s+/)[1];
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
logcat() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
const cmd = `${self.adbBin} logcat --pid ${file.pid}`;
|
||||
const command = new Command(cmd).exec();
|
||||
this.push(command);
|
||||
command.contents.pipe(
|
||||
new HandlerWriter((line: string) => {
|
||||
if (line.includes("SDL") && (line.includes("onDestroy()") || line.includes("onStop()"))) {
|
||||
callback();
|
||||
throw "Exit"; // ToDo:
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
sign(keystore: string, keypass: string) {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self.log.i("sign *%s*", file.path);
|
||||
const filename = path.join(os.tmpdir(), "tmp.apk");
|
||||
fs.writeFileSync(filename, file.contents);
|
||||
const cmd = [
|
||||
self.buildTool("apksigner"),
|
||||
"sign",
|
||||
"--ks",
|
||||
keystore,
|
||||
"--ks-pass",
|
||||
`pass:${keypass}`,
|
||||
filename,
|
||||
].join(" ");
|
||||
exec(".", cmd).then(() => {
|
||||
file.contents = fs.readFileSync(filename);
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+123
@@ -0,0 +1,123 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { watch } from "../common/watch";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run";
|
||||
|
||||
export class FlashPlayer extends Sdk {
|
||||
static ID = "flashplayer";
|
||||
|
||||
static VERSION_24 = "24";
|
||||
static VERSION_25 = "25";
|
||||
static VERSION_26 = "26";
|
||||
static VERSION_27 = "27";
|
||||
static VERSION_28 = "28";
|
||||
static VERSION_29 = "29";
|
||||
static VERSION_30 = "30";
|
||||
static VERSION_31 = "31";
|
||||
static VERSION_32 = "32";
|
||||
|
||||
static VERSION = FlashPlayer.VERSION_32;
|
||||
|
||||
BASE_URL = "https://fpdownload.macromedia.com/pub/flashplayer/updaters";
|
||||
|
||||
private debug: boolean;
|
||||
protected baseUrl: string;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return super.prepare(0);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.flashPlayerBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
const baseUrl = `${this.baseUrl}/${this.version}`;
|
||||
if (System.isWindows) {
|
||||
return baseUrl + `/flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
||||
} else if (System.isLinux) {
|
||||
return baseUrl + `/flash_player_sa_linux${this.debug ? "_debug" : ""}.x86_64.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
get flashPlayerBin(): string {
|
||||
if (System.isWindows) {
|
||||
const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
||||
return path.join(this.path, playerName);
|
||||
} else if (System.isLinux) {
|
||||
const binPath = path.join(this.path, `flashplayer${this.debug ? "debugger" : ""}`);
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
return binPath;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
static get flashPlayerDir(): string {
|
||||
if (os.type() === "Windows_NT") {
|
||||
return path.join(process.env.APPDATA!, "Macromedia", "Flash Player");
|
||||
} else if (os.type() === "Linux") {
|
||||
return path.join(os.homedir(), ".macromedia", "Flash_Player");
|
||||
} else {
|
||||
throw `Unuspported os: ${os.type()}`;
|
||||
}
|
||||
}
|
||||
|
||||
static get log() {
|
||||
return path.join(this.flashPlayerDir, "Logs", "flashlog.txt");
|
||||
}
|
||||
|
||||
static enableLog() {
|
||||
const filename = path.join(os.homedir(), "mm.cfg");
|
||||
const value = "TraceOutputFileEnable=1";
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename, "utf8");
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
fse.ensureDirSync(path.join(this.flashPlayerDir, "Logs"));
|
||||
fs.writeFileSync(FlashPlayer.log, "");
|
||||
}
|
||||
|
||||
static trust(value: string) {
|
||||
const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg");
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename, "utf8");
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
if (!fs.existsSync(path.dirname(filename))) {
|
||||
fse.ensureDirSync(path.dirname(filename));
|
||||
}
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
FlashPlayer.trust(filename);
|
||||
FlashPlayer.enableLog();
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params).exec().pipe(watch(FlashPlayer.log));
|
||||
}
|
||||
}
|
||||
Executable
+243
@@ -0,0 +1,243 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import rename from "gulp-rename";
|
||||
import template from "lodash.template";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import vfs from "vinyl-fs";
|
||||
import { Env } from "../common/env";
|
||||
import exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import type { Config, LibDef } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Neko } from "./neko";
|
||||
|
||||
export class Haxe extends Sdk {
|
||||
static ID = "haxe";
|
||||
|
||||
static VERSION_3_4_0 = "3.4.0";
|
||||
static VERSION_3_4_2 = "3.4.2";
|
||||
static VERSION_3_4_3 = "3.4.3";
|
||||
static VERSION_3_4_7 = "3.4.7";
|
||||
static VERSION_3 = Haxe.VERSION_3_4_7;
|
||||
static VERSION_4_0_0 = "4.0.0";
|
||||
static VERSION_4_0_1 = "4.0.1";
|
||||
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 = Haxe.VERSION_4;
|
||||
|
||||
static buildDir = path.join(process.cwd(), "build");
|
||||
|
||||
getBin(name: string) {
|
||||
if (System.isWindows) {
|
||||
return path.join(this.path, name + ".exe");
|
||||
} else if (System.isLinux) {
|
||||
const binPath = path.join(this.path, name);
|
||||
if (fs.existsSync(binPath)) {
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
}
|
||||
return binPath;
|
||||
}
|
||||
throw `Unsupported OS: ${os.type()}`;
|
||||
}
|
||||
|
||||
get haxeBin() {
|
||||
return this.getBin("haxe");
|
||||
}
|
||||
|
||||
get haxelibBin() {
|
||||
return this.getBin("haxelib");
|
||||
}
|
||||
|
||||
private neko: Neko;
|
||||
|
||||
constructor(version?: string) {
|
||||
super(Haxe.ID, version || Haxe.VERSION);
|
||||
this.neko = new Neko();
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.haxeBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
|
||||
fs.copyFileSync(
|
||||
path.resolve(import.meta.dirname, "..", "template/haxe/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
if (System.isWindows) {
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-win.zip`;
|
||||
} else if (System.isLinux) {
|
||||
let arch = System.archInt;
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-linux${arch}.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os: ${System.os}`;
|
||||
}
|
||||
}
|
||||
|
||||
haxe(args: any) {
|
||||
this.activate();
|
||||
return exec(".", [this.haxeBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
haxelib(args: any) {
|
||||
this.activate();
|
||||
return exec(".", [this.haxelibBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
resolveBuildDir(config: Config) {
|
||||
return path.join(Haxe.buildDir, config.name);
|
||||
}
|
||||
|
||||
openfl(command: string, platform: string, config: Config, debug = false) {
|
||||
this.log.i("_openfl_ _build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.xml"), "utf8"),
|
||||
);
|
||||
const project = projectTemplate({ ...config, buildDir: buildDir });
|
||||
fs.writeFileSync(path.resolve(buildDir, "project.xml"), project);
|
||||
|
||||
const args = ["-cwd", buildDir, "run", "openfl", command, platform];
|
||||
if (debug) {
|
||||
args.push("-debug");
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, "bin");
|
||||
fse.emptyDirSync(target);
|
||||
const result =
|
||||
{
|
||||
android: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
|
||||
flash: "*.swf",
|
||||
}[platform] || "**/*";
|
||||
return this.haxelib(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "android") {
|
||||
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
build(platform: string, config: Config, debug = false) {
|
||||
this.log.i("_build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.hxml"), "utf8"),
|
||||
);
|
||||
|
||||
const ext =
|
||||
{
|
||||
flash: ".swf",
|
||||
neko: ".n",
|
||||
}[platform] || "";
|
||||
|
||||
const out =
|
||||
{
|
||||
flash: "swf",
|
||||
}[platform] || platform;
|
||||
|
||||
const project = projectTemplate({ ...config, buildDir: buildDir, platform: platform, ext: ext, out: out });
|
||||
const projectHXML = path.resolve(buildDir, "project.hxml");
|
||||
fs.writeFileSync(projectHXML, project);
|
||||
|
||||
const args = [projectHXML];
|
||||
if (debug) {
|
||||
args.push("-debug");
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, "bin");
|
||||
if (platform !== "cpp") {
|
||||
fse.emptyDirSync(target);
|
||||
}
|
||||
for (const asset of config.assets) {
|
||||
fse.copySync(asset, path.join(target, asset.split("/").pop()!));
|
||||
}
|
||||
const result =
|
||||
{
|
||||
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
|
||||
}[platform] || "**/*";
|
||||
return this.haxe(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "cpp") {
|
||||
r = r.pipe(rename(config.meta.filename!));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
install(packages: Record<string, string> | LibDef[]) {
|
||||
this.activate();
|
||||
let promise = this.haxelib(["setup", path.join(this.path, "lib")]);
|
||||
const next = (args: any) => () => {
|
||||
this.log.i("_haxelib_ _install_ *%s:%s*", args[1], args[2]);
|
||||
return this.haxelib(args);
|
||||
};
|
||||
|
||||
if (!Array.isArray(packages)) {
|
||||
packages = Object.entries(packages).map(([k, v]) => ({ name: k, version: v }));
|
||||
}
|
||||
|
||||
for (let pack of packages) {
|
||||
const args = [];
|
||||
let version = null;
|
||||
if (typeof pack === "string") {
|
||||
args.push("install", pack);
|
||||
} else if (typeof pack === "object") {
|
||||
version = pack.version;
|
||||
if (version.substr(0, 3) === "git") {
|
||||
pack.git = version;
|
||||
version = null;
|
||||
}
|
||||
if (pack.git) {
|
||||
args.push("git", pack.name, pack.git);
|
||||
if (pack.branch) args.push(pack.branch);
|
||||
} else {
|
||||
args.push("install", pack.name);
|
||||
if (version) args.push(version);
|
||||
}
|
||||
args.push("--always");
|
||||
}
|
||||
let path = `${this.path}/lib/${args[1]}`;
|
||||
if (version) {
|
||||
path += `/${version.replace(/\./g, ",")}`;
|
||||
} else if (pack.git) {
|
||||
path += "/git";
|
||||
}
|
||||
if (!fs.existsSync(path)) {
|
||||
promise = promise.then(next(args));
|
||||
}
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
let promise = this.haxelib(["setup", path.join(this.path, "lib")]);
|
||||
promise = promise.then(() => this.haxelib(["upgrade", "--always"]));
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import template from "lodash.template";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import exec from "../common/exec";
|
||||
import type { Config } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
|
||||
export class InnoSetup extends Sdk {
|
||||
static ID = "innosetup";
|
||||
static VERSION = "6";
|
||||
|
||||
constructor(version?: string) {
|
||||
super(InnoSetup.ID, version || InnoSetup.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return "http://www.jrsoftware.org/download.php/is.exe";
|
||||
}
|
||||
|
||||
prepare(strip = 1) {
|
||||
let result = super.prepare(strip);
|
||||
if (!this.prepared) {
|
||||
result = result.then(() => {
|
||||
return exec(this.path, `is.exe /VERYSILENT /SUPPRESSMSGBOXES /DIR=${this.path}`);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
get isccBin() {
|
||||
return path.join(this.path, "ISCC.exe");
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.isccBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pack(config: Config, source: string, output: string) {
|
||||
const buildDir = path.join(os.tmpdir(), "build", config.name, "innosetup");
|
||||
const appTemplate = template(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/windows/app.iss"), "utf8"),
|
||||
);
|
||||
const app = appTemplate({ ...config, buildDir: buildDir, output: output });
|
||||
|
||||
fse.ensureDirSync(buildDir);
|
||||
fse.copySync(`${source}`, `${buildDir}`);
|
||||
|
||||
fs.writeFileSync(path.resolve(buildDir, "app.iss"), app);
|
||||
return exec(buildDir, [`"${this.isccBin}"`, "app.iss"].join(" "));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run/index";
|
||||
|
||||
export class NekoLink {
|
||||
static get type() {
|
||||
switch (os.type()) {
|
||||
case "Linux":
|
||||
return "linux";
|
||||
case "Windows_NT":
|
||||
return "win";
|
||||
}
|
||||
}
|
||||
|
||||
static get arch() {
|
||||
switch (os.arch()) {
|
||||
case "ia32":
|
||||
return "";
|
||||
case "x64":
|
||||
return "64";
|
||||
}
|
||||
}
|
||||
|
||||
static get ext() {
|
||||
switch (os.type()) {
|
||||
case "Linux":
|
||||
return "tar.gz";
|
||||
case "Windows_NT":
|
||||
return "zip";
|
||||
}
|
||||
}
|
||||
|
||||
static get(version: string) {
|
||||
const vv = version.split("\.").join("-");
|
||||
const filename = `neko-${version}-${NekoLink.type}${NekoLink.arch}.${NekoLink.ext}`;
|
||||
return `https://github.com/HaxeFoundation/neko/releases/download/v${vv}/${filename}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class Neko extends Sdk {
|
||||
static ID = "neko";
|
||||
|
||||
static VERSION_2_2_0 = "2.2.0";
|
||||
static VERSION = Neko.VERSION_2_2_0;
|
||||
|
||||
constructor(version?: string) {
|
||||
super(Neko.ID, version || Neko.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return NekoLink.get(this.version);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.nekoBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
activate() {
|
||||
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(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
get nekoBin() {
|
||||
let binname = "neko";
|
||||
if (os.type() === "Windows_NT") binname += ".exe";
|
||||
return path.join(this.path, binname);
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
this.activate();
|
||||
return run(`${this.nekoBin} ${filename}`, params).exec();
|
||||
}
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { watch } from "../common/watch";
|
||||
import run from "../run";
|
||||
import { FlashPlayer } from "./flashplayer";
|
||||
|
||||
export class RufflePlayer extends FlashPlayer {
|
||||
static ID = "ruffle";
|
||||
|
||||
static VERSION_2026_05_15 = "nightly-2026_05_15";
|
||||
static VERSION_2026_10_13 = "nightly-2026_10_13";
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
const nightly = this.version.includes("nightly");
|
||||
const baseUrl = `${this.baseUrl}/${nightly ? "" : "v"}${this.version.replaceAll("_", "-")}`;
|
||||
if (System.isWindows) {
|
||||
return baseUrl + `/ruffle-${this.version}-windows-x86_64.zip`;
|
||||
} else if (System.isLinux) {
|
||||
return baseUrl + `/ruffle-${this.version}-linux-x86_64.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
get flashPlayerBin(): string {
|
||||
if (System.isWindows) {
|
||||
return path.join(this.path, "ruffle.exe");
|
||||
} else if (System.isLinux) {
|
||||
return path.join(this.path, "ruffle");
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
static get log(): string {
|
||||
return path.join(os.homedir(), ".cache/ruffle/log/ruffle.log");
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params)
|
||||
.exec()
|
||||
.pipe(
|
||||
watch(RufflePlayer.log, (line: string) => {
|
||||
if (line.includes("avm_trace")) {
|
||||
return line.split("avm_trace: ").pop();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export * from "./common/system";
|
||||
export * from "./core/config";
|
||||
export * from "./common/download";
|
||||
export * from "./core/sdk";
|
||||
export * from "./core/type";
|
||||
export * from "./impl/android";
|
||||
export * from "./impl/flashplayer";
|
||||
export * from "./impl/haxe";
|
||||
export * from "./impl/innosetup";
|
||||
export * from "./impl/neko";
|
||||
export * from "./impl/ruffle";
|
||||
export * from "./project";
|
||||
export * from "./project/impl";
|
||||
export * from "./project/preset";
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Config } from "../../core/config";
|
||||
import { Target } from "./target";
|
||||
|
||||
export class Builder extends Target {
|
||||
static factory: Record<string, typeof Builder> = {};
|
||||
|
||||
public buildSystem: string;
|
||||
public debug: boolean;
|
||||
|
||||
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
|
||||
super(config, platform);
|
||||
this.buildSystem = buildSystem;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
static register(buildSystem: string, builder: typeof Builder) {
|
||||
Builder.factory[buildSystem] = builder;
|
||||
}
|
||||
|
||||
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder {
|
||||
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./builder";
|
||||
export * from "./packer";
|
||||
export * from "./runner";
|
||||
export * from "./target";
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { Config } from "../../core/config";
|
||||
import { Target } from "./target";
|
||||
|
||||
export type PackerFactory = new (config: Config) => Packer;
|
||||
|
||||
export class Packer extends Target {
|
||||
static factory: Record<string, Record<string, PackerFactory>> = {};
|
||||
|
||||
call() {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
static register(platform: string, 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import gulp from "gulp";
|
||||
import rename from "gulp-rename";
|
||||
import { DEBUG } from "../../common/debug";
|
||||
import { tail } from "../../common/tail";
|
||||
import { Config } from "../../core/config";
|
||||
import { Target } from "./target";
|
||||
|
||||
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
|
||||
|
||||
export class Runner extends Target {
|
||||
static factory: Record<string, RunnerFactory> = {};
|
||||
|
||||
public debug: boolean;
|
||||
|
||||
constructor(config: Config, platform: string, 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));
|
||||
}
|
||||
|
||||
static register(platform: string, runner: RunnerFactory) {
|
||||
Runner.factory[platform] = runner;
|
||||
}
|
||||
|
||||
static new(config: Config, platform: string, debug: boolean): Runner {
|
||||
return new Runner.factory[platform](config, debug);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import path from "path";
|
||||
import type { Config } from "../../core/config";
|
||||
|
||||
export class Target {
|
||||
public config: Config;
|
||||
public platform: string;
|
||||
public target: string;
|
||||
|
||||
constructor(config: Config, platform: string) {
|
||||
this.config = config;
|
||||
this.platform = platform;
|
||||
this.target = "target";
|
||||
}
|
||||
|
||||
prepare(): Promise<any> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
call() {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
resolveTargetPath(platform = this.platform): string {
|
||||
return path.resolve(this.target, this.config.name, platform);
|
||||
}
|
||||
|
||||
get targetPath(): string {
|
||||
return this.resolveTargetPath();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
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 { Android } from "../../../impl/android";
|
||||
import { Haxe } from "../../../impl/haxe";
|
||||
import { Builder } from "../../core/builder";
|
||||
|
||||
export class HaxeBuilder extends Builder {
|
||||
public haxe: Haxe;
|
||||
public android: Android;
|
||||
|
||||
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
|
||||
super(config, platform, buildSystem, debug);
|
||||
this.haxe = new Haxe();
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
|
||||
if (this.buildSystem === BuildSystem.OPENFL) {
|
||||
if (this.platform === Platform.ANDROID) {
|
||||
result = result
|
||||
.then(() => this.android.prepare())
|
||||
.then(() => this.android.activate())
|
||||
.then(() =>
|
||||
this.android.sdkmanager([
|
||||
// ToDo: android sdk dependencies config?
|
||||
//'tools',
|
||||
"platform-tools",
|
||||
"build-tools;27.0.3",
|
||||
"platforms;android-28", //ToDo: lime version 7.6.0 -> 28; 7.0.0 -> 26
|
||||
//'ndk-bundle',
|
||||
//'lldb;3.1',
|
||||
"cmake;3.6.4111459",
|
||||
]),
|
||||
);
|
||||
const AndroidSDK = this.android.android_home;
|
||||
const AndroidNDK = this.android.ndk_home;
|
||||
const answer = `echo "${[AndroidSDK, AndroidNDK].join("\n")}"`;
|
||||
result = result.then(() => {
|
||||
return exec(".", [answer, "|", this.haxe.haxelibBin, "run", "openfl", "setup", this.platform].join(" "));
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
switch (this.buildSystem) {
|
||||
case BuildSystem.OPENFL:
|
||||
return this.haxe.openfl("build", this.platform, this.config, this.debug).then((result) => {
|
||||
if (this.platform === Platform.ANDROID && this.config.key) {
|
||||
result = result.pipe(this.android.sign(this.config.key.store, this.config.key.pass));
|
||||
}
|
||||
return streamToPromise(result.pipe(vfs.dest(target)));
|
||||
});
|
||||
case BuildSystem.HAXE:
|
||||
return this.haxe
|
||||
.build(this.platform, this.config, this.debug)
|
||||
.then((result) => streamToPromise(result.pipe(vfs.dest(target))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Builder.register(BuildSystem.HAXE, HaxeBuilder);
|
||||
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
|
||||
@@ -0,0 +1,13 @@
|
||||
export * from "./builder/haxe";
|
||||
export * from "./packer/flash";
|
||||
export * from "./packer/linux/archive";
|
||||
export * from "./packer/linux/deb";
|
||||
export * from "./packer/windows/archive";
|
||||
export * from "./packer/windows/installer";
|
||||
export * from "./runner/android";
|
||||
export * from "./runner/flash";
|
||||
export * from "./runner/html5";
|
||||
export * from "./runner/linux";
|
||||
export * from "./runner/neko";
|
||||
export * from "./runner/ruffle";
|
||||
export * from "./runner/windows";
|
||||
@@ -0,0 +1,27 @@
|
||||
import fs from "fs";
|
||||
import template from "lodash.template";
|
||||
import path from "path";
|
||||
import type { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { Packer } from "../../core/packer";
|
||||
|
||||
export class FlashHTMLPacker extends Packer {
|
||||
static NAME = "html";
|
||||
|
||||
constructor(config: Config) {
|
||||
super(config, Platform.FLASH);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const indexTemplate = template(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html"), "utf8"),
|
||||
);
|
||||
const index = indexTemplate(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"));
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
Packer.register(Platform.FLASH, FlashHTMLPacker.NAME, FlashHTMLPacker);
|
||||
@@ -0,0 +1,26 @@
|
||||
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 { Packer } from "../../../core/packer";
|
||||
|
||||
export class LinuxArchivePacker extends Packer {
|
||||
static NAME = "archive";
|
||||
|
||||
constructor(config: Config) {
|
||||
super(config, Platform.LINUX);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_linux.tar`;
|
||||
return gulp
|
||||
.src(`${target}/**/*`)
|
||||
.pipe(tar(archiveName))
|
||||
.pipe(gzip())
|
||||
.pipe(gulp.dest(this.resolveTargetPath("archive")));
|
||||
}
|
||||
}
|
||||
|
||||
Packer.register(Platform.LINUX, LinuxArchivePacker.NAME, LinuxArchivePacker);
|
||||
@@ -0,0 +1,55 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import gulp from "gulp";
|
||||
import deb from "gulp-debian";
|
||||
import { template } from "lodash";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class LinuxDEBPacker extends Packer {
|
||||
static NAME = "deb";
|
||||
|
||||
constructor(config: Config) {
|
||||
super(config, Platform.LINUX);
|
||||
}
|
||||
|
||||
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 desktopTemplate = template(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop"), "utf8"),
|
||||
);
|
||||
const desktop = desktopTemplate(Object.assign({ 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}`);
|
||||
return gulp.src(`${buildDir}/*`).pipe(
|
||||
deb({
|
||||
package: this.config.meta.filename!,
|
||||
version: this.config.meta.version!,
|
||||
section: "base",
|
||||
priority: "optional",
|
||||
architecture: "all",
|
||||
maintainer: this.config.meta.author,
|
||||
description: this.config.meta.title,
|
||||
changelog: [],
|
||||
postinst: [
|
||||
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
|
||||
" update-menus\n" +
|
||||
"fi",
|
||||
],
|
||||
_target: "/",
|
||||
_out: this.resolveTargetPath("debian"),
|
||||
_clean: true,
|
||||
_verbose: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Packer.register(Platform.LINUX, LinuxDEBPacker.NAME, LinuxDEBPacker);
|
||||
@@ -0,0 +1,24 @@
|
||||
import gulp from "gulp";
|
||||
import zip from "gulp-zip";
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class WindowsArchivePacker extends Packer {
|
||||
static NAME = "archive";
|
||||
|
||||
constructor(config: Config) {
|
||||
super(config, Platform.WINDOWS);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_win.zip`;
|
||||
return gulp
|
||||
.src(`${target}/**/*`)
|
||||
.pipe(zip(archiveName))
|
||||
.pipe(gulp.dest(this.resolveTargetPath("archive")));
|
||||
}
|
||||
}
|
||||
|
||||
Packer.register(Platform.WINDOWS, WindowsArchivePacker.NAME, WindowsArchivePacker);
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Config } from "../../../../core/config";
|
||||
import { Platform } from "../../../../core/type";
|
||||
import { InnoSetup } from "../../../../impl/innosetup";
|
||||
import { Packer } from "../../../core/packer";
|
||||
|
||||
export class WindowsInstallerPacker extends Packer {
|
||||
static NAME = "installer";
|
||||
|
||||
public innosetup: InnoSetup;
|
||||
|
||||
constructor(config: Config) {
|
||||
super(config, Platform.WINDOWS);
|
||||
this.innosetup = new InnoSetup();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.innosetup.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
return this.innosetup.pack(this.config, this.targetPath, this.resolveTargetPath("installer"));
|
||||
}
|
||||
}
|
||||
|
||||
Packer.register(Platform.WINDOWS, WindowsInstallerPacker.NAME, WindowsInstallerPacker);
|
||||
@@ -0,0 +1,32 @@
|
||||
import gulp from "gulp";
|
||||
import type { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { Android } from "../../../impl/android";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class AndroidRunner extends Runner {
|
||||
protected android: Android;
|
||||
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, Platform.ANDROID, debug);
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.android.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
return this.log(
|
||||
gulp
|
||||
.src(`${target}/${this.config.meta.filename}_${this.config.meta.version}.apk`)
|
||||
.pipe(this.android.apk())
|
||||
.pipe(this.android.install())
|
||||
.pipe(this.android.start())
|
||||
.pipe(this.android.logcat()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.ANDROID, AndroidRunner);
|
||||
@@ -0,0 +1,27 @@
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { FlashPlayer } from "../../../impl/flashplayer";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class FlashRunner extends Runner {
|
||||
public player: FlashPlayer;
|
||||
|
||||
constructor(config: Config, debug: boolean, player: typeof FlashPlayer = FlashPlayer) {
|
||||
super(config, Platform.FLASH, debug);
|
||||
this.player = new player(debug);
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.player.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename + ".swf");
|
||||
const result = this.player.run(filename, { cwd: target, verbosity: 0 });
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.FLASH, FlashRunner);
|
||||
@@ -0,0 +1,21 @@
|
||||
import connect from "gulp-connect";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class Html5Runner extends Runner {
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, Platform.HTML5, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
return connect.server({
|
||||
root: this.targetPath,
|
||||
host: "0.0.0.0",
|
||||
port: 3000,
|
||||
fallback: "index.html",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.HTML5, Html5Runner);
|
||||
@@ -0,0 +1,30 @@
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import run from "../../../run";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class LinuxRunner extends Runner {
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, Platform.LINUX, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename!);
|
||||
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", { cwd: target, verbosity: 0 }));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.LINUX, LinuxRunner);
|
||||
|
||||
export class CPPRunner extends LinuxRunner {
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, debug);
|
||||
this.platform = Platform.CPP;
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.CPP, CPPRunner);
|
||||
@@ -0,0 +1,27 @@
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { Neko } from "../../../impl/neko";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class NekoRunner extends Runner {
|
||||
public neko: Neko;
|
||||
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, Platform.NEKO, debug);
|
||||
this.neko = new Neko();
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return this.neko.prepare();
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename + ".n");
|
||||
const result = this.neko.run(filename, { cwd: target, verbosity: 0 });
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.NEKO, NekoRunner);
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { Config } from "../../../core/config";
|
||||
import { RufflePlayer } from "../../../impl/ruffle";
|
||||
import { FlashRunner } from "./flash";
|
||||
|
||||
export class RuffleRunner extends FlashRunner {
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, debug, RufflePlayer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import run from "../../../run";
|
||||
import { Runner } from "../../core/runner";
|
||||
|
||||
export class WindowsRunner extends Runner {
|
||||
constructor(config: Config, debug: boolean) {
|
||||
super(config, Platform.WINDOWS, debug);
|
||||
}
|
||||
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
const filename = path.resolve(target, this.config.meta.filename + ".exe");
|
||||
const result = gulp.src(filename).pipe(run("<%=file.basename%>", { cwd: target, verbosity: 0 }));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
Runner.register(Platform.WINDOWS, WindowsRunner);
|
||||
@@ -0,0 +1,87 @@
|
||||
import gulp from "gulp";
|
||||
import type { Task, TaskFunction } from "undertaker";
|
||||
import { Config } from "../core/config";
|
||||
import { BuildSystem, Platform } 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 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];
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
hasLib(name: string): boolean {
|
||||
for (const lib of this.config.libs) {
|
||||
if (lib.name === name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
build(platform: string, debug: boolean = false): Task[] {
|
||||
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
|
||||
const tasks: Task[] = [builder.prepare.bind(builder)];
|
||||
tasks.push(builder.call.bind(builder));
|
||||
return tasks;
|
||||
}
|
||||
|
||||
run(platform: string, 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[] {
|
||||
return this.build(platform, debug).concat(this.run(platform, debug));
|
||||
}
|
||||
|
||||
pack(platform: string, name: string) {
|
||||
const packer = Packer.new(this.config, platform, name);
|
||||
return [packer.prepare.bind(packer), packer.call.bind(packer)];
|
||||
}
|
||||
|
||||
compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
|
||||
const result: Record<string, TaskFunction> = {};
|
||||
const _gulp = external_gulp || gulp;
|
||||
for (const platform of this.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));
|
||||
result[`${this.config.name}:${platform}:test`] = _gulp.series(this.test(platform));
|
||||
}
|
||||
if (Packer.factory[platform]) {
|
||||
for (const name of Object.keys(Packer.factory[platform])) {
|
||||
result[`${this.config.name}:${platform}:${name}`] = _gulp.series(this.pack(platform, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
register(external_gulp?: gulp.Gulp) {
|
||||
const _gulp = external_gulp || gulp;
|
||||
for (const [k, v] of Object.entries(this.compile(_gulp))) {
|
||||
_gulp.task(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
static useRuffle() {
|
||||
Runner.register(Platform.FLASH, RuffleRunner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import dateformat from "dateformat";
|
||||
import gulp from "gulp";
|
||||
import gulpClean from "gulp-clean";
|
||||
import template from "lodash.template";
|
||||
import os from "os";
|
||||
import type { Task } from "undertaker";
|
||||
import { Builder, Project } from ".";
|
||||
import { System } from "../common/system";
|
||||
import { Config, type ConfigParams } 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?: any;
|
||||
}
|
||||
|
||||
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 {
|
||||
const configTemplate = template(JSON.stringify(preset));
|
||||
return JSON.parse(
|
||||
configTemplate({ 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import colors from "ansi-colors";
|
||||
import cp from "child_process";
|
||||
import { defaults, template } from "lodash";
|
||||
import path from "path";
|
||||
import stream from "stream";
|
||||
import util from "util";
|
||||
import Vinyl from "vinyl";
|
||||
|
||||
export class Command {
|
||||
private command: string;
|
||||
private isWindows: boolean;
|
||||
private options: any;
|
||||
|
||||
constructor(command: string, options?: any) {
|
||||
this.command = command;
|
||||
this.isWindows = process.platform.lastIndexOf("win") === 0;
|
||||
this.options = defaults(options || {}, {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
verbosity: options && options.silent ? 1 : 2,
|
||||
usePowerShell: false,
|
||||
});
|
||||
|
||||
let previousPath;
|
||||
previousPath = this.options.env.PATH;
|
||||
this.options.env.PATH = path.join(this.options.cwd, "node_modules", ".bin");
|
||||
this.options.env.PATH += path.delimiter;
|
||||
this.options.env.PATH += previousPath;
|
||||
}
|
||||
|
||||
exec(stdin?: any, callback?: any) {
|
||||
let fileName;
|
||||
let directory;
|
||||
let subShell;
|
||||
|
||||
// parse the arguments, both are optional.
|
||||
// after parsing, stdin is a vinyl file to use as standard input to
|
||||
// the command (possibly empty), and callback is a function.
|
||||
if (typeof stdin === "function") {
|
||||
callback = stdin;
|
||||
stdin = undefined;
|
||||
} else if (typeof callback !== "function") {
|
||||
callback = function noop() {};
|
||||
}
|
||||
|
||||
if (!(stdin instanceof Vinyl)) {
|
||||
fileName = this.command.split(" ")[0];
|
||||
directory = path.join(this.options.cwd, fileName);
|
||||
|
||||
if (typeof stdin === "string") {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: new Buffer(stdin),
|
||||
});
|
||||
} else if (stdin instanceof Buffer || stdin instanceof stream.Readable) {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: stdin,
|
||||
});
|
||||
} else {
|
||||
stdin = new Vinyl(stdin);
|
||||
|
||||
if (!stdin.path) {
|
||||
stdin.path = directory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute the command.
|
||||
// we spawn the command in a subshell, so things like i/o redirection
|
||||
// just work. e.g. `echo hello world >> ./hello.txt` works as expected.
|
||||
const command = template(this.command)({
|
||||
file: stdin,
|
||||
});
|
||||
|
||||
if (this.isWindows && this.options.usePowerShell) {
|
||||
// windows powershell
|
||||
subShell = cp.spawn("powershell.exe", ["-NonInteractive", "-NoLogo", "-Command", command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd,
|
||||
});
|
||||
} else if (this.isWindows) {
|
||||
// windows cmd.exe
|
||||
subShell = cp.spawn("cmd.exe", ["/c", command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd,
|
||||
});
|
||||
} else {
|
||||
// POSIX shell
|
||||
subShell = cp.spawn("sh", ["-c", command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd,
|
||||
});
|
||||
}
|
||||
|
||||
// setup the output
|
||||
//
|
||||
// - if verbosity equals to 3, the command prints directly to the terminal.
|
||||
// - if verbosity equals to 2, the command's stdout and stderr are buffered
|
||||
// and printed to the user's terminal after the command exits (this
|
||||
// prevents overlaping output of multiple commands)
|
||||
// - if verbosity equals to 1, the command's stderr is buffered as in 2, but
|
||||
// the stdout is silenced.
|
||||
const log = new stream.PassThrough();
|
||||
|
||||
const sendLog = (context: any) => {
|
||||
var title = util.format(
|
||||
"$ %s%s",
|
||||
colors.blue(command),
|
||||
this.options.verbosity < 2 ? colors.grey(" # Silenced\n") : "\n",
|
||||
);
|
||||
|
||||
context.write(title);
|
||||
};
|
||||
|
||||
switch (this.options.verbosity) {
|
||||
case 3:
|
||||
sendLog(process.stdout);
|
||||
subShell.stdout.pipe(process.stdout);
|
||||
subShell.stderr.pipe(process.stderr);
|
||||
break;
|
||||
case 2:
|
||||
subShell.stdout.pipe(log);
|
||||
// fallthrough
|
||||
case 1:
|
||||
subShell.stderr.pipe(log);
|
||||
sendLog(log);
|
||||
break;
|
||||
}
|
||||
|
||||
// setup the cleanup proceedure for when the command finishes.
|
||||
subShell.once("close", function handleSubShellClose() {
|
||||
// write the buffered output to stdout
|
||||
const content = log.read();
|
||||
|
||||
if (content !== null) {
|
||||
process.stdout.write(content);
|
||||
}
|
||||
});
|
||||
|
||||
subShell.once("exit", function handleSubShellExit(code) {
|
||||
// report an error if the command exited with a non-zero exit code.
|
||||
if (code !== 0) {
|
||||
const err: Error & { status?: number | null } = new Error(
|
||||
util.format("Command `%s` exited with code %s", command, code),
|
||||
);
|
||||
err.status = code;
|
||||
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
|
||||
// the file wrapping stdout is as the one wrapping stdin (same metadata)
|
||||
// with different contents.
|
||||
const stdout = stdin.clone({ path: "stdout" });
|
||||
stdout.contents = subShell.stdout.pipe(new stream.PassThrough());
|
||||
|
||||
// finally, write the input to the process's stdin.
|
||||
//stdin.pipe(subShell.stdin); //TODO:
|
||||
|
||||
return stdout;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.command;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Transform, type TransformCallback } from "stream";
|
||||
import { Command } from "./command";
|
||||
|
||||
export class RunTransform extends Transform {
|
||||
private command: Command;
|
||||
|
||||
constructor(template: string, options?: any) {
|
||||
super({ objectMode: true });
|
||||
this.command = new Command(template, options || {});
|
||||
}
|
||||
|
||||
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
|
||||
const stdout = this.command.exec(chunk, callback);
|
||||
this.push(stdout);
|
||||
}
|
||||
|
||||
exec(stdin?: any, callback?: any) {
|
||||
this.write(stdin, callback);
|
||||
this.end();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export default (template: string, options?: any) => new RunTransform(template, options);
|
||||
@@ -4,6 +4,8 @@
|
||||
-lib <%=item.name%>:<%=item.version.split('@').shift()%><% }); %>
|
||||
<% macros.forEach(function(item) { %>
|
||||
--macro "<%=item%>"<% }); %>
|
||||
<% flags.forEach(function(item) { %>
|
||||
-D <%=item%><% }); %>
|
||||
|
||||
-main <%=main%>
|
||||
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=meta.filename%><%=ext%>"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import assert from "node:assert/strict";
|
||||
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";
|
||||
|
||||
const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
|
||||
|
||||
const TEST_DATA = {
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-win.zip": "haxe.exe",
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-linux64.tar.gz": "haxe",
|
||||
"https://home.shmyga.ru/public/test.txt": "test.txt",
|
||||
};
|
||||
|
||||
for (const [url, file] of Object.entries(TEST_DATA)) {
|
||||
test(`Test download: ${url}`, async () => {
|
||||
const target = resolveTargetDir();
|
||||
await Downloader.download(url, target);
|
||||
assert(existsSync(join(target, file)));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["es2023"],
|
||||
"moduleDetection": "force",
|
||||
"module": "preserve",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"types": ["node"],
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"skipLibCheck": true,
|
||||
"noImplicitThis": false,
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { defineConfig } from "tsdown";
|
||||
|
||||
export default defineConfig({
|
||||
dts: {
|
||||
tsgo: true,
|
||||
},
|
||||
exports: true,
|
||||
sourcemap: true,
|
||||
});
|
||||
Reference in New Issue
Block a user