Skip to content

Commit 866a2e3

Browse files
committed
fix init command
1 parent a1d40b2 commit 866a2e3

5 files changed

Lines changed: 88 additions & 57 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fluentci studio
110110
fluentci --help
111111

112112
Usage: fluentci [pipeline] [jobs...]
113-
Version: 0.16.6
113+
Version: 0.16.7
114114

115115
Description:
116116

deno.lock

Lines changed: 24 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export {
1414
yellow,
1515
} from "jsr:@std/fmt@0.224.0/colors";
1616
export { z } from "npm:zod@3.22.2";
17-
export { decompress } from "https://deno.land/x/zip@v1.2.5/mod.ts";
17+
export { decompress } from "https://cdn.jsdelivr.net/gh/tsirysndr/deno-zip@7f47a98/mod.ts";
1818
export { existsSync } from "jsr:@std/fs@0.224.0/exists";
1919
export { load } from "jsr:@std/dotenv@0.224.0";
2020
export { Secret } from "jsr:@cliffy/prompt@1.0.0-rc.7/secret";
@@ -53,9 +53,9 @@ export { Buffer };
5353
export { mergeReadableStreams } from "jsr:@std/streams@0.224.0";
5454
export { Cell, Table } from "jsr:@cliffy/table@1.0.0-rc.7";
5555
export {
56-
TerminalSpinner,
5756
SpinnerTypes,
58-
} from "https://deno.land/x/spinners@v1.1.2/mod.ts";
57+
TerminalSpinner,
58+
} from "https://cdn.jsdelivr.net/gh/tsirysndr/spinners@master/mod.ts";
5959
export { readAllSync } from "jsr:@std/io@0.224.0";
6060
export { serve } from "jsr:@std/http@0.224.0/server";
6161
export { createYoga } from "npm:graphql-yoga@5.1.1";
@@ -76,7 +76,7 @@ export {
7676
} from "jsr:@tsirysndr/fluent-circleci@0.3.1";
7777
export { AzurePipeline } from "jsr:@tsirysndr/fluent-az-pipelines@0.3.1";
7878
export { BuildSpec } from "jsr:@tsirysndr/fluent-codepipeline@0.3";
79-
export { ClientError, GraphQLClient, gql } from "npm:graphql-request@6.1.0";
79+
export { ClientError, gql, GraphQLClient } from "npm:graphql-request@6.1.0";
8080
import * as toml from "jsr:@std/toml";
8181
export { toml };
8282
export { assertEquals, assertObjectMatch } from "jsr:@std/assert";

src/cmd/init.ts

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
decompress,
3-
prompt,
4-
Input,
2+
_,
53
brightGreen,
64
Confirm,
7-
TerminalSpinner,
8-
SpinnerTypes,
5+
decompress,
96
green,
10-
_,
7+
Input,
8+
prompt,
9+
SpinnerTypes,
10+
TerminalSpinner,
1111
toml,
1212
} from "../../deps.ts";
1313
import { directoryExists } from "../utils.ts";
@@ -30,7 +30,7 @@ async function init(
3030
standalone,
3131
wasm,
3232
}: { template?: string; standalone?: boolean; wasm?: boolean } = {},
33-
name?: string
33+
name?: string,
3434
) {
3535
const infos = await promptPackageDetails(standalone, name);
3636
let version = extractVersion(template || "base_pipeline");
@@ -40,8 +40,9 @@ async function init(
4040
const data = await result.json();
4141

4242
if (data.version) {
43-
version =
44-
version === "latest" ? data.version || data.default_branch : version;
43+
version = version === "latest"
44+
? data.version || data.default_branch
45+
: version;
4546
if (
4647
await downloadTemplateFromRegistry(template, version, standalone, wasm)
4748
) {
@@ -57,8 +58,9 @@ async function init(
5758
}
5859

5960
if (data.github_url) {
60-
version =
61-
version === "latest" ? data.version || data.default_branch : version;
61+
version = version === "latest"
62+
? data.version || data.default_branch
63+
: version;
6264
await downloadTemplateFromGithub(data, template, version, standalone, wasm);
6365
await overrideFluentciToml(infos, standalone ? "." : ".fluentci");
6466
if (wasm) {
@@ -71,9 +73,11 @@ async function init(
7173
}
7274

7375
console.log(
74-
`Pipeline template ${green('"')}${green(template)}${green(
75-
'"'
76-
)} not found in Fluent CI registry`
76+
`Pipeline template ${green('"')}${green(template)}${
77+
green(
78+
'"',
79+
)
80+
} not found in Fluent CI registry`,
7781
);
7882
Deno.exit(1);
7983
}
@@ -119,9 +123,9 @@ async function download(url: string, template: string) {
119123

120124
terminalSpinner.succeed("Downloaded template");
121125

122-
Deno.writeFile(tempFilePath, new Uint8Array(value));
126+
await Deno.writeFile(tempFilePath, new Uint8Array(value));
123127

124-
await decompress(tempFilePath, ".");
128+
const io = await decompress(tempFilePath, ".", { overwrite: true });
125129

126130
// Cleanup the temp file
127131
await Deno.remove(tempFilePath);
@@ -158,18 +162,21 @@ async function downloadTemplateFromGithub(
158162
template: string,
159163
version: string,
160164
standalone?: boolean,
161-
wasm?: boolean
165+
wasm?: boolean,
162166
) {
163-
const archiveUrl =
164-
data.version && data.version.startsWith("v")
165-
? `${data.github_url.replace(
166-
"https://github.com",
167-
"https://codeload.github.com"
168-
)}/zip/refs/tags/${version}`
169-
: `${data.github_url.replace(
170-
"https://github.com",
171-
"https://api.github.com/repos"
172-
)}/zipball/${version}`;
167+
const archiveUrl = data.version && data.version.startsWith("v")
168+
? `${
169+
data.github_url.replace(
170+
"https://github.com",
171+
"https://codeload.github.com",
172+
)
173+
}/zip/refs/tags/${version}`
174+
: `${
175+
data.github_url.replace(
176+
"https://github.com",
177+
"https://api.github.com/repos",
178+
)
179+
}/zipball/${version}`;
173180

174181
await download(archiveUrl, template);
175182

@@ -209,10 +216,10 @@ async function downloadTemplateFromRegistry(
209216
template: string,
210217
version: string,
211218
standalone?: boolean,
212-
wasm?: boolean
219+
wasm?: boolean,
213220
) {
214221
const status = await fetch(
215-
`https://pkg.fluentci.io/${template}@${version}`
222+
`https://pkg.fluentci.io/${template}@${version}`,
216223
).then((res) => res.status);
217224
if (status === 200) {
218225
await download(`https://pkg.fluentci.io/${template}@${version}`, template);
@@ -257,14 +264,18 @@ async function promptPackageDetails(standalone?: boolean, name?: string) {
257264
console.log(`👋 Welcome to ${brightGreen("Fluent CI")}!\n`);
258265
console.log(`This utility will walk you through creating a new pipeline.`);
259266
console.log(
260-
`It only covers the most common items, and tries to guess sensible defaults.\n`
267+
`It only covers the most common items, and tries to guess sensible defaults.\n`,
261268
);
262269
console.log(
263-
`Use ${brightGreen(
264-
"`fluentci run <pkg>`"
265-
)} to run a published pipeline, or ${brightGreen(
266-
"`fluentci publish`"
267-
)} to publish one.\n`
270+
`Use ${
271+
brightGreen(
272+
"`fluentci run <pkg>`",
273+
)
274+
} to run a published pipeline, or ${
275+
brightGreen(
276+
"`fluentci publish`",
277+
)
278+
} to publish one.\n`,
268279
);
269280
console.log(`See ${brightGreen("`fluentci help`")} for more information.\n`);
270281
console.log(`Press ${brightGreen("CTRL+C")} at any time to quit.\n`);
@@ -305,9 +316,9 @@ async function promptPackageDetails(standalone?: boolean, name?: string) {
305316
]);
306317

307318
console.log(
308-
`\n✨ About to create a new${
309-
standalone ? " reusable " : " "
310-
}pipeline in ${brightGreen(Deno.cwd())}\n`
319+
`\n✨ About to create a new${standalone ? " reusable " : " "}pipeline in ${
320+
brightGreen(Deno.cwd())
321+
}\n`,
311322
);
312323

313324
console.log("📦 Package details:\n");
@@ -341,14 +352,14 @@ async function overrideDaggerJson(infos: Record<string, unknown>, path = ".") {
341352
const dagger = await Deno.readFile(`${path}/dagger.json`);
342353
// deno-lint-ignore no-explicit-any
343354
const daggerJson: Record<string, any> = JSON.parse(
344-
new TextDecoder().decode(dagger)
355+
new TextDecoder().decode(dagger),
345356
);
346357
for (const key of Object.keys(infos)) {
347358
daggerJson[key] = _.get(infos, key);
348359
}
349360
await Deno.writeFile(
350361
`${path}/dagger.json`,
351-
new TextEncoder().encode(JSON.stringify(daggerJson, null, 2))
362+
new TextEncoder().encode(JSON.stringify(daggerJson, null, 2)),
352363
);
353364

354365
if (_.isEqual(path, ".fluentci")) {
@@ -372,13 +383,13 @@ async function overrideCargoToml(infos: Record<string, unknown>, path = ".") {
372383

373384
await Deno.writeFile(
374385
`${path}/Cargo.toml`,
375-
new TextEncoder().encode(toml.stringify(config))
386+
new TextEncoder().encode(toml.stringify(config)),
376387
);
377388
}
378389

379390
async function overrideFluentciToml(
380391
infos: Record<string, unknown>,
381-
path = "."
392+
path = ".",
382393
) {
383394
let config = {};
384395
try {
@@ -399,7 +410,7 @@ async function overrideFluentciToml(
399410

400411
await Deno.writeFile(
401412
`${path}/fluentci.toml`,
402-
new TextEncoder().encode(toml.stringify(config))
413+
new TextEncoder().encode(toml.stringify(config)),
403414
);
404415
}
405416

src/consts.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { dir } from "../deps.ts";
2-
export const VERSION = "0.16.6";
2+
export const VERSION = "0.16.7";
33

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

66
const FLUENTCI_HOST = Deno.env.get("FLUENTCI_HOST") || "vm.fluentci.io";
77

8-
const scheme =
9-
FLUENTCI_HOST.startsWith("localhost") ||
10-
FLUENTCI_HOST.split(":")[0].match(/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)
11-
? "http"
12-
: "https";
8+
const scheme = FLUENTCI_HOST.startsWith("localhost") ||
9+
FLUENTCI_HOST.split(":")[0].match(/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)
10+
? "http"
11+
: "https";
1312

1413
export const FLUENTCI_API_URL = `${scheme}://${FLUENTCI_HOST}`;
1514
export const FLUENTCI_WS_URL = "wss://events.fluentci.io";

0 commit comments

Comments
 (0)