Created
March 28, 2020 05:04
-
-
Save Alhadis/965c27e64bf360cb063066388560b81b to your computer and use it in GitHub Desktop.
Stupid compilation test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BIN = ../../var/bin | |
LIB = ../../var/lib | |
SRC-MAIN = print-status.mjs | |
SRC-QJS = qjs-entry.mjs | |
NAME = git-status | |
TMP = $(TMP-MAIN) $(TMP-QJS) | |
TMP-MAIN = $(LIB)/$(SRC-MAIN) | |
TMP-QJS = $(LIB)/$(SRC-QJS) | |
BUNDLE = $(LIB)/$(NAME).mjs | |
OUT = $(BIN)/$(NAME) | |
all: $(OUT) | |
# Compile an executable using QuickJS | |
$(OUT): $(LIB)/Labs $(BUNDLE) | |
qjsc -flto -o $@ $(BUNDLE) | |
strip $@ | |
chmod +x $@ | |
# Transient copies of ESM source | |
$(TMP-QJS): $(SRC-QJS); sed < $^ > $@ -e '/^#!/ d' | |
$(TMP-MAIN): $(SRC-MAIN); sed < $^ > $@ -e '/^#!/ d; s|from "\.\./\.\./\.\./Labs/|from "./Labs/|g' | |
$(BUNDLE): $(TMP) | |
rollup \ | |
--format es \ | |
--preferConst \ | |
--no-esModule \ | |
--no-externalLiveBindings \ | |
--no-freeze \ | |
--no-indent \ | |
--no-interop \ | |
--no-treeshake.propertyReadSideEffects \ | |
--inlineDynamicImports \ | |
--input $(TMP-QJS) \ | |
--file $@ | |
sed -i.bak -e '/^Promise\.resolve()\.then(function/ { d; q; }' $@ | |
sed -i.bak -e 's/^\( *const *isQuickJS *=\)\s*/\1 true; void /' $@ | |
rm -f $@.bak | |
# Wipe generated files | |
clean:; rm -f $(OUT) $(BUNDLE) $(TMP) $(LIB)/.*.mjs | |
.PHONY: clean | |
# Create missing directories if needed | |
$(BIN):; mkdir $@ | |
$(LIB):; mkdir $@ | |
# Checkout projects locally if they're missing | |
$(HOME)/Labs:; mkdir $@ | |
$(HOME)/Labs/Utils:; cd $^ && git clone git@github.com:Alhadis/Utils.git | |
$(HOME)/Labs/EAL:; cd $^ && git clone git@github.com:Alhadis/EAL.git | |
# Symlink project directories | |
$(LIB)/Labs: $(LIB) $(HOME)/Labs $(HOME)/Labs/Utils $(HOME)/Labs/EAL | |
test -e $@ && touch $@ || ln -s $(HOME)/Labs $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import {parseGitStatus} from "../../../Labs/Utils/lib/text.mjs"; | |
import {exec, log, argv, warn, exit, isTTY} from "../../../Labs/EAL/index.mjs"; | |
exec("git", ["status", "--porcelain=2", "-bz", ...argv]).then(result => { | |
const {stdout, stderr, code} = result; | |
stderr && warn(stderr); | |
code && exit(code); | |
const status = parseGitStatus(stdout); | |
const [OFF, RED, GREEN, GREY] = isTTY(1) | |
? ["\x1B[0m", "\x1B[31m", "\x1B[32m", "\x1B[38;5;8m"] | |
: ["", "", "", ""]; | |
log(status.isDetached | |
? `${RED}HEAD detached at${OFF} ${status.currentCommit}` | |
: `On branch ${status.currentBranch}`); | |
if(status.upstream){ | |
const {ahead, behind} = status.upstream; | |
const branch = `'${status.upstream.branch}'`; | |
if(ahead && behind){ | |
log(`Your branch and ${branch} have diverged,`); | |
log(`and have ${ahead} and ${behind} different commits each, respectively.`); | |
} | |
else if(ahead) | |
log(`Your branch is ahead of ${branch} by ${ahead} commit${1 !== ahead ? "s" : ""}.`); | |
else if(behind) | |
log(`Your branch is behind '${branch}' by ${behind} commit${1 !== behind ? "s" : ""}, and can be fast-forwarded.`); | |
else | |
log(`Your branch is up-to-date with ${branch}.`); | |
} | |
if(status.isNewRepo) | |
log("\nNo commits yet"); | |
if(status.isClean) | |
log("\nnothing to commit, working tree clean"); | |
else{ | |
if(status.changes){ | |
const {staged, unstaged} = divvy(status.changes); | |
if(staged.length){ | |
log("\nChanges to be committed:\n"); | |
for(const entry of staged) | |
log("\t" + GREEN + entry + OFF); | |
} | |
if(unstaged.length){ | |
log("\nChanges not staged for commit:\n"); | |
for(const entry of unstaged) | |
log("\t" + RED + entry + OFF); | |
} | |
} | |
if(status.untracked){ | |
log("\nUntracked files:\n"); | |
for(const path of status.untracked) | |
log("\t" + RED + path + OFF); | |
} | |
if(status.ignored){ | |
log("\nIgnored files:\n"); | |
for(const path of status.ignored) | |
log("\t" + GREY + path + OFF); | |
} | |
log(!status.changes ? `\n${status.isNewRepo ? "nothing" : "no changes added"} to commit` : ""); | |
} | |
}).catch(error => { | |
warn(error); | |
exit(1); | |
}); | |
function divvy(changes){ | |
const staged = []; | |
const unstaged = []; | |
for(const {state: states, path} of changes) | |
for(const [state, list] of [[states.index, staged], [states.workTree, unstaged]]) | |
if("unmodified" === state) | |
continue; | |
else list.push(("added" === state ? "new file" : state) | |
+ ": " | |
+ ("string" === typeof path ? path : `${path.old} -> ${path.new}`) | |
+ (state.similarity ? ` (${state.similarity}% similarity)` : "")); | |
return {staged, unstaged}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env qjs | |
import * as std from "std"; | |
import * as os from "os"; | |
globalThis.std = std; | |
globalThis.os = os; | |
Error.prototype.toString = function(){ | |
return `${this.name}: ${this.message}\n${this.stack}`.trim(); | |
}; | |
import("./print-status.mjs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sed -f | |
s|^\(export[[:blank:]][[:blank:]]*const[[:blank:]][[:blank:]]*haveNativeDOM *=\) *|\1 false; 0 \&\& |; | |
/^export[[:blank:]][[:blank:]]*const[[:blank:]][[:blank:]]*is[A-Z]/ { | |
s/\(isQuickJS *=\) */\1 true; void / | |
s/\(isBrowser *=\) */\1 false; void / | |
s/\(isDeno *=\) */\1 false; void / | |
s/\(isNode *=\) */\1 false; void / | |
s/\(isElectron *=\) */\1 false; void / | |
s/\(isV8Shell *=\) */\1 false; void / | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment