Skip to content

Commit

Permalink
Version bumps and config tweaks (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkedy authored Feb 4, 2024
1 parent 3f6ac1c commit c666c89
Show file tree
Hide file tree
Showing 35 changed files with 136 additions and 118 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Install `deno` with instructions
To install a release version of the `apex` CLI, run the command below:

```
deno install -A --unstable -f -n apex https://deno.land/x/[email protected]/apex.ts
deno install -A -f -n apex https://deno.land/x/[email protected]/apex.ts
```

To install from source, clone this repository and run `./apex run install`
To install from source, clone this repository and run `./apex install`

```sh
git clone https://github.com/apexlang/apex.git
cd apex
./apex install # or deno install -A --unstable ./apex.ts
./apex install # or deno install -A -f ./apex.ts
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion apex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
# deno install mocker
exec deno run --allow-all --unstable './apex.ts' "$@"
exec deno run --allow-all './apex.ts' "$@"
16 changes: 10 additions & 6 deletions apex.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run --unstable
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run

import { Command, CompletionsCommand, HelpCommand } from "./src/deps/cliffy.ts";
import { GithubProvider, UpgradeCommand } from "./src/deps/cliffy.ts";
import * as log from "https://deno.land/[email protected]/log/mod.ts";
import {
Command,
CompletionsCommand,
GithubProvider,
HelpCommand,
UpgradeCommand,
} from "./src/deps/cliffy.ts";
import * as log from "https://deno.land/[email protected]/log/mod.ts";

const LEVEL =
(Deno.env.get("APEX_LOG")?.toUpperCase() as log.LevelName | undefined) ||
Expand All @@ -29,7 +34,7 @@ const args = Array.from(Deno.args);
if (
args.length == 1 &&
args[0] == "__generate" &&
!Deno.isatty(Deno.stdin.rid)
!Deno.stdin.isTerminal()
) {
generate.fromStdin();
} else {
Expand Down Expand Up @@ -58,7 +63,6 @@ if (
"--allow-env",
"--allow-net",
"--allow-run",
"--unstable",
],
provider: [new GithubProvider({ repository: "apexlang/apex" })],
}),
Expand Down
6 changes: 3 additions & 3 deletions apex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ tasks:
cmds:
- deno fmt --check src/ test/
- deno lint src/
- deno check --unstable apex.ts
- deno test --unstable -A
- deno check apex.ts
- deno test -A
install:
description: Install apex
cmds:
- deno install -f -A --unstable ./apex.ts
- deno install -A -f ./apex.ts
2 changes: 1 addition & 1 deletion src/astyle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as WASI } from "https://deno.land/std@0.192.0/wasi/snapshot_preview1.ts";
import { default as WASI } from "https://deno.land/std@0.206.0/wasi/snapshot_preview1.ts";
import { cache } from "https://deno.land/x/[email protected]/mod.ts";
import { decode, encode } from "./utf8.ts";

Expand Down
7 changes: 7 additions & 0 deletions src/commands/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const templates = new Command()
if (temp.description) {
console.log(`Description: ${temp.description}`);
}
if (temp.metadata) {
console.log(`Metadata:`);
Object.keys(temp.metadata).forEach((key) => {
const value = temp.metadata![key];
console.log(` ${key}: ${value}`);
});
}

const variables = temp.variables || [];
if (variables.length > 0) {
Expand Down
18 changes: 11 additions & 7 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from "../deps/cliffy.ts";
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";

import { Configuration, Output, parseConfigYaml } from "../config.ts";
import {
Expand All @@ -21,11 +21,15 @@ export const command = new Command()
"reload files from cache",
)
.action(async (options: ProcessOptions, configFiles: string[]) => {
configFiles ||= [];
if (!configFiles.length) {
configFiles = ["apex.yaml"];
if (!Deno.stdin.isTerminal()) {
await fromStdin(options || {});
} else {
configFiles ||= [];
if (!configFiles.length) {
configFiles = ["apex.yaml"];
}
await fromFiles(configFiles, options || {});
}
await fromFiles(configFiles, options || {});
});

export async function fromFiles(
Expand All @@ -46,7 +50,7 @@ export async function fromFiles(
}

export async function fromStdin(options: ProcessOptions = {}) {
const stdinContent = await streams.readAll(Deno.stdin);
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
const configs = parseConfigYaml(content);
await fromConfigs(configs, options);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
import * as yaml from "https://deno.land/std@0.192.0/yaml/mod.ts";
import * as path from "https://deno.land/std@0.213.0/path/mod.ts";
import * as yaml from "https://deno.land/std@0.213.0/yaml/mod.ts";

import { Command } from "../deps/cliffy.ts";
import { getInstallDirectories } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from "../deps/cliffy.ts";
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";
import { fromConfigs } from "./generate.ts";
import * as ui from "../ui.ts";

Expand Down
6 changes: 3 additions & 3 deletions src/commands/watch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from "../deps/cliffy.ts";
import * as yaml from "https://deno.land/std@0.192.0/yaml/mod.ts";
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
import * as yaml from "https://deno.land/std@0.213.0/yaml/mod.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";
import * as path from "https://deno.land/std@0.213.0/path/mod.ts";

import { Configuration } from "../config.ts";
import {
Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TaskConfig } from "./task.ts";
import * as yaml from "https://deno.land/std@0.192.0/yaml/mod.ts";
import * as yaml from "https://deno.land/std@0.213.0/yaml/mod.ts";
import { findApexConfig } from "./utils.ts";
import { log } from "./deps/log.ts";

export type Config = { [key: string]: unknown };
export type Config = Record<string, unknown>;

/// MAIN CONFIG

Expand Down Expand Up @@ -76,7 +76,8 @@ export interface FSStructure {
variables?: Record<string, string | number | boolean>;
files?: string[];
directories?: string[];
templates?: { [engine: string]: string[] };
templates?: Record<string, string[]>;
definitions?: Record<string, string>;
}

export interface TemplateConfig {
Expand All @@ -97,6 +98,7 @@ export interface Template {
export interface TemplateInfo {
name: string;
description: string;
metadata?: Record<string, unknown>;
variables?: Variable[];
specLocation?: string;
}
Expand Down
5 changes: 4 additions & 1 deletion src/deps/cliffy.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from "https://deno.land/x/[email protected]/mod.ts";
export * from "https://deno.land/x/[email protected]/command/mod.ts";
export * from "https://deno.land/x/[email protected]/prompt/mod.ts";
export * from "https://deno.land/x/[email protected]/table/mod.ts";
export * from "https://deno.land/x/[email protected]/ansi/mod.ts";
2 changes: 1 addition & 1 deletion src/deps/dax.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/dax@0.32.0/mod.ts";
export * from "https://deno.land/x/dax@0.37.1/mod.ts";
2 changes: 1 addition & 1 deletion src/deps/log.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as log from "https://deno.land/std@0.192.0/log/mod.ts";
export * as log from "https://deno.land/std@0.213.0/log/mod.ts";
18 changes: 9 additions & 9 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as apex from "https://deno.land/x/[email protected].3/mod.ts";
import * as model from "https://deno.land/x/[email protected].3/model/mod.ts";
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as base64 from "https://deno.land/std@0.192.0/encoding/base64.ts";
import * as ast from "https://deno.land/x/[email protected].5/ast.ts";
import * as model from "https://deno.land/x/[email protected].5/model.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";
import * as base64 from "https://deno.land/std@0.213.0/encoding/base64.ts";

import {
Config,
Expand Down Expand Up @@ -116,7 +116,7 @@ export async function processConfig(
}

export async function processPlugin(
doc: apex.ast.Document,
doc: ast.Document,
config: Configuration,
): Promise<Configuration> {
// make a copy of our original config to protect against mutation
Expand Down Expand Up @@ -148,16 +148,16 @@ export async function importTemplate(
}

// Detect piped input
if (!Deno.isatty(Deno.stdin.rid) && import.meta.main) {
const stdinContent = await streams.readAll(Deno.stdin);
if (!Deno.stdin.isTerminal() && import.meta.main) {
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
const scaffold = Deno.args.indexOf("--scaffold") != -1;
try {
const config = JSON.parse(content) as Configuration;
console.log(
JSON.stringify(
await processConfig(config, scaffold),
(_, v) => v instanceof Uint8Array ? base64.encode(v) : v,
(_, v) => v instanceof Uint8Array ? base64.encodeBase64(v) : v,
),
);
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
import * as fs from "https://deno.land/std@0.192.0/fs/mod.ts";
import * as yaml from "https://deno.land/std@0.192.0/yaml/mod.ts";
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as path from "https://deno.land/std@0.213.0/path/mod.ts";
import * as fs from "https://deno.land/std@0.213.0/fs/mod.ts";
import * as yaml from "https://deno.land/std@0.213.0/yaml/mod.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";
import {
Confirm,
ConfirmOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";

import { getTemplateInfo, ProcessOptions, processTemplate } from "./process.ts";
import { makeRelativeUrl } from "./utils.ts";
Expand Down
10 changes: 5 additions & 5 deletions src/process.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// deno-lint-ignore-file no-explicit-any
import * as log from "https://deno.land/std@0.192.0/log/mod.ts";
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
import * as log from "https://deno.land/std@0.213.0/log/mod.ts";
import * as path from "https://deno.land/std@0.213.0/path/mod.ts";
import { fileExtension } from "https://deno.land/x/[email protected]/mod.ts";
import * as base64 from "https://deno.land/std@0.192.0/encoding/base64.ts";
import * as base64 from "https://deno.land/std@0.213.0/encoding/base64.ts";

const __dirname = new URL(".", import.meta.url).pathname;

Expand Down Expand Up @@ -79,7 +79,7 @@ export async function process(
log.debug(`Generator output: ${output}`);
const fromJson = JSON.parse(output) as JsonOutput[];
return fromJson.map((o: any) => {
o.contents = base64.decode(o.contents);
o.contents = base64.decodeBase64(o.contents);
return o as Output;
});
}
Expand All @@ -105,7 +105,7 @@ export async function processConfiguration(
options,
);
return fromJson.map((o: any) => {
o.contents = base64.decode(o.contents);
o.contents = base64.decodeBase64(o.contents);
return o as Output;
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/run_config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as base64 from "https://deno.land/std@0.192.0/encoding/base64.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";
import * as base64 from "https://deno.land/std@0.213.0/encoding/base64.ts";

import { Configuration } from "./config.ts";
import { processConfig } from "./generate.ts";

// Detect piped input
if (!Deno.isatty(Deno.stdin.rid) && import.meta.main) {
const stdinContent = await streams.readAll(Deno.stdin);
if (!Deno.stdin.isTerminal() && import.meta.main) {
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
const scaffold = Deno.args.indexOf("--scaffold") != -1;
try {
const config = JSON.parse(content) as Configuration;
console.log(JSON.stringify(
await processConfig(config, scaffold),
(_, v) => v instanceof Uint8Array ? base64.encode(v) : v,
(_, v) => v instanceof Uint8Array ? base64.encodeBase64(v) : v,
));
} catch (e) {
console.error(e);
Expand Down
10 changes: 5 additions & 5 deletions src/run_plugins.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as base64 from "https://deno.land/std@0.192.0/encoding/base64.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";
import * as base64 from "https://deno.land/std@0.213.0/encoding/base64.ts";

import { Configuration } from "./config.ts";
import { processPlugins } from "./generate.ts";

// Detect piped input
if (!Deno.isatty(Deno.stdin.rid) && import.meta.main) {
const stdinContent = await streams.readAll(Deno.stdin);
if (!Deno.stdin.isTerminal() && import.meta.main) {
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
try {
const config = JSON.parse(content) as Configuration;
console.log(JSON.stringify(
await processPlugins(config),
(_, v) => v instanceof Uint8Array ? base64.encode(v) : v,
(_, v) => v instanceof Uint8Array ? base64.encodeBase64(v) : v,
));
} catch (e) {
console.error(e);
Expand Down
6 changes: 3 additions & 3 deletions src/run_process_template.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";

import { ProcessTemplateArgs } from "./config.ts";
import { importTemplate } from "./generate.ts";

// Detect piped input
if (!Deno.isatty(Deno.stdin.rid) && import.meta.main) {
const stdinContent = await streams.readAll(Deno.stdin);
if (!Deno.stdin.isTerminal() && import.meta.main) {
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
try {
const args = JSON.parse(content) as ProcessTemplateArgs;
Expand Down
6 changes: 3 additions & 3 deletions src/run_template_info.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as streams from "https://deno.land/std@0.192.0/streams/read_all.ts";
import * as io from "https://deno.land/std@0.213.0/io/read_all.ts";

import { importTemplate } from "./generate.ts";

// Detect piped input
if (!Deno.isatty(Deno.stdin.rid) && import.meta.main) {
const stdinContent = await streams.readAll(Deno.stdin);
if (!Deno.stdin.isTerminal() && import.meta.main) {
const stdinContent = await io.readAll(Deno.stdin);
const content = new TextDecoder().decode(stdinContent);
try {
const module = JSON.parse(content) as string;
Expand Down
15 changes: 8 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import home_dir from "https://deno.land/x/[email protected]/home_dir/mod.ts";
import * as yaml from "https://deno.land/[email protected]/yaml/mod.ts";
import * as log from "https://deno.land/[email protected]/log/mod.ts";
import * as apex from "https://deno.land/x/[email protected]/mod.ts";
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import home_dir from "https://deno.land/x/[email protected]/home_dir/mod.ts";
import * as yaml from "https://deno.land/[email protected]/yaml/mod.ts";
import * as log from "https://deno.land/[email protected]/log/mod.ts";
import * as apex from "https://deno.land/x/[email protected]/mod.ts";
import * as ast from "https://deno.land/x/[email protected]/ast.ts";

import {
Configuration,
Expand Down Expand Up @@ -223,9 +224,9 @@ export function flatten(prefix: string, obj: unknown): unknown {
}
}

export async function readSpec(spec?: string): Promise<apex.ast.Document> {
export async function readSpec(spec?: string): Promise<ast.Document> {
if (!spec) {
return new apex.ast.Document(undefined, []);
return new ast.Document(undefined, []);
}
try {
const apexSource = await Deno.readTextFile(
Expand Down
Loading

0 comments on commit c666c89

Please sign in to comment.