Skip to content

Commit

Permalink
Start using haxe-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 committed Aug 25, 2019
1 parent 31a538f commit ce005ef
Show file tree
Hide file tree
Showing 140 changed files with 1,449 additions and 1,442 deletions.
38 changes: 19 additions & 19 deletions BuildExamples.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import haxe.io.Path;
import sys.FileSystem;

class BuildExamples {
static function main() {
Sys.setCwd("examples");
for (file in FileSystem.readDirectory(".")) {
if (Path.extension(file) == "hx") {
var main = Path.withoutExtension(file);
var code = Sys.command("haxe", [
"-main", main,
"-js", '$main.js',
"-lib", "hxnodejs",
"-D", "js-es5",
"-D", "analyzer",
"-dce", "full",
]);
if (code != 0)
Sys.exit(code);
}
}
}
}
static function main() {
Sys.setCwd("examples");
for (file in FileSystem.readDirectory(".")) {
if (Path.extension(file) == "hx") {
var main = Path.withoutExtension(file);
var code = Sys.command("haxe", [
"-main", main,
"-js", '$main.js',
"-lib", "hxnodejs",
"-D", "js-es5",
"-D", "analyzer",
"-dce", "full",
]);
if (code != 0)
Sys.exit(code);
}
}
}
}
40 changes: 20 additions & 20 deletions ImportAll.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import haxe.macro.Context;
import sys.FileSystem;

class ImportAll {
static function run(cp:String):Void {
Compiler.addClassPath(cp);
Compiler.allowPackage("sys");
Compiler.define("nodejs");
static function run(cp:String):Void {
Compiler.addClassPath(cp);
Compiler.allowPackage("sys");
Compiler.define("nodejs");

function loop(acc:Array<String>):Void {
var path = Path.join([cp].concat(acc));
if (FileSystem.isDirectory(path)) {
if (acc.length > 0 && acc[acc.length - 1].charCodeAt(0) == "_".code) // skip hidden packages
return;
for (file in FileSystem.readDirectory(path))
loop(acc.concat([file]));
} else if (Path.extension(path) == "hx") {
var moduleName = Path.withoutExtension(acc[acc.length - 1]);
var modulePath = acc.slice(0, acc.length - 1);
var typePath = if (modulePath.length == 0) moduleName else modulePath.join(".") + "." + moduleName;
Context.getType(typePath);
}
}
loop([]);
}
function loop(acc:Array<String>):Void {
var path = Path.join([cp].concat(acc));
if (FileSystem.isDirectory(path)) {
if (acc.length > 0 && acc[acc.length - 1].charCodeAt(0) == "_".code) // skip hidden packages
return;
for (file in FileSystem.readDirectory(path))
loop(acc.concat([file]));
} else if (Path.extension(path) == "hx") {
var moduleName = Path.withoutExtension(acc[acc.length - 1]);
var modulePath = acc.slice(0, acc.length - 1);
var typePath = if (modulePath.length == 0) moduleName else modulePath.join(".") + "." + moduleName;
Context.getType(typePath);
}
}
loop([]);
}
}
100 changes: 49 additions & 51 deletions Release.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,57 @@ import haxe.crypto.Crc32;
import haxe.zip.Entry;
import haxe.zip.Writer;
import haxe.zip.Tools;

import sys.io.File;
import sys.FileSystem;

class Release {
static var outPath = "release.zip";
static var files = ["haxelib.json", "extraParams.hxml", "src", "LICENSE", "README.md"];

static function makeZip() {
var entries = new List<Entry>();

function add(path:String, target:String) {
if (!FileSystem.exists(path))
throw 'Invalid path: $path';

if (FileSystem.isDirectory(path)) {
for (item in FileSystem.readDirectory(path))
add(path + "/" + item, target + "/" + item);
} else {
trace("Adding " + target);
var bytes = File.getBytes(path);
var entry:Entry = {
fileName: target,
fileSize: bytes.length,
fileTime: FileSystem.stat(path).mtime,
compressed: false,
dataSize: 0,
data: bytes,
crc32: Crc32.make(bytes),
}
Tools.compress(entry, 9);
entries.add(entry);
}

}

for (file in files)
add(file, file);

trace("Saving to " + outPath);
var out = File.write(outPath, true);
var writer = new Writer(out);
writer.write(entries);
out.close();
}

static function submitZip() {
trace("Submitting " + outPath);
Sys.command("haxelib", ["submit", outPath]);
}

static function main() {
makeZip();
submitZip();
}
static var outPath = "release.zip";
static var files = ["haxelib.json", "extraParams.hxml", "src", "LICENSE", "README.md"];

static function makeZip() {
var entries = new List<Entry>();

function add(path:String, target:String) {
if (!FileSystem.exists(path))
throw 'Invalid path: $path';

if (FileSystem.isDirectory(path)) {
for (item in FileSystem.readDirectory(path))
add(path + "/" + item, target + "/" + item);
} else {
trace("Adding " + target);
var bytes = File.getBytes(path);
var entry:Entry = {
fileName: target,
fileSize: bytes.length,
fileTime: FileSystem.stat(path).mtime,
compressed: false,
dataSize: 0,
data: bytes,
crc32: Crc32.make(bytes),
}
Tools.compress(entry, 9);
entries.add(entry);
}
}

for (file in files)
add(file, file);

trace("Saving to " + outPath);
var out = File.write(outPath, true);
var writer = new Writer(out);
writer.write(entries);
out.close();
}

static function submitZip() {
trace("Submitting " + outPath);
Sys.command("haxelib", ["submit", outPath]);
}

static function main() {
makeZip();
submitZip();
}
}
12 changes: 6 additions & 6 deletions ci/Config.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Utils.*;

class Config {
static public var htmlDir = env("GHP_HTMLDIR", "bin/api");
static public var remote = env("GHP_REMOTE", null); // should be in the form of https://[email protected]/account/repo.git
static public var branch = env("GHP_BRANCH", "gh-pages");
static public var username = env("GHP_USERNAME", null);
static public var email = env("GHP_EMAIL", null);
}
static public var htmlDir = env("GHP_HTMLDIR", "bin/api");
static public var remote = env("GHP_REMOTE", null); // should be in the form of https://[email protected]/account/repo.git
static public var branch = env("GHP_BRANCH", "gh-pages");
static public var username = env("GHP_USERNAME", null);
static public var email = env("GHP_EMAIL", null);
}
67 changes: 34 additions & 33 deletions ci/DeployGhPages.hx
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import Sys.*;
import Utils.*;
import Config.*;

using StringTools;

class DeployGhPages {
static function main():Void {
var root = getCwd();
static function main():Void {
var root = getCwd();

if (remote == null) {
println('GHP_REMOTE is not set, skip deploy.');
return;
}
if (remote == null) {
println('GHP_REMOTE is not set, skip deploy.');
return;
}

// TravisCI by default clones repositories to a depth of 50 commits.
// We need a full clone inorder to do git operations.
runCommand("git", ["fetch", "--unshallow"]);
// TravisCI by default clones repositories to a depth of 50 commits.
// We need a full clone inorder to do git operations.
runCommand("git", ["fetch", "--unshallow"]);

var sha = commandOutput("git", ["rev-parse", "HEAD"]).trim();
var sha = commandOutput("git", ["rev-parse", "HEAD"]).trim();

setCwd(htmlDir);
runCommand("git", ["init"]);
if (username != null)
runCommand("git", ["config", "--local", "user.name", username]);
if (email != null)
runCommand("git", ["config", "--local", "user.email", email]);
runCommand("git", ["remote", "add", "local", root]);
runCommand("git", ["remote", "add", "remote", remote]);
runCommand("git", ["fetch", "--all"]);
runCommand("git", ["checkout", "--orphan", branch]);
if (commandOutput("git", ["ls-remote", "--heads", "local", branch]).trim() != "") {
runCommand("git", ["reset", "--soft", 'local/${branch}']);
}
if (commandOutput("git", ["ls-remote", "--heads", "remote", branch]).trim() != "") {
runCommand("git", ["reset", "--soft", 'remote/${branch}']);
}
runCommand("git", ["add", "--all"]);
runCommand("git", ["commit", "--allow-empty", "--quiet", "-m", 'deploy for ${sha}']);
runCommand("git", ["push", "local", branch]);
setCwd(htmlDir);
runCommand("git", ["init"]);
if (username != null)
runCommand("git", ["config", "--local", "user.name", username]);
if (email != null)
runCommand("git", ["config", "--local", "user.email", email]);
runCommand("git", ["remote", "add", "local", root]);
runCommand("git", ["remote", "add", "remote", remote]);
runCommand("git", ["fetch", "--all"]);
runCommand("git", ["checkout", "--orphan", branch]);
if (commandOutput("git", ["ls-remote", "--heads", "local", branch]).trim() != "") {
runCommand("git", ["reset", "--soft", 'local/${branch}']);
}
if (commandOutput("git", ["ls-remote", "--heads", "remote", branch]).trim() != "") {
runCommand("git", ["reset", "--soft", 'remote/${branch}']);
}
runCommand("git", ["add", "--all"]);
runCommand("git", ["commit", "--allow-empty", "--quiet", "-m", 'deploy for ${sha}']);
runCommand("git", ["push", "local", branch]);

setCwd(root);
runCommand("git", ["push", remote, branch]);
}
}
setCwd(root);
runCommand("git", ["push", remote, branch]);
}
}
Loading

0 comments on commit ce005ef

Please sign in to comment.