Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c522783b75 | ||
|
|
ad6bc17b1b | ||
|
|
a25f223b61 | ||
|
|
84d905dbb3 | ||
|
|
a421d56ec1 | ||
|
|
079cf9d52d | ||
|
|
0edfb12473 | ||
|
|
c3c0b07d32 | ||
|
|
ec3d3b547c |
@@ -4,27 +4,15 @@ on:
|
||||
push:
|
||||
tags: ["*"]
|
||||
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- run: echo '' > requirements.txt
|
||||
- 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:
|
||||
node-version: "24.x"
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
#- run: pm publish:npm -vv
|
||||
#- run: npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
|
||||
- run: npm publish --provenance --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
setup-nodejs: true
|
||||
- run: pm build -vv
|
||||
- run: npm config set //registry.npmjs.org/:_authToken "${{ secrets.NPM_TOKEN }}"
|
||||
- run: npm publish
|
||||
|
||||
@@ -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,5 +1,7 @@
|
||||
# Gulp HaXe Tool
|
||||
|
||||
[](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions?workflow=test.yaml)
|
||||
|
||||
## Introducing
|
||||
|
||||
### Dignity
|
||||
|
||||
Generated
+2646
-4169
File diff suppressed because it is too large
Load Diff
+34
-20
@@ -1,19 +1,21 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"type": "module",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "HaXe Tool for Gulp",
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"template",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsdown",
|
||||
"dev": "tsdown --watch",
|
||||
"typecheck": "tsc --noEmit"
|
||||
"lint": "tsc --noEmit",
|
||||
"test": "node --test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -29,42 +31,54 @@
|
||||
"dependencies": {
|
||||
"ansi-colors": "^1.1.0",
|
||||
"async": "^2.6.0",
|
||||
"cli-progress": "^3.0.0",
|
||||
"cli-progress": "^3.12.0",
|
||||
"dateformat": "^5.0.4",
|
||||
"fancy-log": "^1.3.2",
|
||||
"fs-extra": "^5.0.0",
|
||||
"got": "^9.6.0",
|
||||
"gulp": "^4.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": "^1.2.2",
|
||||
"gulp-spawn": "^0.4.0",
|
||||
"gulp-tar": "^3.0.0",
|
||||
"gulp-webserver": "^0.9.1",
|
||||
"gulp-zip": "^5.0.0",
|
||||
"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": "^1.2.3",
|
||||
"tar": "^4.4.10",
|
||||
"through2": "^2.0.3",
|
||||
"time-stamp": "^1.1.0",
|
||||
"tail": "^2.2.6",
|
||||
"tar": "^7.5.22",
|
||||
"through2": "^5.0.12",
|
||||
"tmp-file": "^2.0.1",
|
||||
"unzip-stream": "^0.3.0",
|
||||
"vinyl": "^2.1.0",
|
||||
"vinyl-fs": "^3.0.2"
|
||||
"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.1.1",
|
||||
"@types/vinyl-fs": "^3.0.8",
|
||||
"eslint": "^10.12.0",
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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
@@ -1,5 +1,4 @@
|
||||
import colors from "ansi-colors";
|
||||
import timestamp from "time-stamp";
|
||||
|
||||
const Level = {
|
||||
VERBOSE: -1,
|
||||
@@ -11,24 +10,27 @@ const Level = {
|
||||
|
||||
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 colorize(pattern: string) {
|
||||
for (const item of [
|
||||
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) {
|
||||
static write(level: number, tag: string, pattern: string, args: any[]) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -39,23 +41,23 @@ export class Log {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
v(...args: any) {
|
||||
Log.write(-1, this.tag, ...args);
|
||||
v(message: string, ...args: any) {
|
||||
Log.write(-1, this.tag, message, args);
|
||||
}
|
||||
|
||||
d(...args: any) {
|
||||
Log.write(0, this.tag, ...args);
|
||||
d(message: string, ...args: any) {
|
||||
Log.write(0, this.tag, message, args);
|
||||
}
|
||||
|
||||
i(...args: any) {
|
||||
Log.write(1, this.tag, ...args);
|
||||
i(message: string, ...args: any) {
|
||||
Log.write(1, this.tag, message, args);
|
||||
}
|
||||
|
||||
w(...args: any) {
|
||||
Log.write(2, this.tag, ...args);
|
||||
w(message: string, ...args: any) {
|
||||
Log.write(2, this.tag, message, args);
|
||||
}
|
||||
|
||||
e(...args: any) {
|
||||
Log.write(3, this.tag, ...args);
|
||||
e(message: string, ...args: any) {
|
||||
Log.write(3, this.tag, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-45
@@ -1,48 +1,25 @@
|
||||
import { Transform, Writable } from "stream";
|
||||
import { Transform, Writable, type TransformCallback, type WritableOptions } from "stream";
|
||||
import { StringDecoder } from "string_decoder";
|
||||
import { Tail } from "tail";
|
||||
import through from "through2";
|
||||
import Vinyl from "vinyl";
|
||||
|
||||
export class TailVinyl extends Vinyl {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
export type TailHandler = (line: string) => void;
|
||||
|
||||
dispose() {
|
||||
if (this.tail) {
|
||||
this.tail.unwatch();
|
||||
}
|
||||
this.contents.destroy();
|
||||
}
|
||||
}
|
||||
export class HandlerWriter extends Writable {
|
||||
private handler: any;
|
||||
private decoder: StringDecoder;
|
||||
private data: string;
|
||||
|
||||
export class StringWritable extends Writable {
|
||||
constructor(handler: any, options?: any) {
|
||||
constructor(handler: TailHandler, options?: WritableOptions) {
|
||||
if (!options) options = {};
|
||||
options.objectMode = true;
|
||||
super(options);
|
||||
this.handler = handler;
|
||||
const state = this._writableState;
|
||||
this._decoder = new StringDecoder(state.defaultEncoding);
|
||||
this.decoder = new StringDecoder(options?.defaultEncoding);
|
||||
this.data = "";
|
||||
}
|
||||
|
||||
_write(chunk, encoding, callback) {
|
||||
if (encoding === "buffer") {
|
||||
chunk = this._decoder.write(chunk);
|
||||
for (const line of chunk.split("\n"))
|
||||
_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);
|
||||
}
|
||||
@@ -51,18 +28,24 @@ export class StringWritable extends Writable {
|
||||
callback();
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
this.data += this._decoder.end();
|
||||
_final(callback: (error?: Error | null) => void): void {
|
||||
this.data += this.decoder.end();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export const tail = (handler: any) => {
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
if (file.contents && file.contents.pipe) {
|
||||
file.contents.pipe(new StringWritable(handler));
|
||||
export class TailTransform extends Transform {
|
||||
constructor(private handler: TailHandler) {
|
||||
super({ objectMode: true });
|
||||
}
|
||||
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();
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const tail = (handler: TailHandler) => new TailTransform(handler);
|
||||
|
||||
@@ -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 });
|
||||
@@ -75,17 +75,8 @@ export class Config {
|
||||
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;
|
||||
|
||||
+1
-82
@@ -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 path from "path";
|
||||
import ps from "promise-streams";
|
||||
import tar from "tar";
|
||||
import unzip from "unzip-stream";
|
||||
import { Downloader } from "../common/download";
|
||||
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 {
|
||||
static _dir: string;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import through from "through2";
|
||||
|
||||
+4
-3
@@ -2,11 +2,12 @@ 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 { StringWritable } from "../common/tail";
|
||||
import { Downloader, Sdk } from "../core/sdk";
|
||||
import { HandlerWriter } from "../common/tail";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Command } from "../run/command";
|
||||
|
||||
export class Android extends Sdk {
|
||||
@@ -222,7 +223,7 @@ export class Android extends Sdk {
|
||||
const command = new Command(cmd).exec();
|
||||
this.push(command);
|
||||
command.contents.pipe(
|
||||
new StringWritable((line) => {
|
||||
new HandlerWriter((line: string) => {
|
||||
if (line.includes("SDL") && (line.includes("onDestroy()") || line.includes("onStop()"))) {
|
||||
callback();
|
||||
throw "Exit"; // ToDo:
|
||||
|
||||
+5
-18
@@ -2,10 +2,9 @@ import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { TailVinyl } from "../common/tail";
|
||||
import { watch } from "../common/watch";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run";
|
||||
|
||||
@@ -60,7 +59,6 @@ export class FlashPlayer extends Sdk {
|
||||
|
||||
get flashPlayerBin(): string {
|
||||
if (System.isWindows) {
|
||||
const v = this.version.split(".");
|
||||
const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
||||
return path.join(this.path, playerName);
|
||||
} else if (System.isLinux) {
|
||||
@@ -74,7 +72,7 @@ export class FlashPlayer extends Sdk {
|
||||
|
||||
static get flashPlayerDir(): string {
|
||||
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") {
|
||||
return path.join(os.homedir(), ".macromedia", "Flash_Player");
|
||||
} else {
|
||||
@@ -90,7 +88,7 @@ export class FlashPlayer extends Sdk {
|
||||
const filename = path.join(os.homedir(), "mm.cfg");
|
||||
const value = "TraceOutputFileEnable=1";
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
const data = fs.readFileSync(filename, "utf8");
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
@@ -104,7 +102,7 @@ export class FlashPlayer extends Sdk {
|
||||
static trust(value: string) {
|
||||
const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg");
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
const data = fs.readFileSync(filename, "utf8");
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
@@ -120,17 +118,6 @@ export class FlashPlayer extends Sdk {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
FlashPlayer.trust(filename);
|
||||
FlashPlayer.enableLog();
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params)
|
||||
.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();
|
||||
}),
|
||||
);
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params).exec().pipe(watch(FlashPlayer.log));
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -77,7 +77,10 @@ export class Haxe extends Sdk {
|
||||
|
||||
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"));
|
||||
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);
|
||||
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 });
|
||||
fs.writeFileSync(path.resolve(buildDir, "project.xml"), project);
|
||||
|
||||
@@ -128,7 +133,7 @@ export class Haxe extends Sdk {
|
||||
flash: "*.swf",
|
||||
}[platform] || "**/*";
|
||||
return this.haxelib(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`);
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "android") {
|
||||
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);
|
||||
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 =
|
||||
{
|
||||
@@ -175,9 +182,9 @@ export class Haxe extends Sdk {
|
||||
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
|
||||
}[platform] || "**/*";
|
||||
return this.haxe(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`);
|
||||
let r = vfs.src(`${target}/${result}`, { encoding: false });
|
||||
if (platform === "cpp") {
|
||||
r = r.pipe(rename(config.meta.filename));
|
||||
r = r.pipe(rename(config.meta.filename!));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
|
||||
@@ -43,7 +43,9 @@ export class InnoSetup extends Sdk {
|
||||
|
||||
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 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);
|
||||
|
||||
+2
-11
@@ -1,9 +1,8 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { TailVinyl } from "../common/tail";
|
||||
import { watch } from "../common/watch";
|
||||
import run from "../run";
|
||||
import { FlashPlayer } from "./flashplayer";
|
||||
|
||||
@@ -55,18 +54,10 @@ export class RufflePlayer extends FlashPlayer {
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params)
|
||||
.exec()
|
||||
.pipe(
|
||||
through.obj(function (file: any, enc: string, callback: any) {
|
||||
const log = new TailVinyl({
|
||||
path: RufflePlayer.log,
|
||||
handler: (line: string) => {
|
||||
watch(RufflePlayer.log, (line: string) => {
|
||||
if (line.includes("avm_trace")) {
|
||||
return line.split("avm_trace: ").pop();
|
||||
}
|
||||
},
|
||||
});
|
||||
this.on("end", () => log.dispose());
|
||||
this.push(log);
|
||||
callback();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from "./common/system";
|
||||
export * from "./core/config";
|
||||
export * from "./common/download";
|
||||
export * from "./core/sdk";
|
||||
export * from "./core/type";
|
||||
export * from "./impl/android";
|
||||
|
||||
@@ -15,7 +15,7 @@ export class FlashHTMLPacker extends Packer {
|
||||
call() {
|
||||
const target = this.targetPath;
|
||||
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);
|
||||
fs.writeFileSync(path.resolve(target, "index.html"), index);
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import gulp from "gulp";
|
||||
import deb from "gulp-debian";
|
||||
import template from "lodash.template";
|
||||
import { template } from "lodash";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
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 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")),
|
||||
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`);
|
||||
@@ -30,8 +30,8 @@ export class LinuxDEBPacker extends Packer {
|
||||
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,
|
||||
package: this.config.meta.filename!,
|
||||
version: this.config.meta.version!,
|
||||
section: "base",
|
||||
priority: "optional",
|
||||
architecture: "all",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import gulp from "gulp";
|
||||
import webserver from "gulp-webserver";
|
||||
import connect from "gulp-connect";
|
||||
import { Config } from "../../../core/config";
|
||||
import { Platform } from "../../../core/type";
|
||||
import { Runner } from "../../core/runner";
|
||||
@@ -10,15 +9,12 @@ export class Html5Runner extends Runner {
|
||||
}
|
||||
|
||||
call() {
|
||||
return gulp.src(this.targetPath).pipe(
|
||||
webserver({
|
||||
// TODO: config?
|
||||
return connect.server({
|
||||
root: this.targetPath,
|
||||
host: "0.0.0.0",
|
||||
port: 3000,
|
||||
open: true,
|
||||
fallback: "index.html",
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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";
|
||||
@@ -7,8 +8,6 @@ import { Runner } from "./core/runner";
|
||||
import { RuffleRunner } from "./impl/runner/ruffle";
|
||||
export * from "./core";
|
||||
|
||||
export type Task = any; // TODO: gulp task type
|
||||
|
||||
export class Project {
|
||||
// TODO: compatibility
|
||||
static Config = Config;
|
||||
@@ -56,8 +55,8 @@ export class Project {
|
||||
return [packer.prepare.bind(packer), packer.call.bind(packer)];
|
||||
}
|
||||
|
||||
compile(external_gulp?: any): Record<string, Task> {
|
||||
const result: Record<string, Task> = {};
|
||||
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));
|
||||
@@ -74,7 +73,7 @@ export class Project {
|
||||
return result;
|
||||
}
|
||||
|
||||
register(external_gulp?: any) {
|
||||
register(external_gulp?: gulp.Gulp) {
|
||||
const _gulp = external_gulp || gulp;
|
||||
for (const [k, v] of Object.entries(this.compile(_gulp))) {
|
||||
_gulp.task(k, v);
|
||||
|
||||
+17
-16
@@ -3,6 +3,7 @@ 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";
|
||||
@@ -65,7 +66,7 @@ export class Preset {
|
||||
return projects;
|
||||
}
|
||||
|
||||
register(external_gulp?: any, additional_tasks?: string[]) {
|
||||
register(external_gulp?: gulp.Gulp, additional_tasks?: string[]) {
|
||||
const _gulp = external_gulp || gulp;
|
||||
|
||||
const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
|
||||
@@ -114,15 +115,15 @@ export class Preset {
|
||||
project.register(_gulp);
|
||||
}
|
||||
|
||||
const defaultSeries = [_gulp.task("clean"), _gulp.task("setup")];
|
||||
const defaultSeries: Task[] = [_gulp.task("clean")!, _gulp.task("setup")!];
|
||||
|
||||
if (protohx) {
|
||||
defaultSeries.push("protohx:generate");
|
||||
defaultSeries.push(_gulp.task("protohx:generate")!);
|
||||
}
|
||||
|
||||
if (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) {
|
||||
switch (platform) {
|
||||
case Platform.FLASH:
|
||||
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}:build`)!);
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:html`)!);
|
||||
break;
|
||||
case Platform.HTML5:
|
||||
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`));
|
||||
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`));
|
||||
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`));
|
||||
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`));
|
||||
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`));
|
||||
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`));
|
||||
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;
|
||||
}
|
||||
|
||||
+53
-77
@@ -1,83 +1,61 @@
|
||||
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');
|
||||
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";
|
||||
|
||||
/**
|
||||
* Creates a new `gulp-run` command.
|
||||
*
|
||||
* @param {string} command
|
||||
* @param {object} options
|
||||
*/
|
||||
export function Command(command, options?) {
|
||||
var previousPath;
|
||||
export class Command {
|
||||
private command: string;
|
||||
private isWindows: boolean;
|
||||
private options: any;
|
||||
|
||||
constructor(command: string, options?: any) {
|
||||
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.isWindows = process.platform.lastIndexOf("win") === 0;
|
||||
this.options = defaults(options || {}, {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
verbosity: (options && options.silent) ? 1 : 2,
|
||||
usePowerShell: false
|
||||
verbosity: options && options.silent ? 1 : 2,
|
||||
usePowerShell: false,
|
||||
});
|
||||
|
||||
// include node_modules/.bin on the path when we execute the command.
|
||||
let previousPath;
|
||||
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 += 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;
|
||||
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') {
|
||||
if (typeof stdin === "function") {
|
||||
callback = stdin;
|
||||
stdin = undefined;
|
||||
} else if (typeof callback !== 'function') {
|
||||
} else if (typeof callback !== "function") {
|
||||
callback = function noop() {};
|
||||
}
|
||||
|
||||
if (!(stdin instanceof Vinyl)) {
|
||||
fileName = this.command.split(' ')[0];
|
||||
fileName = this.command.split(" ")[0];
|
||||
directory = path.join(this.options.cwd, fileName);
|
||||
|
||||
if (typeof stdin === 'string') {
|
||||
if (typeof stdin === "string") {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: new Buffer(stdin)
|
||||
contents: new Buffer(stdin),
|
||||
});
|
||||
} else if (stdin instanceof Buffer || stdin instanceof stream.Readable) {
|
||||
stdin = new Vinyl({
|
||||
path: directory,
|
||||
contents: stdin
|
||||
contents: stdin,
|
||||
});
|
||||
} else {
|
||||
stdin = new Vinyl(stdin);
|
||||
@@ -91,27 +69,27 @@ Command.prototype.exec = function exec(stdin, callback) {
|
||||
// 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
|
||||
const command = template(this.command)({
|
||||
file: stdin,
|
||||
});
|
||||
|
||||
if (this.isWindows && this.options.usePowerShell) {
|
||||
// windows powershell
|
||||
subShell = cp.spawn('powershell.exe', ['-NonInteractive', '-NoLogo', '-Command', command], {
|
||||
subShell = cp.spawn("powershell.exe", ["-NonInteractive", "-NoLogo", "-Command", command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd
|
||||
cwd: this.options.cwd,
|
||||
});
|
||||
} else if (this.isWindows) {
|
||||
// windows cmd.exe
|
||||
subShell = cp.spawn('cmd.exe', ['/c', command], {
|
||||
subShell = cp.spawn("cmd.exe", ["/c", command], {
|
||||
env: this.options.env,
|
||||
cwd: this.options.cwd
|
||||
cwd: this.options.cwd,
|
||||
});
|
||||
} else {
|
||||
// POSIX shell
|
||||
subShell = cp.spawn('sh', ['-c', command], {
|
||||
subShell = cp.spawn("sh", ["-c", command], {
|
||||
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)
|
||||
// - if verbosity equals to 1, the command's stderr is buffered as in 2, but
|
||||
// the stdout is silenced.
|
||||
log = new stream.PassThrough();
|
||||
const log = new stream.PassThrough();
|
||||
|
||||
function sendLog(context) {
|
||||
const sendLog = (context: any) => {
|
||||
var title = util.format(
|
||||
'$ %s%s',
|
||||
"$ %s%s",
|
||||
colors.blue(command),
|
||||
(self.options.verbosity < 2) ? colors.grey(' # Silenced\n') : '\n'
|
||||
this.options.verbosity < 2 ? colors.grey(" # Silenced\n") : "\n",
|
||||
);
|
||||
|
||||
context.write(title);
|
||||
}
|
||||
};
|
||||
|
||||
switch (this.options.verbosity) {
|
||||
case 3:
|
||||
@@ -151,19 +129,21 @@ Command.prototype.exec = function exec(stdin, callback) {
|
||||
}
|
||||
|
||||
// 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
|
||||
var content = log.read();
|
||||
const content = log.read();
|
||||
|
||||
if (content !== null) {
|
||||
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.
|
||||
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;
|
||||
|
||||
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)
|
||||
// with different contents.
|
||||
stdout = stdin.clone();
|
||||
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:
|
||||
//stdin.pipe(subShell.stdin); //TODO:
|
||||
|
||||
return stdout;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command template.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
Command.prototype.toString = function toString() {
|
||||
toString() {
|
||||
return this.command;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+14
-61
@@ -1,71 +1,24 @@
|
||||
/**
|
||||
* Pipe shell commands in gulp.
|
||||
* @module gulp-run
|
||||
*/
|
||||
|
||||
import { Transform, type TransformCallback } from "stream";
|
||||
import { Command } from "./command";
|
||||
|
||||
var inherit = require("util").inherits;
|
||||
var Transform = require("stream").Transform;
|
||||
export class RunTransform extends Transform {
|
||||
private command: 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);
|
||||
constructor(template: string, options?: any) {
|
||||
super({ objectMode: true });
|
||||
this.command = new Command(template, options || {});
|
||||
}
|
||||
|
||||
this.command = new Command(template, options || {});
|
||||
Transform.call(this, { objectMode: true });
|
||||
}
|
||||
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void {
|
||||
const stdout = this.command.exec(chunk, callback);
|
||||
this.push(stdout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
exec(stdin?: any, callback?: any) {
|
||||
this.write(stdin, callback);
|
||||
this.end();
|
||||
return this;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @type {Command}
|
||||
*/
|
||||
GulpRunner.Command = Command;
|
||||
|
||||
export default GulpRunner;
|
||||
export default (template: string, options?: any) => new RunTransform(template, options);
|
||||
|
||||
@@ -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
@@ -14,7 +14,8 @@
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"noImplicitThis": false,
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user