create-foliwake 0.12.0 → 0.12.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ with them. While the version is 0.x, a minor release may break; breaking changes
5
5
 
6
6
  Entries are written from the changesets of each pull request (`.changeset/`, CONTRIBUTING.md), newest first.
7
7
 
8
+ ## 0.12.1
9
+
10
+ ### Patch Changes
11
+
12
+ - 835fd54: `foliwake create` checks the site id before anything is written. A site that a server creates needs an id of at
13
+ most 12 lowercase letters, digits and single inner hyphens, starting with a letter. When the folder name does not
14
+ fit, the folder keeps its name and create suggests an id cut at a hyphen (`foli-test1-site` → `foli-test1`): in a
15
+ terminal it asks you to confirm it or type another; without a terminal it stops before writing any file and names
16
+ the `--site <id>` to pass. `foliwake connect` → "Create a new site" asks for a valid id the same way, and
17
+ `connect --create` and `site create` refuse an invalid id before signing in, with a suggestion. Client and server
18
+ use the same rule.
19
+
20
+ The "Next:" steps that create prints, and the generated README, now say `npm i -g foliwake` and
21
+ `foliwake dev --watch` (the local preview runs the engine in Docker) instead of `npm i -g @foliwake/cli` and an
22
+ engine CLI that is "not public yet". When a folder has no Git commit yet, `connect` says plainly what to run so a
23
+ new site gets its code.
24
+ - @foliwake/block-kit@0.12.1
25
+ - @foliwake/site-check@0.12.1
26
+
8
27
  ## 0.12.0
9
28
 
10
29
  ### Patch Changes
package/README.md CHANGED
@@ -21,7 +21,7 @@ Storybook's packages, Git). Without a terminal, or with `--no-interactive`, it u
21
21
  | --- | --- |
22
22
  | `[folder]` | the new project's folder (default `foliwake-site`; `.` for the current folder) |
23
23
  | `--template minimal\|examples` | `minimal`: one page, one block; `examples`: two pages, three blocks, one with JavaScript |
24
- | `--site <id>` | the site id on your Foliwake server, if you know it (used in the README and local configuration) |
24
+ | `--site <id>` | the site id on your Foliwake server, if you know it (used in the README and local configuration); a site the server creates for you needs at most 12 lowercase letters, digits and single inner hyphens, starting with a letter |
25
25
  | `--react` / `--no-react` | React and ReactDOM vendored in `scripts/vendor/` (shipped with this package; nothing is downloaded) and a React example block |
26
26
  | `--storybook` / `--no-storybook` | Storybook for the blocks; `npm run stories` needs the Foliwake CLI |
27
27
  | `--install` / `--no-install` | install the npm packages (only Storybook has any) with the package manager that ran create |
@@ -53,7 +53,8 @@ tests. Push the repository to GitHub and connect it to your site in the Foliwake
53
53
  preview. For editors, create writes the types of `@foliwake/block-kit` and the JSON Schema of block definitions
54
54
  into `.foliwake/` (git-ignored). The project's `README.md` has the details.
55
55
 
56
- Some features need [the Foliwake CLI](https://docs.foliwake.org/guide/quickstart#install-the-cli), installed from the open repository and run with a local Foliwake server. Without it you do not get a local preview (`foliwake dev`), the local block
56
+ Some features need [the Foliwake CLI](https://docs.foliwake.org/guide/quickstart#install-the-cli):
57
+ `npm i -g foliwake` (its `foliwake dev` runs the engine in Docker). Without it you do not get a local preview (`foliwake dev`), the local block
57
58
  catalog (`/_dev/blocks`), `npm run stories` (Storybook renders the block examples with the CLI), the page checks
58
59
  (`foliwake page check`) or the types of each block's own fields (`.foliwake/types/blocks/`). The branch preview
59
60
  on the platform shows pages and block examples instead.
package/dist/create.js CHANGED
@@ -22,8 +22,8 @@ import { nestedRepositories, pathProblems, resolveDestination, writeProject } fr
22
22
  import { projectFiles } from './files.js';
23
23
  import { INITIAL_BRANCH, enclosingRepository, initAndCommit } from './git.js';
24
24
  import { installPackages, packageManagerOf } from './install.js';
25
- import { CreateCancelled, CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, folderProblem, siteIdProblem, templateProblem, } from './options.js';
26
- import { askExisting, askFolder, askGit, askInstall, askReact, askStorybook, askTemplate, welcome, } from './prompts.js';
25
+ import { CreateCancelled, CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, createdSiteIdProblem, folderProblem, localSiteId, siteIdProblem, suggestSiteId, templateProblem, } from './options.js';
26
+ import { askExisting, askFolder, askGit, askInstall, askReact, askSiteId, askStorybook, askTemplate, welcome, } from './prompts.js';
27
27
  import { writeKitTypes, writeLocalSchema } from './editor-files.js';
28
28
  import { packageVersion, siteCheckVersion } from './starters.js';
29
29
  import { projectProblems } from './validate.js';
@@ -35,13 +35,36 @@ function nearestExisting(target) {
35
35
  return at;
36
36
  }
37
37
  }
38
+ /** A --site that a server could not create, with a valid one to pass instead; null when it fits. */
39
+ function newSiteFlagProblem(site) {
40
+ const problem = createdSiteIdProblem(site);
41
+ return problem && `${problem} Pass --site ${suggestSiteId(site)} (or another valid id).`;
42
+ }
38
43
  function checkRequest(request) {
39
44
  const problem = (request.folder !== undefined ? folderProblem(request.folder) : null) ??
40
45
  (request.template !== undefined ? templateProblem(request.template) : null) ??
41
- (request.site ? siteIdProblem(request.site) : null);
46
+ (request.site ? siteIdProblem(request.site) : null) ??
47
+ (request.site && request.newSite ? newSiteFlagProblem(request.site) : null);
42
48
  if (problem)
43
49
  throw new CreateUsageError(problem);
44
50
  }
51
+ /**
52
+ * The site id of the answers: --site as given; for a new site whose id would be made from a folder name that a
53
+ * server refuses, the id asked for in a terminal, else a refusal that names --site (nothing written yet).
54
+ */
55
+ async function siteIdOf(request, target, ask) {
56
+ if (request.site)
57
+ return request.site;
58
+ const made = localSiteId(null, target);
59
+ const problem = request.newSite ? createdSiteIdProblem(made) : null;
60
+ if (problem === null)
61
+ return null;
62
+ const suggestion = suggestSiteId(path.basename(target));
63
+ if (ask)
64
+ return ask(made, suggestion);
65
+ throw new CreateUsageError(`${problem} The folder name can stay: pass --site ${suggestion} (or another valid id) for the site. ` +
66
+ 'Nothing was written.');
67
+ }
45
68
  /** A path as a shell word (quoted only when needed). */
46
69
  export function shellWord(value) {
47
70
  return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
@@ -58,6 +81,8 @@ async function answer(request, io, interactive) {
58
81
  welcome(prompts);
59
82
  const folder = await ask(request.folder, () => askFolder(prompts), DEFAULT_FOLDER);
60
83
  const { target, state } = await resolveDestination(io.cwd, folder);
84
+ const askId = (rejected, suggestion) => askSiteId(prompts, rejected, suggestion);
85
+ const siteId = await siteIdOf(request, target, interactive ? askId : null);
61
86
  let existing = null;
62
87
  if (state.kind === 'files') {
63
88
  existing = await ask(request.existing, () => askExisting(prompts, folder, state.entries), null);
@@ -65,7 +90,6 @@ async function answer(request, io, interactive) {
65
90
  throw notEmptyProblem(folder, state.entries);
66
91
  }
67
92
  const template = await ask(request.template, () => askTemplate(prompts), DEFAULT_TEMPLATE);
68
- const siteId = request.site ? request.site : null;
69
93
  const react = await ask(request.react, () => askReact(prompts), false);
70
94
  const storybook = await ask(request.storybook, () => askStorybook(prompts), false);
71
95
  const manager = packageManagerOf(io.env);
@@ -217,9 +241,9 @@ export function nextSteps(result) {
217
241
  const steps = ['Next:'];
218
242
  if (result.shown !== '.')
219
243
  steps.push(` cd ${shellWord(result.shown)}`);
220
- steps.push(' npx @foliwake/site-check re-check after every change; the platform runs the same checks', ' Push the repository to GitHub and link this folder to your site with `foliwake connect` ' +
244
+ steps.push(' npx @foliwake/site-check re-check after every change; the platform runs the same checks', ' npm i -g foliwake the Foliwake CLI: local preview, sign-in, sites, keys', ' foliwake dev --watch the local preview at http://127.0.0.1:3000/ (runs the engine in Docker)', ' Push the repository to GitHub and link this folder to your site with `foliwake connect` ' +
221
245
  '(README.md, "Connect to Foliwake"):', " every branch gets a preview with the site's content; " +
222
- "a merge to main goes to the site's preview, then Release in the admin.", ' Server commands (connect, keys, deploy): npm i -g @foliwake/cli', " Local preview and page checks need the Foliwake engine's CLI (not public yet): foliwake dev --watch");
246
+ "a merge to main goes to the site's preview, then Release in the admin.");
223
247
  if (result.answers?.storybook && !result.answers.install)
224
248
  steps.push(' npm install (Storybook; `npm run stories` needs the Foliwake CLI)');
225
249
  return steps;
package/dist/files.js CHANGED
@@ -54,8 +54,8 @@ function localConfig(id) {
54
54
  }
55
55
  /**
56
56
  * The Foliwake CLI the CI workflows run with npx: an exact version, the one of this package (the Foliwake packages
57
- * are released together). It is a field of its own, not a devDependency: `npm run` puts node_modules/.bin first on
58
- * PATH, and that `@foliwake/cli` (server commands only) would shadow the developer's `foliwake` in `npm run dev`.
57
+ * are released together). It is a field of its own, not a devDependency: the project needs no `npm install`
58
+ * (only Storybook adds packages), and `npm run dev` uses the developer's own `foliwake` (`npm i -g foliwake`).
59
59
  */
60
60
  function foliwakeField(cliVersion) {
61
61
  return { cli: cliVersion };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { type CreateIO, type CreateResult, EXIT_CANCELLED, createProject, nextSteps, printResult, runCreate, shellWord, } from './create.js';
2
2
  export { type ProjectFile, projectFiles } from './files.js';
3
- export { type CreateAnswers, type CreateRequest, CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, TEMPLATES, type TemplateName, localSiteId, } from './options.js';
3
+ export { CREATED_SITE_ID_RULE, type CreateAnswers, type CreateRequest, CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, TEMPLATES, type TemplateName, createdSiteIdProblem, localSiteId, suggestSiteId, } from './options.js';
4
4
  export { KIT_TYPES_PATH, LOCAL_SCHEMA_PATH, writeKitTypes, writeLocalSchema } from './editor-files.js';
5
5
  export { projectProblems } from './validate.js';
package/dist/index.js CHANGED
@@ -2,6 +2,6 @@
2
2
  // the same run without printing, for a wrapper that adds its own steps (the Foliwake CLI's `foliwake create`).
3
3
  export { EXIT_CANCELLED, createProject, nextSteps, printResult, runCreate, shellWord, } from './create.js';
4
4
  export { projectFiles } from './files.js';
5
- export { CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, TEMPLATES, localSiteId, } from './options.js';
5
+ export { CREATED_SITE_ID_RULE, CreateUsageError, DEFAULT_FOLDER, DEFAULT_TEMPLATE, TEMPLATES, createdSiteIdProblem, localSiteId, suggestSiteId, } from './options.js';
6
6
  export { KIT_TYPES_PATH, LOCAL_SCHEMA_PATH, writeKitTypes, writeLocalSchema } from './editor-files.js';
7
7
  export { projectProblems } from './validate.js';
package/dist/options.d.ts CHANGED
@@ -10,6 +10,12 @@ export interface CreateRequest {
10
10
  template?: TemplateName | undefined;
11
11
  /** The site id on a Foliwake server; "" means none. */
12
12
  site?: string | undefined;
13
+ /**
14
+ * The site id (given, else made from the folder name) must be one a server can create: `foliwake create`
15
+ * before it offers to create the site. A folder name that does not fit is asked about in a terminal (a valid
16
+ * id suggested) and refused otherwise, before anything is written.
17
+ */
18
+ newSite?: boolean | undefined;
13
19
  git?: boolean | undefined;
14
20
  /** Add Storybook for the blocks (starters/storybook/); asked in a terminal, else no. */
15
21
  storybook?: boolean | undefined;
@@ -40,6 +46,15 @@ export declare class CreateCancelled extends Error {
40
46
  }
41
47
  /** Why a site id is not valid, or null. */
42
48
  export declare function siteIdProblem(value: string): string | null;
49
+ /** The rule of a new site's id, in one line. */
50
+ export declare const CREATED_SITE_ID_RULE = "at most 12 lowercase letters, digits and single inner hyphens, starting with a letter";
51
+ /** Why `value` cannot be the id of a new site on a server, or null. */
52
+ export declare function createdSiteIdProblem(value: string): string | null;
53
+ /**
54
+ * A valid id for a new site, made from a name: lowercase, letters and digits, starting with a letter, cut at
55
+ * a hyphen to at most 12 characters (`foli-test1-site` → `foli-test1`). "site" when nothing is left.
56
+ */
57
+ export declare function suggestSiteId(name: string): string;
43
58
  export declare function templateProblem(value: string): string | null;
44
59
  export declare function folderProblem(value: string): string | null;
45
60
  /** The id of the site in the local configuration: the given site id, else one made from the folder name. */
package/dist/options.js CHANGED
@@ -19,6 +19,41 @@ export function siteIdProblem(value) {
19
19
  ? null
20
20
  : `"${value}" is not a site id: 1–40 lowercase letters, digits and "-", starting with a letter or digit.`;
21
21
  }
22
+ /**
23
+ * The id of a site a Foliwake server creates (`sites.create`): the engine's own rule (CREATED_SITE_ID in its
24
+ * src/core/sites/create-schema.ts). Stricter than SITE_ID: the id must fit `<branch>--<site>--<org>` and name the
25
+ * site's credentials `<SITE>__…`.
26
+ */
27
+ const CREATED_SITE_ID = /^(?=.{1,12}$)[a-z](?:-?[a-z0-9])*$/;
28
+ const CREATED_SITE_ID_MAX = 12;
29
+ /** The rule of a new site's id, in one line. */
30
+ export const CREATED_SITE_ID_RULE = 'at most 12 lowercase letters, digits and single inner hyphens, starting with a letter';
31
+ /** Why `value` cannot be the id of a new site on a server, or null. */
32
+ export function createdSiteIdProblem(value) {
33
+ if (CREATED_SITE_ID.test(value))
34
+ return null;
35
+ return `The site id "${value}" cannot be used for a new site on a server: ${CREATED_SITE_ID_RULE}.`;
36
+ }
37
+ /** The longest run of whole words (joined by "-") that fits the limit; the first word cut when it alone is longer. */
38
+ function wordsWithin(words, max) {
39
+ let kept = words[0].slice(0, max);
40
+ for (const word of words.slice(1)) {
41
+ if (kept.length + 1 + word.length > max)
42
+ break;
43
+ kept = `${kept}-${word}`;
44
+ }
45
+ return kept;
46
+ }
47
+ /**
48
+ * A valid id for a new site, made from a name: lowercase, letters and digits, starting with a letter, cut at
49
+ * a hyphen to at most 12 characters (`foli-test1-site` → `foli-test1`). "site" when nothing is left.
50
+ */
51
+ export function suggestSiteId(name) {
52
+ const words = slug(name, Infinity).replace(/^[^a-z]+/, '').split('-').filter(Boolean);
53
+ if (words.length === 0)
54
+ return 'site';
55
+ return wordsWithin(words, CREATED_SITE_ID_MAX);
56
+ }
22
57
  export function templateProblem(value) {
23
58
  return TEMPLATES.includes(value)
24
59
  ? null
package/dist/prompts.d.ts CHANGED
@@ -6,6 +6,8 @@ export interface PromptStreams {
6
6
  }
7
7
  export declare function welcome(io: PromptStreams): void;
8
8
  export declare function askFolder(io: PromptStreams): Promise<string>;
9
+ /** The folder name cannot be a new site's id: the id to use instead (Enter takes the suggestion). */
10
+ export declare function askSiteId(io: PromptStreams, rejected: string, suggestion: string): Promise<string>;
9
11
  /** The folder has files: cancel, remove them (.git kept) or add next to them. */
10
12
  export declare function askExisting(io: PromptStreams, shown: string, entries: readonly string[]): Promise<ExistingFiles>;
11
13
  export declare function askTemplate(io: PromptStreams): Promise<TemplateName>;
package/dist/prompts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { confirm, intro, isCancel, select, text } from '@clack/prompts';
2
- import { CreateCancelled, DEFAULT_FOLDER, DEFAULT_TEMPLATE, folderProblem, } from './options.js';
2
+ import { CREATED_SITE_ID_RULE, CreateCancelled, DEFAULT_FOLDER, DEFAULT_TEMPLATE, createdSiteIdProblem, folderProblem, } from './options.js';
3
3
  function answered(value) {
4
4
  if (isCancel(value))
5
5
  throw new CreateCancelled();
@@ -18,6 +18,17 @@ export async function askFolder(io) {
18
18
  }));
19
19
  return value === '' ? DEFAULT_FOLDER : value;
20
20
  }
21
+ /** The folder name cannot be a new site's id: the id to use instead (Enter takes the suggestion). */
22
+ export async function askSiteId(io, rejected, suggestion) {
23
+ const value = answered(await text({
24
+ ...io,
25
+ message: `Site id on the server ("${rejected}" does not fit: ${CREATED_SITE_ID_RULE})`,
26
+ placeholder: suggestion,
27
+ defaultValue: suggestion,
28
+ validate: (v) => (v ? (createdSiteIdProblem(v) ?? undefined) : undefined),
29
+ }));
30
+ return value === '' ? suggestion : value;
31
+ }
21
32
  /** The folder has files: cancel, remove them (.git kept) or add next to them. */
22
33
  export async function askExisting(io, shown, entries) {
23
34
  const listed = entries.slice(0, 4).join(', ') + (entries.length > 4 ? ', …' : '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-foliwake",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Create a Foliwake site frontend: npm create foliwake@latest. Blocks, styles, local sample pages, checks and GitHub workflows, checked with @foliwake/site-check before anything is written.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -52,8 +52,8 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@clack/prompts": "1.8.1",
55
- "@foliwake/block-kit": "0.12.0",
56
- "@foliwake/site-check": "0.12.0"
55
+ "@foliwake/block-kit": "0.12.1",
56
+ "@foliwake/site-check": "0.12.1"
57
57
  },
58
58
  "files": [
59
59
  "dist/",
@@ -30,9 +30,9 @@ node --test "tests/*.test.mjs"
30
30
 
31
31
  ### With the Foliwake CLI
32
32
 
33
- The server commands of the Foliwake CLI are open: `npm i -g @foliwake/cli` (sign-in, sites, code, branches, keys).
34
- The local preview and the page checks need the Foliwake engine's `foliwake` (the same command with the engine
35
- added), which is not public yet. Where you have it:
33
+ Install the Foliwake CLI: `npm i -g foliwake` (Node.js 22.22 or later). It has the local preview and the server
34
+ commands (sign-in, sites, code, branches, keys). The local preview runs the Foliwake engine in a container, so it
35
+ needs Docker:
36
36
 
37
37
  ```bash
38
38
  foliwake dev --watch
@@ -110,7 +110,7 @@ The workflows run the open Foliwake CLI with `npx @foliwake/cli@<version>`, outs
110
110
  "foliwake": { "cli": "{{createVersion}}" }
111
111
  ```
112
112
 
113
- Update it there; the workflows refuse anything but an exact version (`1.2.3`, no range). It is deliberately not a `devDependency`: `npm run` puts `node_modules/.bin` first on PATH, and an installed `@foliwake/cli` (server commands only, no local preview) would replace your own `foliwake` in `npm run dev` and `npm run check:pages`. On your machine, install a CLI globally instead: `npm i -g @foliwake/cli` for the server commands (`foliwake account keys create`, `branch update`, …), or the Foliwake CLI described in "Develop" for the local preview and page checks.
113
+ Update it there; the workflows refuse anything but an exact version (`1.2.3`, no range). It is deliberately not a `devDependency`: the project needs no `npm install` (only Storybook adds packages), and `npm run dev` and `npm run check:pages` use your own `foliwake`. On your machine, install the CLI globally instead: `npm i -g foliwake` (see "Develop").
114
114
 
115
115
  To let [Renovate](https://docs.renovatebot.com/) bump the field, add a custom manager to `renovate.json`:
116
116