@format.dev/cli 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -20
- package/bin/format.mjs +20 -0
- package/dist/config-Dq7O4e8N.mjs +63 -0
- package/dist/config.d.mts +21 -0
- package/dist/config.mjs +3 -0
- package/dist/draw-random-name-BzvSSVqO.d.mts +4 -0
- package/dist/draw-random-name-Dpt6YmUk.mjs +13 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1539 -0
- package/dist/install-BiDrmMgJ.mjs +1486 -0
- package/dist/lockstep.d.mts +27 -0
- package/dist/lockstep.mjs +30 -0
- package/dist/project-pX62Di_9.mjs +124 -0
- package/dist/random-name.d.mts +2 -0
- package/dist/random-name.mjs +3 -0
- package/dist/scaffold-shared.d.mts +2 -0
- package/dist/scaffold-shared.mjs +3 -0
- package/dist/scaffold.d.mts +191 -0
- package/dist/scaffold.mjs +6 -0
- package/dist/shared-BD62UD5L.d.mts +32 -0
- package/dist/shared-CM3vyUlL.mjs +143 -0
- package/env.d.ts +99 -0
- package/package.json +86 -34
- package/templates/html/documents/welcome/data/alternative.json +3 -0
- package/templates/html/documents/welcome/data/default.json +3 -0
- package/templates/html/documents/welcome/index.html +32 -0
- package/templates/html/documents/welcome/index.ts +4 -0
- package/templates/html/documents/welcome/pages/Close/close.html +9 -0
- package/templates/html/documents/welcome/pages/Cover/cover.html +13 -0
- package/templates/html/documents/welcome/pages/FeatureShowcase/feature-showcase.css +296 -0
- package/templates/html/documents/welcome/pages/FeatureShowcase/feature-showcase.html +296 -0
- package/templates/html/documents/welcome/pages/NextSteps/next-steps.css +107 -0
- package/templates/html/documents/welcome/pages/NextSteps/next-steps.html +398 -0
- package/templates/html/documents/welcome/styles.css +214 -0
- package/templates/html/format.config.json +4 -0
- package/templates/html/package.json +15 -0
- package/templates/html/tsconfig.json +3 -0
- package/templates/react/documents/welcome/components/ButtonLink.tsx +29 -0
- package/templates/react/documents/welcome/data/alternative.json +3 -0
- package/templates/react/documents/welcome/data/default.json +3 -0
- package/templates/react/documents/welcome/data/schema.ts +7 -0
- package/templates/react/documents/welcome/icons/propeller-asterisk.svg +1 -0
- package/templates/react/documents/welcome/index.tsx +59 -0
- package/templates/react/documents/welcome/logos/_logo-base.tsx +9 -0
- package/templates/react/documents/welcome/logos/aws-lambda.tsx +22 -0
- package/templates/react/documents/welcome/logos/bun.tsx +30 -0
- package/templates/react/documents/welcome/logos/cloudflare-workers.tsx +52 -0
- package/templates/react/documents/welcome/logos/css-modules.tsx +54 -0
- package/templates/react/documents/welcome/logos/css-official.tsx +18 -0
- package/templates/react/documents/welcome/logos/deno.tsx +17 -0
- package/templates/react/documents/welcome/logos/linaria.tsx +18 -0
- package/templates/react/documents/welcome/logos/node.tsx +47 -0
- package/templates/react/documents/welcome/logos/panda-css.tsx +18 -0
- package/templates/react/documents/welcome/logos/sass.tsx +12 -0
- package/templates/react/documents/welcome/logos/tailwind.tsx +45 -0
- package/templates/react/documents/welcome/logos/vanilla-extract.tsx +74 -0
- package/templates/react/documents/welcome/logos/vercel.tsx +17 -0
- package/templates/react/documents/welcome/pages/Close/ClosePage.tsx +13 -0
- package/templates/react/documents/welcome/pages/Cover/CoverPage.tsx +17 -0
- package/templates/react/documents/welcome/pages/FeatureShowcase/FeatureShowcasePage.tsx +221 -0
- package/templates/react/documents/welcome/pages/FeatureShowcase/feature-showcase.css +296 -0
- package/templates/react/documents/welcome/pages/FeatureShowcase/mountains.ts +27 -0
- package/templates/react/documents/welcome/pages/NextSteps/NextStepsPage.tsx +146 -0
- package/templates/react/documents/welcome/pages/NextSteps/next-steps.css +107 -0
- package/templates/react/documents/welcome/styles.css +214 -0
- package/templates/react/documents/welcome/types.ts +4 -0
- package/templates/react/format.config.json +4 -0
- package/templates/react/package.json +22 -0
- package/templates/react/tsconfig.json +6 -0
- package/templates/shared/README.md +18 -0
- package/templates/shared/_env +1 -0
- package/templates/shared/_gitignore +3 -0
- package/templates/shared/documents/welcome/assets/deploy.svg +268 -0
- package/templates/shared/documents/welcome/assets/logo.svg +22 -0
- package/templates/shared/documents/welcome/assets/mona-sans.woff2 +0 -0
- package/templates/shared/documents/welcome/assets/styling.svg +59 -0
- package/templates/vue/documents/welcome/components/ButtonLink.vue +28 -0
- package/templates/vue/documents/welcome/data/alternative.json +3 -0
- package/templates/vue/documents/welcome/data/default.json +3 -0
- package/templates/vue/documents/welcome/data/schema.ts +7 -0
- package/templates/vue/documents/welcome/index.vue +48 -0
- package/templates/vue/documents/welcome/logos/aws-lambda.vue +18 -0
- package/templates/vue/documents/welcome/logos/bun.vue +26 -0
- package/templates/vue/documents/welcome/logos/cloudflare-workers.vue +48 -0
- package/templates/vue/documents/welcome/logos/css-modules.vue +49 -0
- package/templates/vue/documents/welcome/logos/css-official.vue +14 -0
- package/templates/vue/documents/welcome/logos/deno.vue +13 -0
- package/templates/vue/documents/welcome/logos/linaria.vue +14 -0
- package/templates/vue/documents/welcome/logos/node.vue +43 -0
- package/templates/vue/documents/welcome/logos/panda-css.vue +14 -0
- package/templates/vue/documents/welcome/logos/sass.vue +8 -0
- package/templates/vue/documents/welcome/logos/tailwind.vue +41 -0
- package/templates/vue/documents/welcome/logos/vanilla-extract.vue +70 -0
- package/templates/vue/documents/welcome/logos/vercel.vue +13 -0
- package/templates/vue/documents/welcome/pages/Close/ClosePage.vue +11 -0
- package/templates/vue/documents/welcome/pages/Cover/CoverPage.vue +19 -0
- package/templates/vue/documents/welcome/pages/FeatureShowcase/FeatureShowcasePage.vue +217 -0
- package/templates/vue/documents/welcome/pages/FeatureShowcase/feature-showcase.css +296 -0
- package/templates/vue/documents/welcome/pages/FeatureShowcase/mountains.ts +27 -0
- package/templates/vue/documents/welcome/pages/NextSteps/NextStepsPage.vue +146 -0
- package/templates/vue/documents/welcome/pages/NextSteps/next-steps.css +107 -0
- package/templates/vue/documents/welcome/styles.css +214 -0
- package/templates/vue/documents/welcome/types.ts +4 -0
- package/templates/vue/format.config.json +4 -0
- package/templates/vue/package.json +19 -0
- package/templates/vue/tsconfig.json +7 -0
- package/tsconfig.recommended.json +22 -0
- package/index.d.ts +0 -2
- package/index.js +0 -3
package/README.md
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
# @format.dev/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This CLI exposes the `format` binary: the front door to Format. Install this package to scaffold projects, compile documents, and run the Studio dev server.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
package: it contains no implementation, and installing it gets you an empty
|
|
7
|
-
module.
|
|
5
|
+
There are two key advantages to using the Format CLI.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
1. It pins all Format packages to a single version defined in your `format.config.json` and provides an interface to update or migrate to different versions in one command.
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
package that already exists. Creating these names ahead of the first release is
|
|
13
|
-
what lets every real release go out through a reviewed, credential-free
|
|
14
|
-
workflow rather than through a token somebody holds.
|
|
9
|
+
2. It runs `@format.dev/studio` and `@format.dev/compile` as transient dependencies that are run in memory when called on. For you this means less dependencies need to be installed at CI if they're not strictly needed.
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## Install
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install @format.dev/cli --save-dev
|
|
15
|
+
```
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
so `latest` points at this placeholder until Format reaches general
|
|
22
|
-
availability. That is why the deprecation warning is there.
|
|
17
|
+
## Commands
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
| Command | What it does |
|
|
20
|
+
| --------------------- | -------------------------------------------------------------------- |
|
|
21
|
+
| `format dev` | Start the Format Studio dev server |
|
|
22
|
+
| `format compile` | Compile documents into standalone renderers |
|
|
23
|
+
| `format new project` | Creates a completely fresh Format setup. Recommended for fresh repos |
|
|
24
|
+
| `format init` | Boostraps Format into an existing repo |
|
|
25
|
+
| `format new document` | Scaffolds a new document |
|
|
26
|
+
| `format update` | Updates to the latest Format version |
|
|
27
|
+
| `format version` | Prints the current Format version you're using |
|
|
26
28
|
|
|
27
|
-
##
|
|
29
|
+
## Documentation
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
- https://github.com/format-hq/format-js
|
|
31
|
+
The [docs](https://format.dev/docs/cli/overview) for the CLI.
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
## The lockstep model
|
|
34
|
+
|
|
35
|
+
All public Format packages release in lockstep. The `version` field in `format.config.json` pins which release your project uses, and `format update` is the most consistent way to move it up or down.
|
|
36
|
+
|
|
37
|
+
Format doesn't use the peer dependency model to enforce the dependency between our packages. It's all driven from this CLI.
|
|
38
|
+
|
|
39
|
+
## Config
|
|
40
|
+
|
|
41
|
+
`format.config.json` is JSON. It holds your version and project settings. The `$schema` URL at `format.dev/schema/format-config.json` gives you editor autocomplete. [Docs](https://format.dev/docs/studio/configuration).
|
package/bin/format.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Committed launcher for the `format` bin. pnpm only creates a bin shim when
|
|
3
|
+
// the target file exists at install time, and a fresh checkout (CI) installs
|
|
4
|
+
// before dist/ is built — pointing `bin` straight at dist/index.mjs means no
|
|
5
|
+
// shim is ever created there. This file always exists, so the shim always
|
|
6
|
+
// links; it defers to the built CLI at run time.
|
|
7
|
+
const distEntry = new URL('../dist/index.mjs', import.meta.url)
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
await import(distEntry.href)
|
|
11
|
+
} catch (error) {
|
|
12
|
+
const isMissingDist = error?.code === 'ERR_MODULE_NOT_FOUND' && error.message.includes('dist/index.mjs')
|
|
13
|
+
|
|
14
|
+
if (!isMissingDist) {
|
|
15
|
+
throw error
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
console.error('@format.dev/cli is not built (dist/ is missing). Run `pnpm build` from the repo root, then re-run.')
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
5
|
+
|
|
6
|
+
//#region src/errors.ts
|
|
7
|
+
var CliError = class extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "CliError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/config.ts
|
|
16
|
+
const DEFAULT_CONFIG_BASE_NAME = "format.config";
|
|
17
|
+
const CONFIG_EXTENSIONS = ["json", "jsonc"];
|
|
18
|
+
function findConfigPath(startDir, options) {
|
|
19
|
+
const baseName = options?.baseName ?? DEFAULT_CONFIG_BASE_NAME;
|
|
20
|
+
const names = CONFIG_EXTENSIONS.map((extension) => `${baseName}.${extension}`);
|
|
21
|
+
let dir = resolve(startDir);
|
|
22
|
+
for (;;) {
|
|
23
|
+
for (const name of names) {
|
|
24
|
+
const candidate = join(dir, name);
|
|
25
|
+
if (existsSync(candidate)) return candidate;
|
|
26
|
+
}
|
|
27
|
+
const parent = dirname(dir);
|
|
28
|
+
if (parent === dir) return null;
|
|
29
|
+
dir = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function readConfigFile(filepath) {
|
|
33
|
+
const raw = await fs.readFile(filepath, "utf8");
|
|
34
|
+
const errors = [];
|
|
35
|
+
const config = parse(raw, errors, { allowTrailingComma: true });
|
|
36
|
+
if (errors.length > 0) throw new CliError(`Could not parse ${filepath}: ${errors.map((error) => {
|
|
37
|
+
const line = raw.slice(0, error.offset).split("\n").length;
|
|
38
|
+
return `${printParseErrorCode(error.error)} at line ${line}`;
|
|
39
|
+
}).join(", ")}`);
|
|
40
|
+
if (typeof config !== "object" || config === null || Array.isArray(config)) throw new CliError(`Invalid Format config in ${filepath}: expected a JSON object.`);
|
|
41
|
+
return {
|
|
42
|
+
filepath,
|
|
43
|
+
config,
|
|
44
|
+
raw
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async function writeConfigVersion(args) {
|
|
48
|
+
const { filepath, version } = args;
|
|
49
|
+
const raw = await fs.readFile(filepath, "utf8");
|
|
50
|
+
const indent = detectIndent(raw);
|
|
51
|
+
const edits = modify(raw, ["version"], version, { formattingOptions: {
|
|
52
|
+
insertSpaces: !indent.includes(" "),
|
|
53
|
+
tabSize: indent.includes(" ") ? 4 : indent.length
|
|
54
|
+
} });
|
|
55
|
+
await fs.writeFile(filepath, applyEdits(raw, edits), "utf8");
|
|
56
|
+
}
|
|
57
|
+
function detectIndent(raw) {
|
|
58
|
+
const match = raw.match(/^[ \t]+/m);
|
|
59
|
+
return match ? match[0] : " ";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { readConfigFile as a, findConfigPath as i, DEFAULT_CONFIG_BASE_NAME as n, writeConfigVersion as o, detectIndent as r, CliError as s, CONFIG_EXTENSIONS as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
declare const DEFAULT_CONFIG_BASE_NAME = "format.config";
|
|
3
|
+
declare const CONFIG_EXTENSIONS: string[];
|
|
4
|
+
interface FormatConfigFile {
|
|
5
|
+
filepath: string;
|
|
6
|
+
config: Record<string, unknown>;
|
|
7
|
+
raw: string;
|
|
8
|
+
}
|
|
9
|
+
interface FindConfigPathOptions {
|
|
10
|
+
baseName?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function findConfigPath(startDir: string, options?: FindConfigPathOptions): string | null;
|
|
13
|
+
declare function readConfigFile(filepath: string): Promise<FormatConfigFile>;
|
|
14
|
+
interface WriteConfigVersionArgs {
|
|
15
|
+
filepath: string;
|
|
16
|
+
version: string;
|
|
17
|
+
}
|
|
18
|
+
declare function writeConfigVersion(args: WriteConfigVersionArgs): Promise<void>;
|
|
19
|
+
declare function detectIndent(raw: string): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CONFIG_EXTENSIONS, DEFAULT_CONFIG_BASE_NAME, FormatConfigFile, detectIndent, findConfigPath, readConfigFile, writeConfigVersion };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as readConfigFile, i as findConfigPath, n as DEFAULT_CONFIG_BASE_NAME, o as writeConfigVersion, r as detectIndent, t as CONFIG_EXTENSIONS } from "./config-Dq7O4e8N.mjs";
|
|
2
|
+
|
|
3
|
+
export { CONFIG_EXTENSIONS, DEFAULT_CONFIG_BASE_NAME, detectIndent, findConfigPath, readConfigFile, writeConfigVersion };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { animals, colors, uniqueNamesGenerator } from "unique-names-generator";
|
|
2
|
+
|
|
3
|
+
//#region src/scaffold/document/draw-random-name.ts
|
|
4
|
+
function drawRandomName() {
|
|
5
|
+
return uniqueNamesGenerator({
|
|
6
|
+
dictionaries: [colors, animals],
|
|
7
|
+
separator: "-",
|
|
8
|
+
style: "lowerCase"
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { drawRandomName as t };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|