Skip to content

Commit

Permalink
Merge pull request #48 from fluentci-io/feat/fluentci-config-file
Browse files Browse the repository at this point in the history
feat: add support for `fluentci.toml` config file
  • Loading branch information
tsirysndr authored Jun 13, 2024
2 parents 49348d1 + eaffe02 commit 40a429e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ Requirements:

**Latest (CLI):**

- `Mac`: arm64: [fluentci_v0.14.7_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.7/fluentci_v0.14.7_aarch64-apple-darwin.tar.gz) intel: [fluentci_v0.14.7_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.7/fluentci_v0.14.7_x86_64-apple-darwin.tar.gz)
- `Linux`: intel: [fluentci_v0.14.7_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.7/fluentci_v0.14.7_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci_v0.14.7_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.7/fluentci_v0.14.7_aarch64-unknown-linux-gnu.tar.gz)
- `Mac`: arm64: [fluentci_v0.14.8_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.8/fluentci_v0.14.8_aarch64-apple-darwin.tar.gz) intel: [fluentci_v0.14.8_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.8/fluentci_v0.14.8_x86_64-apple-darwin.tar.gz)
- `Linux`: intel: [fluentci_v0.14.8_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.8/fluentci_v0.14.8_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci_v0.14.8_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci/releases/download/v0.14.8/fluentci_v0.14.8_aarch64-unknown-linux-gnu.tar.gz)

## ✨ Quick Start

Expand All @@ -110,7 +110,7 @@ fluentci studio
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.14.7
Version: 0.14.8

Description:

Expand Down
62 changes: 47 additions & 15 deletions src/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async function init(
if (
await downloadTemplateFromRegistry(template, version, standalone, wasm)
) {
await overrideFluentciToml(infos, standalone ? "." : ".fluentci");
if (wasm) {
await overrideCargoToml(infos, standalone ? "." : ".fluentci");
return;
Expand All @@ -60,6 +61,7 @@ async function init(
version =
version === "latest" ? data.version || data.default_branch : version;
await downloadTemplateFromGithub(data, template, version, standalone, wasm);
await overrideFluentciToml(infos, standalone ? "." : ".fluentci");
if (wasm) {
await overrideCargoToml(infos, standalone ? "." : ".fluentci");
return;
Expand Down Expand Up @@ -336,22 +338,25 @@ async function promptPackageDetails(standalone?: boolean, name?: string) {
}

async function overrideDaggerJson(infos: Record<string, unknown>, path = ".") {
const dagger = await Deno.readFile(`${path}/dagger.json`);
// deno-lint-ignore no-explicit-any
const daggerJson: Record<string, any> = JSON.parse(
new TextDecoder().decode(dagger)
);
for (const key of Object.keys(infos)) {
daggerJson[key] = _.get(infos, key);
}
await Deno.writeFile(
`${path}/dagger.json`,
new TextEncoder().encode(JSON.stringify(daggerJson, null, 2))
);
try {
const dagger = await Deno.readFile(`${path}/dagger.json`);
// deno-lint-ignore no-explicit-any
const daggerJson: Record<string, any> = JSON.parse(
new TextDecoder().decode(dagger)
);
for (const key of Object.keys(infos)) {
daggerJson[key] = _.get(infos, key);
}
await Deno.writeFile(
`${path}/dagger.json`,
new TextEncoder().encode(JSON.stringify(daggerJson, null, 2))
);

if (_.isEqual(path, ".fluentci")) {
await Deno.copyFile(".fluentci/dagger.json", "dagger.json");
}
if (_.isEqual(path, ".fluentci")) {
await Deno.copyFile(".fluentci/dagger.json", "dagger.json");
}
// deno-lint-ignore no-empty no-unused-vars
} catch (e) {}
}

async function overrideCargoToml(infos: Record<string, unknown>, path = ".") {
Expand All @@ -372,4 +377,31 @@ async function overrideCargoToml(infos: Record<string, unknown>, path = ".") {
);
}

async function overrideFluentciToml(
infos: Record<string, unknown>,
path = "."
) {
let config = {};
try {
const fluentciToml = await Deno.readFile(`${path}/fluentci.toml`);
config = toml.parse(new TextDecoder().decode(fluentciToml));
// deno-lint-ignore no-unused-vars no-empty
} catch (e) {}

_.set(config, "package.name", _.get(infos, "name"));
_.set(config, "package.version", _.get(infos, "version").replace("v", ""));
_.set(config, "package.description", _.get(infos, "description"));
_.set(config, "package.license", _.get(infos, "license"));
_.set(config, "package.keywords", _.get(infos, "keywords"));

if (_.get(infos, "author")) {
_.set(config, "package.authors", [_.get(infos, "author")]);
}

await Deno.writeFile(
`${path}/fluentci.toml`,
new TextEncoder().encode(tomlify.toToml(config, { space: 2 }))
);
}

export default init;
3 changes: 1 addition & 2 deletions src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { dir } from "../deps.ts";

export const VERSION = "0.14.7";
export const VERSION = "0.14.8";

export const BASE_URL = "https://api.fluentci.io/v1";

Expand Down

0 comments on commit 40a429e

Please sign in to comment.