Compare commits

...
9 Commits
Author SHA1 Message Date
shmyga 1339ba0c98 ci(version): 1.2.0
test / test (push) Successful in 45s
release / release (push) Failing after 37s
2026-10-24 18:57:08 +03:00
shmyga c63417cefa ci(gitea): add gitea workflows
test / test (push) Successful in 47s
2026-10-24 18:56:28 +03:00
shmyga a25f223b61 refactor: fix typescript errors 2026-10-22 23:18:06 +03:00
shmyga 84d905dbb3 refactor: refork tail module 2026-10-22 12:04:40 +03:00
shmyga a421d56ec1 refactor: format log.ts 2026-10-20 00:54:16 +03:00
shmyga 079cf9d52d refactor: remove time-stamp dependency 2026-10-20 00:37:23 +03:00
shmyga 0edfb12473 test: add tests 2026-10-16 00:43:09 +03:00
shmyga c3c0b07d32 ci(version): 1.1.1
release / release (push) Failing after 37s
2026-10-14 19:35:14 +03:00
shmyga ec3d3b547c build(npm): add template dir to files section 2026-10-14 19:34:56 +03:00
30 changed files with 3217 additions and 4681 deletions
+3 -13
View File
@@ -4,27 +4,17 @@ on:
push: push:
tags: ["*"] tags: ["*"]
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
jobs: jobs:
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- run: echo '' > requirements.txt - run: echo '' > requirements.txt
- uses: https://git.shmyga.ru/InfernalGames/project-manager@master - uses: https://git.shmyga.ru/InfernalGames/project-manager@master
- run: pm setup:npm -vv
- run: pm build:npm -vv
- uses: actions/setup-node@v7
with: with:
node-version: "24.x" setup-nodejs: true
registry-url: "https://registry.npmjs.org" - run: pm build -vv
#- run: pm publish:npm -vv
#- run: npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN" #- run: npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
- run: npm publish --provenance --access public - run: npm publish --provenance --access public
env: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+16
View File
@@ -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
+2
View File
@@ -1,5 +1,7 @@
# Gulp HaXe Tool # Gulp HaXe Tool
[![test](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions/workflows/test.yaml/badge.svg?branch=master)](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions?workflow=test.yaml)
## Introducing ## Introducing
### Dignity ### Dignity
+2646 -4169
View File
File diff suppressed because it is too large Load Diff
+34 -20
View File
@@ -1,19 +1,21 @@
{ {
"name": "gulp-haxetool", "name": "gulp-haxetool",
"type": "module", "type": "module",
"version": "1.1.0", "version": "1.2.0",
"description": "HaXe Tool for Gulp", "description": "HaXe Tool for Gulp",
"exports": { "exports": {
".": "./dist/index.mjs", ".": "./dist/index.mjs",
"./package.json": "./package.json" "./package.json": "./package.json"
}, },
"files": [ "files": [
"template",
"dist" "dist"
], ],
"scripts": { "scripts": {
"build": "tsdown", "build": "tsdown",
"dev": "tsdown --watch", "dev": "tsdown --watch",
"typecheck": "tsc --noEmit" "lint": "tsc --noEmit",
"test": "node --test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -29,42 +31,54 @@
"dependencies": { "dependencies": {
"ansi-colors": "^1.1.0", "ansi-colors": "^1.1.0",
"async": "^2.6.0", "async": "^2.6.0",
"cli-progress": "^3.0.0", "cli-progress": "^3.12.0",
"dateformat": "^5.0.4", "dateformat": "^5.0.4",
"fancy-log": "^1.3.2", "fancy-log": "^1.3.2",
"fs-extra": "^5.0.0", "fs-extra": "^5.0.0",
"got": "^9.6.0", "got": "^16.1.0",
"gulp": "^4.0.0", "gulp": "^5.0.1",
"gulp-clean": "^0.4.0", "gulp-clean": "^0.4.0",
"gulp-connect": "^5.7.0",
"gulp-debian": "^0.1.9", "gulp-debian": "^0.1.9",
"gulp-gzip": "^1.4.2", "gulp-gzip": "^1.4.2",
"gulp-rename": "^1.2.2", "gulp-rename": "^2.1.0",
"gulp-spawn": "^0.4.0", "gulp-tar": "^5.0.0",
"gulp-tar": "^3.0.0", "gulp-zip": "^6.1.0",
"gulp-webserver": "^0.9.1",
"gulp-zip": "^5.0.0",
"lodash.defaults": "^4.2.0", "lodash.defaults": "^4.2.0",
"lodash.template": "^4.4.0", "lodash.template": "^4.4.0",
"plugin-error": "^1.0.1", "plugin-error": "^1.0.1",
"promise-streams": "^2.1.1", "promise-streams": "^2.1.1",
"tail": "^1.2.3", "tail": "^2.2.6",
"tar": "^4.4.10", "tar": "^7.5.22",
"through2": "^2.0.3", "through2": "^5.0.12",
"time-stamp": "^1.1.0",
"tmp-file": "^2.0.1", "tmp-file": "^2.0.1",
"unzip-stream": "^0.3.0", "unzip-stream": "^0.3.4",
"vinyl": "^2.1.0", "vinyl": "^3.0.1",
"vinyl-fs": "^3.0.2" "vinyl-fs": "^4.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/async": "^3.2.26",
"@types/cli-progress": "^3.11.6",
"@types/dateformat": "^5.0.3",
"@types/fs-extra": "^11.0.4", "@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-rename": "^2.0.7",
"@types/gulp-tar": "^4.0.1",
"@types/gulp-zip": "^4.0.4",
"@types/lodash.template": "^4.5.3", "@types/lodash.template": "^4.5.3",
"@types/node": "^26.1.1", "@types/node": "^26.6.5",
"@types/vinyl-fs": "^3.0.8", "@types/tail": "^2.2.3",
"eslint": "^10.12.0", "@types/tar": "^7.0.87",
"@types/through2": "^5.0.0",
"@types/unzip-stream": "^0.3.4",
"eslint": "^10.13.0",
"prettier": "^3.9.10", "prettier": "^3.9.10",
"tsdown": "0.22.14", "tsdown": "0.22.14",
"typescript": "^7.0.2" "typescript": "^7.0.2"
},
"inlinedDependencies": {
"lodash": "4.18.1"
} }
} }
+9
View File
@@ -0,0 +1,9 @@
declare module "gulp-clean" {
import type { WritableStream } from "stream";
export interface Options {
force?: boolean;
}
export default (options?: Options) => WritableStream;
}
+32
View File
@@ -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;
}
+14
View File
@@ -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;
}
+84
View File
@@ -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);
}
}
+19 -17
View File
@@ -1,5 +1,4 @@
import colors from "ansi-colors"; import colors from "ansi-colors";
import timestamp from "time-stamp";
const Level = { const Level = {
VERBOSE: -1, VERBOSE: -1,
@@ -11,24 +10,27 @@ const Level = {
const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO; const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
const formatTime = (date: Date): string => date.toTimeString().split(" ")[0];
export class Log { export class Log {
static level = level; static level = level;
static colorPatterns: [string, (m: string) => string][] = [
static colorize(pattern: string) {
for (const item of [
["_", colors.cyan], ["_", colors.cyan],
["\\*", colors.magenta], ["\\*", colors.magenta],
["!", colors.red], ["!", colors.red],
]) { ];
static colorize(pattern: string) {
for (const item of this.colorPatterns) {
const r = new RegExp(item[0] + "(.*?)" + item[0], "g"); const r = new RegExp(item[0] + "(.*?)" + item[0], "g");
pattern = pattern.replace(r, item[1]("$1")); pattern = pattern.replace(r, item[1]("$1"));
} }
return pattern; return pattern;
} }
static write(level: number, tag: string, pattern: string, ...args: any) { static write(level: number, tag: string, pattern: string, args: any[]) {
if (level >= this.level) { if (level >= this.level) {
const message = `[${colors.gray(timestamp("HH:mm:ss"))}] ${colors.green(tag)} ${this.colorize(pattern)}`; const message = `[${colors.gray(formatTime(new Date()))}] ${colors.green(tag)} ${this.colorize(pattern)}`;
console.log(message, ...args); console.log(message, ...args);
} }
} }
@@ -39,23 +41,23 @@ export class Log {
this.tag = tag; this.tag = tag;
} }
v(...args: any) { v(message: string, ...args: any) {
Log.write(-1, this.tag, ...args); Log.write(-1, this.tag, message, args);
} }
d(...args: any) { d(message: string, ...args: any) {
Log.write(0, this.tag, ...args); Log.write(0, this.tag, message, args);
} }
i(...args: any) { i(message: string, ...args: any) {
Log.write(1, this.tag, ...args); Log.write(1, this.tag, message, args);
} }
w(...args: any) { w(message: string, ...args: any) {
Log.write(2, this.tag, ...args); Log.write(2, this.tag, message, args);
} }
e(...args: any) { e(message: string, ...args: any) {
Log.write(3, this.tag, ...args); Log.write(3, this.tag, message, args);
} }
} }
+28 -45
View File
@@ -1,48 +1,25 @@
import { Transform, Writable } from "stream"; import { Transform, Writable, type TransformCallback, type WritableOptions } from "stream";
import { StringDecoder } from "string_decoder"; import { StringDecoder } from "string_decoder";
import { Tail } from "tail";
import through from "through2";
import Vinyl from "vinyl";
export class TailVinyl extends Vinyl { export type TailHandler = (line: string) => void;
constructor(params: any) {
params.contents = new Transform();
super(params);
if (params.path) {
this.tail = new Tail(params.path);
(this.tail.on("line", (line) => {
if (params.handler) {
line = params.handler(line);
}
if (line) {
this.contents.write(line + "\n");
}
}),
this.tail.on("error", (error: any) => this.contents.write("error: " + error)));
}
}
dispose() { export class HandlerWriter extends Writable {
if (this.tail) { private handler: any;
this.tail.unwatch(); private decoder: StringDecoder;
} private data: string;
this.contents.destroy();
}
}
export class StringWritable extends Writable { constructor(handler: TailHandler, options?: WritableOptions) {
constructor(handler: any, options?: any) { if (!options) options = {};
options.objectMode = true;
super(options); super(options);
this.handler = handler; this.handler = handler;
const state = this._writableState; this.decoder = new StringDecoder(options?.defaultEncoding);
this._decoder = new StringDecoder(state.defaultEncoding);
this.data = ""; this.data = "";
} }
_write(chunk, encoding, callback) { _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
if (encoding === "buffer") { chunk = this.decoder.write(chunk);
chunk = this._decoder.write(chunk); for (const line of chunk.split("\n")) {
for (const line of chunk.split("\n"))
if (line.length) { if (line.length) {
this.handler(line); this.handler(line);
} }
@@ -51,18 +28,24 @@ export class StringWritable extends Writable {
callback(); callback();
} }
_final(callback) { _final(callback: (error?: Error | null) => void): void {
this.data += this._decoder.end(); this.data += this.decoder.end();
callback(); callback();
} }
} }
export const tail = (handler: any) => { export class TailTransform extends Transform {
return through.obj(function (file: any, enc: string, callback: any) { constructor(private handler: TailHandler) {
if (file.contents && file.contents.pipe) { super({ objectMode: true });
file.contents.pipe(new StringWritable(handler));
} }
this.push(file);
_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(); callback();
}); }
}; }
export const tail = (handler: TailHandler) => new TailTransform(handler);
+65
View File
@@ -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 });
-9
View File
@@ -75,17 +75,8 @@ export class Config {
this.flags = []; this.flags = [];
this.icon = null; this.icon = null;
this.meta = { this.meta = {
title: null,
filename: null,
icon: null,
version: null,
pack: null,
author: null,
company: null,
width: 800, width: 800,
height: 600, height: 600,
mobileWidth: null,
mobileHeight: null,
fps: 60, fps: 60,
}; };
this.key = null; this.key = null;
+1 -82
View File
@@ -1,89 +1,8 @@
import progress from "cli-progress";
import fs from "fs";
import fse from "fs-extra";
import got from "got";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import ps from "promise-streams"; import { Downloader } from "../common/download";
import tar from "tar";
import unzip from "unzip-stream";
import { Log } from "../common/log"; import { Log } from "../common/log";
export class Downloader {
static bar: progress.MultiBar;
static createProgressBar() {
if (Downloader.bar == null) {
Downloader.bar = new progress.MultiBar(
{
clearOnComplete: true,
},
progress.Presets.shades_grey,
);
}
return Downloader.bar.create();
}
static releaseProgressBar(bar: progress.MultiBar) {
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: string, dest: string, strip = 1, executable = false) {
fse.ensureDirSync(dest);
const bar = Downloader.createProgressBar();
let 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: strip }));
} else {
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split("/").pop()!)));
}
return ps.wait(stream);
}
}
export class Sdk { export class Sdk {
static _dir: string; static _dir: string;
+1
View File
@@ -1,3 +1,4 @@
// @ts-nocheck
import fs from "fs"; import fs from "fs";
import gulp from "gulp"; import gulp from "gulp";
import through from "through2"; import through from "through2";
+4 -3
View File
@@ -2,11 +2,12 @@ import fs from "fs";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import through from "through2"; import through from "through2";
import { Downloader } from "../common/download";
import { Env } from "../common/env"; import { Env } from "../common/env";
import exec from "../common/exec"; import exec from "../common/exec";
import { System } from "../common/system"; import { System } from "../common/system";
import { StringWritable } from "../common/tail"; import { HandlerWriter } from "../common/tail";
import { Downloader, Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import { Command } from "../run/command"; import { Command } from "../run/command";
export class Android extends Sdk { export class Android extends Sdk {
@@ -222,7 +223,7 @@ export class Android extends Sdk {
const command = new Command(cmd).exec(); const command = new Command(cmd).exec();
this.push(command); this.push(command);
command.contents.pipe( command.contents.pipe(
new StringWritable((line) => { new HandlerWriter((line: string) => {
if (line.includes("SDL") && (line.includes("onDestroy()") || line.includes("onStop()"))) { if (line.includes("SDL") && (line.includes("onDestroy()") || line.includes("onStop()"))) {
callback(); callback();
throw "Exit"; // ToDo: throw "Exit"; // ToDo:
+5 -18
View File
@@ -2,10 +2,9 @@ import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import through from "through2";
import { Env } from "../common/env"; import { Env } from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { TailVinyl } from "../common/tail"; import { watch } from "../common/watch";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import run from "../run"; import run from "../run";
@@ -60,7 +59,6 @@ export class FlashPlayer extends Sdk {
get flashPlayerBin(): string { get flashPlayerBin(): string {
if (System.isWindows) { if (System.isWindows) {
const v = this.version.split(".");
const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`; const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
return path.join(this.path, playerName); return path.join(this.path, playerName);
} else if (System.isLinux) { } else if (System.isLinux) {
@@ -74,7 +72,7 @@ export class FlashPlayer extends Sdk {
static get flashPlayerDir(): string { static get flashPlayerDir(): string {
if (os.type() === "Windows_NT") { if (os.type() === "Windows_NT") {
return path.join(process.env.APPDATA, "Macromedia", "Flash Player"); return path.join(process.env.APPDATA!, "Macromedia", "Flash Player");
} else if (os.type() === "Linux") { } else if (os.type() === "Linux") {
return path.join(os.homedir(), ".macromedia", "Flash_Player"); return path.join(os.homedir(), ".macromedia", "Flash_Player");
} else { } else {
@@ -90,7 +88,7 @@ export class FlashPlayer extends Sdk {
const filename = path.join(os.homedir(), "mm.cfg"); const filename = path.join(os.homedir(), "mm.cfg");
const value = "TraceOutputFileEnable=1"; const value = "TraceOutputFileEnable=1";
if (fs.existsSync(filename)) { if (fs.existsSync(filename)) {
const data = fs.readFileSync(filename); const data = fs.readFileSync(filename, "utf8");
if (data.indexOf(value) === -1) { if (data.indexOf(value) === -1) {
fs.appendFileSync(filename, `${value}\n`); fs.appendFileSync(filename, `${value}\n`);
} }
@@ -104,7 +102,7 @@ export class FlashPlayer extends Sdk {
static trust(value: string) { static trust(value: string) {
const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg"); const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg");
if (fs.existsSync(filename)) { if (fs.existsSync(filename)) {
const data = fs.readFileSync(filename); const data = fs.readFileSync(filename, "utf8");
if (data.indexOf(value) === -1) { if (data.indexOf(value) === -1) {
fs.appendFileSync(filename, `${value}\n`); fs.appendFileSync(filename, `${value}\n`);
} }
@@ -120,17 +118,6 @@ export class FlashPlayer extends Sdk {
this.log.i("_run_ *%s*", filename); this.log.i("_run_ *%s*", filename);
FlashPlayer.trust(filename); FlashPlayer.trust(filename);
FlashPlayer.enableLog(); FlashPlayer.enableLog();
return run(`${this.flashPlayerBin} ${filename}`, params) return run(`${this.flashPlayerBin} ${filename}`, params).exec().pipe(watch(FlashPlayer.log));
.exec()
.pipe(
through.obj(function (file: any, enc: string, callback: any) {
const log = new TailVinyl({
path: FlashPlayer.log,
});
this.on("end", () => log.dispose());
this.push(log);
callback();
}),
);
} }
} }
+13 -6
View File
@@ -77,7 +77,10 @@ export class Haxe extends Sdk {
prepare() { prepare() {
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => { return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
fs.copyFileSync(path.resolve(import.meta.dirname, "..", "template/haxe/activate"), path.resolve(this.path, "activate")); fs.copyFileSync(
path.resolve(import.meta.dirname, "..", "template/haxe/activate"),
path.resolve(this.path, "activate"),
);
}); });
} }
@@ -112,7 +115,9 @@ export class Haxe extends Sdk {
const buildDir = this.resolveBuildDir(config); const buildDir = this.resolveBuildDir(config);
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
const projectTemplate = template(fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.xml"))); const projectTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.xml"), "utf8"),
);
const project = projectTemplate({ ...config, buildDir: buildDir }); const project = projectTemplate({ ...config, buildDir: buildDir });
fs.writeFileSync(path.resolve(buildDir, "project.xml"), project); fs.writeFileSync(path.resolve(buildDir, "project.xml"), project);
@@ -128,7 +133,7 @@ export class Haxe extends Sdk {
flash: "*.swf", flash: "*.swf",
}[platform] || "**/*"; }[platform] || "**/*";
return this.haxelib(args).then(() => { return this.haxelib(args).then(() => {
let r = vfs.src(`${target}/${result}`); let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "android") { if (platform === "android") {
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`)); r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
} }
@@ -142,7 +147,9 @@ export class Haxe extends Sdk {
const buildDir = this.resolveBuildDir(config); const buildDir = this.resolveBuildDir(config);
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
const projectTemplate = template(fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.hxml"))); const projectTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.hxml"), "utf8"),
);
const ext = const ext =
{ {
@@ -175,9 +182,9 @@ export class Haxe extends Sdk {
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`, cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
}[platform] || "**/*"; }[platform] || "**/*";
return this.haxe(args).then(() => { return this.haxe(args).then(() => {
let r = vfs.src(`${target}/${result}`); let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "cpp") { if (platform === "cpp") {
r = r.pipe(rename(config.meta.filename)); r = r.pipe(rename(config.meta.filename!));
} }
return r; return r;
}); });
+3 -1
View File
@@ -43,7 +43,9 @@ export class InnoSetup extends Sdk {
pack(config: Config, source: string, output: string) { pack(config: Config, source: string, output: string) {
const buildDir = path.join(os.tmpdir(), "build", config.name, "innosetup"); 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 appTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/windows/app.iss"), "utf8"),
);
const app = appTemplate({ ...config, buildDir: buildDir, output: output }); const app = appTemplate({ ...config, buildDir: buildDir, output: output });
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
+2 -11
View File
@@ -1,9 +1,8 @@
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import through from "through2";
import { Env } from "../common/env"; import { Env } from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { TailVinyl } from "../common/tail"; import { watch } from "../common/watch";
import run from "../run"; import run from "../run";
import { FlashPlayer } from "./flashplayer"; import { FlashPlayer } from "./flashplayer";
@@ -55,18 +54,10 @@ export class RufflePlayer extends FlashPlayer {
return run(`${this.flashPlayerBin} ${filename}`, params) return run(`${this.flashPlayerBin} ${filename}`, params)
.exec() .exec()
.pipe( .pipe(
through.obj(function (file: any, enc: string, callback: any) { watch(RufflePlayer.log, (line: string) => {
const log = new TailVinyl({
path: RufflePlayer.log,
handler: (line: string) => {
if (line.includes("avm_trace")) { if (line.includes("avm_trace")) {
return line.split("avm_trace: ").pop(); return line.split("avm_trace: ").pop();
} }
},
});
this.on("end", () => log.dispose());
this.push(log);
callback();
}), }),
); );
} }
+1
View File
@@ -1,5 +1,6 @@
export * from "./common/system"; export * from "./common/system";
export * from "./core/config"; export * from "./core/config";
export * from "./common/download";
export * from "./core/sdk"; export * from "./core/sdk";
export * from "./core/type"; export * from "./core/type";
export * from "./impl/android"; export * from "./impl/android";
+1 -1
View File
@@ -15,7 +15,7 @@ export class FlashHTMLPacker extends Packer {
call() { call() {
const target = this.targetPath; const target = this.targetPath;
const indexTemplate = template( const indexTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html")), fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html"), "utf8"),
); );
const index = indexTemplate(this.config); const index = indexTemplate(this.config);
fs.writeFileSync(path.resolve(target, "index.html"), index); fs.writeFileSync(path.resolve(target, "index.html"), index);
+4 -4
View File
@@ -2,7 +2,7 @@ import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import gulp from "gulp"; import gulp from "gulp";
import deb from "gulp-debian"; import deb from "gulp-debian";
import template from "lodash.template"; import { template } from "lodash";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Config } from "../../../../core/config"; import { Config } from "../../../../core/config";
@@ -21,7 +21,7 @@ export class LinuxDEBPacker extends Packer {
const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian"); const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian");
const iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`; const iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`;
const desktopTemplate = template( const desktopTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop")), fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop"), "utf8"),
); );
const desktop = desktopTemplate(Object.assign({ iconfile: iconfile }, this.config)); const desktop = desktopTemplate(Object.assign({ iconfile: iconfile }, this.config));
fse.ensureDirSync(`${buildDir}/usr/share/applications`); fse.ensureDirSync(`${buildDir}/usr/share/applications`);
@@ -30,8 +30,8 @@ export class LinuxDEBPacker extends Packer {
fse.copySync(this.config.meta.icon!, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`); fse.copySync(this.config.meta.icon!, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
return gulp.src(`${buildDir}/*`).pipe( return gulp.src(`${buildDir}/*`).pipe(
deb({ deb({
package: this.config.meta.filename, package: this.config.meta.filename!,
version: this.config.meta.version, version: this.config.meta.version!,
section: "base", section: "base",
priority: "optional", priority: "optional",
architecture: "all", architecture: "all",
+4 -8
View File
@@ -1,5 +1,4 @@
import gulp from "gulp"; import connect from "gulp-connect";
import webserver from "gulp-webserver";
import { Config } from "../../../core/config"; import { Config } from "../../../core/config";
import { Platform } from "../../../core/type"; import { Platform } from "../../../core/type";
import { Runner } from "../../core/runner"; import { Runner } from "../../core/runner";
@@ -10,15 +9,12 @@ export class Html5Runner extends Runner {
} }
call() { call() {
return gulp.src(this.targetPath).pipe( return connect.server({
webserver({ root: this.targetPath,
// TODO: config?
host: "0.0.0.0", host: "0.0.0.0",
port: 3000, port: 3000,
open: true,
fallback: "index.html", fallback: "index.html",
}), });
);
} }
} }
+4 -5
View File
@@ -1,4 +1,5 @@
import gulp from "gulp"; import gulp from "gulp";
import type { Task, TaskFunction } from "undertaker";
import { Config } from "../core/config"; import { Config } from "../core/config";
import { BuildSystem, Platform } from "../core/type"; import { BuildSystem, Platform } from "../core/type";
import { Builder } from "./core/builder"; import { Builder } from "./core/builder";
@@ -7,8 +8,6 @@ import { Runner } from "./core/runner";
import { RuffleRunner } from "./impl/runner/ruffle"; import { RuffleRunner } from "./impl/runner/ruffle";
export * from "./core"; export * from "./core";
export type Task = any; // TODO: gulp task type
export class Project { export class Project {
// TODO: compatibility // TODO: compatibility
static Config = Config; static Config = Config;
@@ -56,8 +55,8 @@ export class Project {
return [packer.prepare.bind(packer), packer.call.bind(packer)]; return [packer.prepare.bind(packer), packer.call.bind(packer)];
} }
compile(external_gulp?: any): Record<string, Task> { compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
const result: Record<string, Task> = {}; const result: Record<string, TaskFunction> = {};
const _gulp = external_gulp || gulp; const _gulp = external_gulp || gulp;
for (const platform of this.platforms) { for (const platform of this.platforms) {
result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform)); result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
@@ -74,7 +73,7 @@ export class Project {
return result; return result;
} }
register(external_gulp?: any) { register(external_gulp?: gulp.Gulp) {
const _gulp = external_gulp || gulp; const _gulp = external_gulp || gulp;
for (const [k, v] of Object.entries(this.compile(_gulp))) { for (const [k, v] of Object.entries(this.compile(_gulp))) {
_gulp.task(k, v); _gulp.task(k, v);
+17 -16
View File
@@ -3,6 +3,7 @@ import gulp from "gulp";
import gulpClean from "gulp-clean"; import gulpClean from "gulp-clean";
import template from "lodash.template"; import template from "lodash.template";
import os from "os"; import os from "os";
import type { Task } from "undertaker";
import { Builder, Project } from "."; import { Builder, Project } from ".";
import { System } from "../common/system"; import { System } from "../common/system";
import { Config, type ConfigParams } from "../core/config"; import { Config, type ConfigParams } from "../core/config";
@@ -65,7 +66,7 @@ export class Preset {
return projects; return projects;
} }
register(external_gulp?: any, additional_tasks?: string[]) { register(external_gulp?: gulp.Gulp, additional_tasks?: string[]) {
const _gulp = external_gulp || gulp; const _gulp = external_gulp || gulp;
const resolvePath = (path: string) => path.replace("$HOME", os.homedir()); const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
@@ -114,15 +115,15 @@ export class Preset {
project.register(_gulp); project.register(_gulp);
} }
const defaultSeries = [_gulp.task("clean"), _gulp.task("setup")]; const defaultSeries: Task[] = [_gulp.task("clean")!, _gulp.task("setup")!];
if (protohx) { if (protohx) {
defaultSeries.push("protohx:generate"); defaultSeries.push(_gulp.task("protohx:generate")!);
} }
if (additional_tasks) { if (additional_tasks) {
for (const task of additional_tasks) { for (const task of additional_tasks) {
defaultSeries.push(_gulp.task(task)); defaultSeries.push(_gulp.task(task)!);
} }
} }
@@ -130,39 +131,39 @@ export class Preset {
for (const platform of project.platforms) { for (const platform of project.platforms) {
switch (platform) { switch (platform) {
case Platform.FLASH: case Platform.FLASH:
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:html`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:html`)!);
break; break;
case Platform.HTML5: case Platform.HTML5:
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
break; break;
case Platform.LINUX: case Platform.LINUX:
if (System.isLinux) { if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); 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}:archive`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:deb`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:deb`)!);
} }
break; break;
case Platform.CPP: case Platform.CPP:
if (System.isLinux) { if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
} }
break; break;
case Platform.NEKO: case Platform.NEKO:
if (System.isLinux) { if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
} }
break; break;
case Platform.ANDROID: case Platform.ANDROID:
if (System.isLinux) { if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
} }
break; break;
case Platform.WINDOWS: case Platform.WINDOWS:
if (System.isWindows) { if (System.isWindows) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)); 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}:archive`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:installer`)); defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:installer`)!);
} }
break; break;
} }
+53 -77
View File
@@ -1,83 +1,61 @@
var cp = require('child_process'); import colors from "ansi-colors";
var path = require('path'); import cp from "child_process";
var stream = require('stream'); import { defaults, template } from "lodash";
var util = require('util'); import path from "path";
var defaults = require('lodash.defaults'); import stream from "stream";
var applyTemplate = require('lodash.template'); import util from "util";
var Vinyl = require('vinyl'); import Vinyl from "vinyl";
var colors = require('ansi-colors');
/** export class Command {
* Creates a new `gulp-run` command. private command: string;
* private isWindows: boolean;
* @param {string} command private options: any;
* @param {object} options
*/
export function Command(command, options?) {
var previousPath;
constructor(command: string, options?: any) {
this.command = command; this.command = command;
this.isWindows = process.platform.lastIndexOf("win") === 0;
// 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 || {}, { this.options = defaults(options || {}, {
cwd: process.cwd(), cwd: process.cwd(),
env: process.env, env: process.env,
verbosity: (options && options.silent) ? 1 : 2, verbosity: options && options.silent ? 1 : 2,
usePowerShell: false usePowerShell: false,
}); });
// include node_modules/.bin on the path when we execute the command. let previousPath;
previousPath = this.options.env.PATH; previousPath = this.options.env.PATH;
this.options.env.PATH = path.join(this.options.cwd, 'node_modules', '.bin'); this.options.env.PATH = path.join(this.options.cwd, "node_modules", ".bin");
this.options.env.PATH += path.delimiter; this.options.env.PATH += path.delimiter;
this.options.env.PATH += previousPath; this.options.env.PATH += previousPath;
} }
/** exec(stdin?: any, callback?: any) {
* Execute the command, invoking the callback when the command exits. let fileName;
* Returns a Vinyl file wrapping the command's stdout. let directory;
* let subShell;
* @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. // parse the arguments, both are optional.
// after parsing, stdin is a vinyl file to use as standard input to // after parsing, stdin is a vinyl file to use as standard input to
// the command (possibly empty), and callback is a function. // the command (possibly empty), and callback is a function.
if (typeof stdin === 'function') { if (typeof stdin === "function") {
callback = stdin; callback = stdin;
stdin = undefined; stdin = undefined;
} else if (typeof callback !== 'function') { } else if (typeof callback !== "function") {
callback = function noop() {}; callback = function noop() {};
} }
if (!(stdin instanceof Vinyl)) { if (!(stdin instanceof Vinyl)) {
fileName = this.command.split(' ')[0]; fileName = this.command.split(" ")[0];
directory = path.join(this.options.cwd, fileName); directory = path.join(this.options.cwd, fileName);
if (typeof stdin === 'string') { if (typeof stdin === "string") {
stdin = new Vinyl({ stdin = new Vinyl({
path: directory, path: directory,
contents: new Buffer(stdin) contents: new Buffer(stdin),
}); });
} else if (stdin instanceof Buffer || stdin instanceof stream.Readable) { } else if (stdin instanceof Buffer || stdin instanceof stream.Readable) {
stdin = new Vinyl({ stdin = new Vinyl({
path: directory, path: directory,
contents: stdin contents: stdin,
}); });
} else { } else {
stdin = new Vinyl(stdin); stdin = new Vinyl(stdin);
@@ -91,27 +69,27 @@ Command.prototype.exec = function exec(stdin, callback) {
// execute the command. // execute the command.
// we spawn the command in a subshell, so things like i/o redirection // 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. // just work. e.g. `echo hello world >> ./hello.txt` works as expected.
command = applyTemplate(this.command)({ const command = template(this.command)({
file: stdin file: stdin,
}); });
if (this.isWindows && this.options.usePowerShell) { if (this.isWindows && this.options.usePowerShell) {
// windows powershell // windows powershell
subShell = cp.spawn('powershell.exe', ['-NonInteractive', '-NoLogo', '-Command', command], { subShell = cp.spawn("powershell.exe", ["-NonInteractive", "-NoLogo", "-Command", command], {
env: this.options.env, env: this.options.env,
cwd: this.options.cwd cwd: this.options.cwd,
}); });
} else if (this.isWindows) { } else if (this.isWindows) {
// windows cmd.exe // windows cmd.exe
subShell = cp.spawn('cmd.exe', ['/c', command], { subShell = cp.spawn("cmd.exe", ["/c", command], {
env: this.options.env, env: this.options.env,
cwd: this.options.cwd cwd: this.options.cwd,
}); });
} else { } else {
// POSIX shell // POSIX shell
subShell = cp.spawn('sh', ['-c', command], { subShell = cp.spawn("sh", ["-c", command], {
env: this.options.env, env: this.options.env,
cwd: this.options.cwd cwd: this.options.cwd,
}); });
} }
@@ -123,17 +101,17 @@ Command.prototype.exec = function exec(stdin, callback) {
// prevents overlaping output of multiple commands) // prevents overlaping output of multiple commands)
// - if verbosity equals to 1, the command's stderr is buffered as in 2, but // - if verbosity equals to 1, the command's stderr is buffered as in 2, but
// the stdout is silenced. // the stdout is silenced.
log = new stream.PassThrough(); const log = new stream.PassThrough();
function sendLog(context) { const sendLog = (context: any) => {
var title = util.format( var title = util.format(
'$ %s%s', "$ %s%s",
colors.blue(command), colors.blue(command),
(self.options.verbosity < 2) ? colors.grey(' # Silenced\n') : '\n' this.options.verbosity < 2 ? colors.grey(" # Silenced\n") : "\n",
); );
context.write(title); context.write(title);
} };
switch (this.options.verbosity) { switch (this.options.verbosity) {
case 3: case 3:
@@ -151,19 +129,21 @@ Command.prototype.exec = function exec(stdin, callback) {
} }
// setup the cleanup proceedure for when the command finishes. // setup the cleanup proceedure for when the command finishes.
subShell.once('close', function handleSubShellClose() { subShell.once("close", function handleSubShellClose() {
// write the buffered output to stdout // write the buffered output to stdout
var content = log.read(); const content = log.read();
if (content !== null) { if (content !== null) {
process.stdout.write(content); process.stdout.write(content);
} }
}); });
subShell.once('exit', function handleSubShellExit(code) { subShell.once("exit", function handleSubShellExit(code) {
// report an error if the command exited with a non-zero exit code. // report an error if the command exited with a non-zero exit code.
if (code !== 0) { if (code !== 0) {
err = new Error(util.format('Command `%s` exited with code %s', command, code)); const err: Error & { status?: number | null } = new Error(
util.format("Command `%s` exited with code %s", command, code),
);
err.status = code; err.status = code;
return callback(err); return callback(err);
@@ -174,20 +154,16 @@ Command.prototype.exec = function exec(stdin, callback) {
// the file wrapping stdout is as the one wrapping stdin (same metadata) // the file wrapping stdout is as the one wrapping stdin (same metadata)
// with different contents. // with different contents.
stdout = stdin.clone(); const stdout = stdin.clone({ path: "stdout" });
stdout.contents = subShell.stdout.pipe(new stream.PassThrough()); stdout.contents = subShell.stdout.pipe(new stream.PassThrough());
// finally, write the input to the process's stdin. // finally, write the input to the process's stdin.
//stdin.pipe(subShell.stdin); //ToDo: //stdin.pipe(subShell.stdin); //TODO:
return stdout; return stdout;
}; }
/** toString() {
* Returns the command template.
*
* @return {string}
*/
Command.prototype.toString = function toString() {
return this.command; return this.command;
}; }
}
+14 -61
View File
@@ -1,71 +1,24 @@
/** import { Transform, type TransformCallback } from "stream";
* Pipe shell commands in gulp.
* @module gulp-run
*/
import { Command } from "./command"; import { Command } from "./command";
var inherit = require("util").inherits; export class RunTransform extends Transform {
var Transform = require("stream").Transform; private command: Command;
/** constructor(template: string, options?: any) {
* Creates a GulpRunner. super({ objectMode: true });
* this.command = new Command(template, options || {});
* 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(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
Transform.call(this, { objectMode: true }); const stdout = this.command.exec(chunk, callback);
} this.push(stdout);
}
/** exec(stdin?: any, callback?: any) {
* @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.write(stdin, callback);
this.end(); this.end();
return this; return this;
}; }
}
/** export default (template: string, options?: any) => new RunTransform(template, options);
* @static
* @type {Command}
*/
GulpRunner.Command = Command;
export default GulpRunner;
+22
View File
@@ -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)));
});
}
+2 -1
View File
@@ -14,7 +14,8 @@
"esModuleInterop": true, "esModuleInterop": true,
"isolatedModules": true, "isolatedModules": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true,
"skipLibCheck": true "skipLibCheck": true,
"noImplicitThis": false,
}, },
"include": ["src"] "include": ["src"]
} }