-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4f2c6a
commit bd7bd02
Showing
5 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import * as eta from "https://deno.land/x/[email protected]/mod.ts" | ||
import { resolve } from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
eta.configure | ||
tags: ["{{", "}}"] | ||
useWith: true | ||
varName: "opt" | ||
parse: { exec: "#", raw: "%", interpolate: "" } | ||
|
||
# magic happens here | ||
export runRecipe = (rc, cwd, recipe, options, recon, asIngredient) -> | ||
export runRecipe = (rc, recipe, options, recon, asIngredient) -> | ||
previousCwd = Deno.cwd() | ||
if not (rc.hasOwnProperty(recipe)) | ||
console.error("\nxuerun: oops, recipe '#{recipe}' is not in .xuerun tasks!\n") | ||
Deno.exit(1) | ||
|
@@ -33,10 +35,11 @@ export runRecipe = (rc, cwd, recipe, options, recon, asIngredient) -> | |
dependencies = if typeof currentRecipe.dependencies == | ||
"string" then currentRecipe.dependencies.split(" ") else currentRecipe.dependencies | ||
|
||
usedCwd = currentRecipe.cwd or cwd | ||
usedCwd = currentRecipe.cwd and resolve(Deno.cwd(), currentRecipe.cwd) or Deno.cwd() | ||
|
||
for dep in dependencies | ||
# won't pass options | ||
if typeof dep == "string" then await runRecipe(rc, usedCwd, dep, {}); break | ||
if typeof dep == "string" then await runRecipe(rc, dep, {}, recon, true); break | ||
|
||
depOption = { ...dep.options } | ||
if typeof dep.passParentOptions == "boolean" and dep.passParentOptions | ||
|
@@ -54,8 +57,10 @@ export runRecipe = (rc, cwd, recipe, options, recon, asIngredient) -> | |
console.error("\nxuerun: oops, something went wrong while reading options.\nError:", | ||
err.message, "\n") | ||
Deno.exit(1) | ||
await runRecipe(rc, usedCwd, dep.name, depOptionToBePassed, recon, true) | ||
await runRecipe(rc, dep.name, depOptionToBePassed, recon, true) | ||
|
||
# change to given cwd for Deno process | ||
Deno.chdir(usedCwd) | ||
# make main recipe | ||
_commands = currentRecipe.command | ||
commands = (if typeof _commands == "string" then [_commands] else _commands) | ||
|
@@ -68,14 +73,20 @@ export runRecipe = (rc, cwd, recipe, options, recon, asIngredient) -> | |
"\nxuerun: oops, something went wrong while reading command.\nError:", | ||
err.message, "\n") | ||
Deno.exit(1) | ||
|
||
for cmdOption in commands | ||
# used by eval | ||
opt = currentOption | ||
# don't run if eval when is false | ||
if typeof cmdOption == "object" and not Boolean(eval(cmdOption.when)) then continue | ||
|
||
commandToRun = [ | ||
(if typeof cmdOption == "object" and | ||
cmdOption.shell then cmdOption.shell else currentRecipe.shell), "-c", | ||
if typeof cmdOption == "string" then cmdOption else cmdOption.cmd ] | ||
|
||
# if recon, just show command | ||
if recon then return console.info(commandToRun) | ||
if recon then console.info(commandToRun); continue | ||
|
||
# run command | ||
preparedEnv = {} | ||
|
@@ -104,3 +115,5 @@ export runRecipe = (rc, cwd, recipe, options, recon, asIngredient) -> | |
if status.code != 0 | ||
console.error("\nxuerun: command exit with exit code:", status.code, "\n") | ||
Deno.exit(status.code) | ||
# back to previous cwd ( root of project ) | ||
Deno.chdir(previousCwd) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { parse as parseYAML } from "https://deno.land/[email protected]/encoding/yaml.ts" | ||
import { YAMLError } from "https://deno.land/[email protected]/encoding/_yaml/error.ts" | ||
import { printf } from "https://deno.land/[email protected]/fmt/printf.ts" | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { parse as parseYAML } from "https://deno.land/[email protected]/encoding/yaml.ts" | ||
import { YAMLError } from "https://deno.land/[email protected]/encoding/_yaml/error.ts" | ||
import { dirname, resolve } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { printf } from "https://deno.land/[email protected]/fmt/printf.ts" | ||
import { StructError } from "https://esm.sh/superstruct" | ||
import { runRecipe } from "./core.coffee" | ||
import createConfiguration from "./schema.coffee" | ||
|
@@ -86,11 +87,14 @@ programMain = () -> | |
|
||
# load and run | ||
xueRunRc = loadXueRunTasks(tasksPath) | ||
# change dir to task path dir. | ||
Deno.chdir(dirname(resolve(tasksPath))) | ||
|
||
if recipes.length == 0 | ||
if xueRunRc.hasOwnProperty("all") | ||
return runRecipe(xueRunRc, null, recipes, userOption) | ||
else console.error("\nxuerun: oops, no recipe given, nothing to do!\n"); Deno.exit(1) | ||
recipes.forEach (recipe) -> await runRecipe(xueRunRc, null, recipe, options, recon, !1) | ||
recipes.forEach (recipe) -> await runRecipe(xueRunRc, recipe, options, recon, !1) | ||
|
||
# call main function | ||
if import.meta.main then programMain() |
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
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