-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrangler and C3: Move the cli folder of C3 into @cloudflare/cli and m…
…ake Wrangler and C3 depend on it We want to start using @clack/core and C3-like components in Wrangler, so the logical next step is to make these components available to wrangler and C3. ./helpers/cli.ts in C3 is now index.ts in @cloudflare/cli, didn't include openInBrowser,C3_DEFAULTS and WRANGLER_DEFAULTS. ./helpers/colors in C3 is now colors.ts in @cloudflare/cli. ./helpers/interactive.ts in C3 is now interactive.ts in @cloudflare/cli.
- Loading branch information
Showing
38 changed files
with
533 additions
and
268 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@cloudflare/cli": major | ||
"create-cloudflare": patch | ||
"wrangler": patch | ||
--- | ||
|
||
Move helper cli files of C3 into @cloudflare/cli and make Wrangler and C3 depend on it |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Cloudflare CLI | ||
|
||
All things related to rendering the CLI for workers-sdk. |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { space } from ".."; | ||
|
||
describe("cli", () => { | ||
test("test spaces", () => { | ||
expect(space(300)).toHaveLength(300); | ||
}); | ||
}); |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { exit } from "process"; | ||
import { brandColor, dim, gray, white, red, hidden, bgRed } from "./colors"; | ||
|
||
export const shapes = { | ||
diamond: "◇", | ||
dash: "─", | ||
radioInactive: "○", | ||
radioActive: "●", | ||
|
||
bar: "│", | ||
leftT: "├", | ||
rigthT: "┤", | ||
|
||
arrows: { | ||
left: "‹", | ||
right: "›", | ||
}, | ||
|
||
corners: { | ||
tl: "╭", | ||
bl: "╰", | ||
tr: "╮", | ||
br: "╯", | ||
}, | ||
}; | ||
|
||
export const status = { | ||
error: bgRed(` ERROR `), | ||
warning: bgRed(` WARNING `), | ||
info: bgRed(` INFO `), | ||
success: bgRed(` SUCCESS `), | ||
}; | ||
|
||
// Returns a string containing n non-trimmable spaces | ||
// This is useful for places where clack trims lines of output | ||
// but we need leading spaces | ||
export const space = (n = 1) => { | ||
return hidden("\u200A".repeat(n)); | ||
}; | ||
|
||
// Primitive for printing to stdout. Use this instead of | ||
// console.log or printing to stdout directly | ||
export const logRaw = (msg: string) => { | ||
process.stdout.write(`${msg}\n`); | ||
}; | ||
|
||
// A simple stylized log for use within a prompt | ||
export const log = (msg: string) => { | ||
const lines = msg.split("\n").map((ln) => `${gray(shapes.bar)} ${white(ln)}`); | ||
|
||
logRaw(lines.join("\n")); | ||
}; | ||
|
||
export const newline = () => { | ||
log(""); | ||
}; | ||
|
||
// Log a simple status update with a style similar to the clack spinner | ||
export const updateStatus = (msg: string) => { | ||
logRaw(`${gray(shapes.leftT)} ${msg}`); | ||
newline(); | ||
}; | ||
|
||
export const startSection = (heading: string, subheading?: string) => { | ||
logRaw( | ||
`${gray(shapes.corners.tl)} ${brandColor(heading)} ${ | ||
subheading ? dim(subheading) : "" | ||
}` | ||
); | ||
newline(); | ||
}; | ||
|
||
export const endSection = (heading: string, subheading?: string) => { | ||
logRaw( | ||
`${gray(shapes.corners.bl)} ${brandColor(heading)} ${ | ||
subheading ? dim(subheading) : "" | ||
}\n` | ||
); | ||
}; | ||
|
||
export const cancel = (msg: string) => { | ||
newline(); | ||
logRaw(`${gray(shapes.corners.bl)} ${white.bgRed(` X `)} ${dim(msg)}`); | ||
}; | ||
|
||
export const warn = (msg: string) => { | ||
newline(); | ||
logRaw(`${gray(shapes.corners.bl)} ${status.warning} ${dim(msg)}`); | ||
}; | ||
|
||
// Strip the ansi color characters out of the line when calculating | ||
// line length, otherwise the padding will be thrown off | ||
// Used from https://github.com/natemoo-re/clack/blob/main/packages/prompts/src/index.ts | ||
export const stripAnsi = (str: string) => { | ||
const pattern = [ | ||
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", | ||
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", | ||
].join("|"); | ||
const regex = RegExp(pattern, "g"); | ||
|
||
return str.replace(regex, ""); | ||
}; | ||
|
||
export const crash = (msg?: string): never => { | ||
if (msg) { | ||
process.stderr.write(red(msg)); | ||
process.stderr.write("\n"); | ||
} | ||
exit(1); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@cloudflare/cli", | ||
"version": "0.1.0", | ||
"description": "An SDK to build workers-sdk CLIs", | ||
"keywords": [ | ||
"cloudflare", | ||
"workers", | ||
"cloudflare workers", | ||
"cli" | ||
], | ||
"scripts": { | ||
"check:type": "tsc", | ||
"test": "vitest run", | ||
"test:ci": "vitest run" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cloudflare/workers-sdk.git", | ||
"directory": "packages/cli" | ||
}, | ||
"license": "MIT OR Apache-2.0", | ||
"author": "wrangler@cloudflare.com", | ||
"devDependencies": { | ||
"@clack/core": "^0.3.2", | ||
"@clack/prompts": "^0.6.3", | ||
"@cloudflare/eslint-config-worker": "*", | ||
"@cloudflare/workers-tsconfig": "workspace:*", | ||
"@typescript-eslint/eslint-plugin": "^5.55.0", | ||
"@typescript-eslint/parser": "^5.55.0", | ||
"ansi-escapes": "^6.2.0", | ||
"chalk": "^5.2.0", | ||
"esbuild": "^0.17.12", | ||
"log-update": "^5.0.1", | ||
"pnpm": "^8.6.11", | ||
"undici": "5.20.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"root": true, | ||
"extends": "@cloudflare/workers-tsconfig/tsconfig.json", | ||
"include": ["**/*.ts"], | ||
"exclude": ["node_modules"], | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"allowJs": false, | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"outDir": "dist", | ||
"types": ["node"], | ||
"resolveJsonModule": true | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "http://turbo.build/schema.json", | ||
"extends": ["//"], | ||
|
||
"pipeline": { | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ["**/__tests__/**/*.{test,spec}.{ts,js,tsx,jsx}"], | ||
testTimeout: 30000, | ||
setupFiles: "./vite.setup.ts", | ||
}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { vi } from "vitest"; | ||
|
||
vi.mock("log-update"); |
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
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
Oops, something went wrong.