strapi-typed-client 2.0.0 → 2.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 +49 -1
- package/dist/cli/commands/generate.d.ts +1 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +10 -25
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts +76 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +400 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/watch.d.ts +1 -0
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +4 -0
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +5 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/file-writer.d.ts +12 -0
- package/dist/cli/utils/file-writer.d.ts.map +1 -1
- package/dist/cli/utils/file-writer.js +21 -0
- package/dist/cli/utils/file-writer.js.map +1 -1
- package/dist/cli/utils/prompt.d.ts +20 -0
- package/dist/cli/utils/prompt.d.ts.map +1 -0
- package/dist/cli/utils/prompt.js +119 -0
- package/dist/cli/utils/prompt.js.map +1 -0
- package/dist/generator/auth-api-generator.d.ts +3 -2
- package/dist/generator/auth-api-generator.d.ts.map +1 -1
- package/dist/generator/auth-api-generator.js +138 -15
- package/dist/generator/auth-api-generator.js.map +1 -1
- package/dist/generator/client-generator.d.ts +3 -1
- package/dist/generator/client-generator.d.ts.map +1 -1
- package/dist/generator/client-generator.js +323 -39
- package/dist/generator/client-generator.js.map +1 -1
- package/dist/generator/index.d.ts +17 -7
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +46 -20
- package/dist/generator/index.js.map +1 -1
- package/dist/next/index.d.ts +1 -0
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +4 -0
- package/dist/next/index.js.map +1 -1
- package/dist/plugin/server/src/index.d.ts +1 -0
- package/dist/plugin/server/src/index.d.ts.map +1 -1
- package/dist/plugin/server/src/services/schema.d.ts +6 -1
- package/dist/plugin/server/src/services/schema.d.ts.map +1 -1
- package/dist/plugin/server/src/services/schema.js +19 -3
- package/dist/plugin/server/src/services/schema.js.map +1 -1
- package/dist/shared/strapi-schema-types.d.ts +8 -0
- package/dist/shared/strapi-schema-types.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/generator/templates/stringify-query.ts +0 -36
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# strapi-typed-client
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/strapi-typed-client) [](https://deepwiki.com/BoxLab-Ltd/strapi-typed-client) [](https://gitmcp.io/BoxLab-Ltd/strapi-typed-client)
|
|
4
|
+
|
|
3
5
|
Automatic TypeScript type generation and a fully typed API client for **Strapi v5**. Install a Strapi plugin, run a single CLI command, and get clean TypeScript interfaces plus a ready-to-use fetch client with full autocomplete.
|
|
4
6
|
|
|
5
7
|
**[Documentation](https://boxlab-ltd.github.io/strapi-typed-client/)**
|
|
@@ -25,7 +27,14 @@ export default {
|
|
|
25
27
|
|
|
26
28
|
### 3. Generate types
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
Scaffold the workflow (adds `strapi:generate` / `strapi:check` scripts to your `package.json`), then generate into your source tree and commit the result:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx strapi-types init
|
|
34
|
+
npm run strapi:generate
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or run the generator directly:
|
|
29
38
|
|
|
30
39
|
```bash
|
|
31
40
|
npx strapi-types generate --url http://localhost:1337 --output ./src/strapi
|
|
@@ -56,6 +65,7 @@ articles[0].category.name // fully typed
|
|
|
56
65
|
- Typed API client — `find`, `findOne`, `create`, `update`, `delete`
|
|
57
66
|
- Built-in upload plugin support — `client.upload.upload/find/findOne/destroy`
|
|
58
67
|
- Typed errors with `isStrapiErrorOf` for discriminated narrowing
|
|
68
|
+
- Session auth (Strapi 5.43+ `jwtManagement: 'refresh'`) — auto-detected, with transparent token refresh
|
|
59
69
|
- Automatic type inference for `populate` — no manual casting
|
|
60
70
|
- Nested populate with unlimited depth
|
|
61
71
|
- Separate Input types for create/update (relations as IDs)
|
|
@@ -66,6 +76,24 @@ articles[0].category.name // fully typed
|
|
|
66
76
|
- Schema hashing — skips regeneration when nothing changed
|
|
67
77
|
- Framework-agnostic — works with any TypeScript project
|
|
68
78
|
|
|
79
|
+
## Session auth (Strapi 5.43+)
|
|
80
|
+
|
|
81
|
+
When your backend runs users-permissions with `jwtManagement: 'refresh'` (short-lived access JWT + rotating refresh token in an httpOnly cookie), the generator detects it automatically and bakes the session flow into the client — no config needed:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const strapi = new StrapiClient({
|
|
85
|
+
baseURL: 'http://localhost:1337',
|
|
86
|
+
credentials: 'include', // let the refresh cookie travel
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
await strapi.auth.login({ identifier, password }) // access token kept in memory
|
|
90
|
+
await strapi.auth.refresh() // bootstrap the session on page load
|
|
91
|
+
await strapi.articles.find() // expired token? refreshed & retried transparently
|
|
92
|
+
await strapi.auth.logout() // revoke the session server-side
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
On a 401 — or a 403 from an anonymous request, which is what Strapi actually answers when a protected route is hit with no credentials (the page-reload bootstrap case) — the client performs a single-flight `POST /api/auth/refresh` and retries the request once; a dead session surfaces the original error. The flow is browser-only (server-side code keeps using API tokens) and steps aside whenever you manage the `Authorization` header yourself. Legacy backends are untouched — the generated client behaves exactly as before. See [Authentication](https://boxlab-ltd.github.io/strapi-typed-client/advanced/authentication) for details.
|
|
96
|
+
|
|
69
97
|
## Requirements
|
|
70
98
|
|
|
71
99
|
- **Strapi v5**
|
|
@@ -84,6 +112,26 @@ Full documentation is available at **[boxlab-ltd.github.io/strapi-typed-client](
|
|
|
84
112
|
- [Plugin Config](https://boxlab-ltd.github.io/strapi-typed-client/advanced/plugin-config) — requireAuth, endpoints, schema hashing
|
|
85
113
|
- [API Reference](https://boxlab-ltd.github.io/strapi-typed-client/reference/api) — full StrapiClient API
|
|
86
114
|
|
|
115
|
+
## Use with AI tools
|
|
116
|
+
|
|
117
|
+
The docs are published in agent-friendly formats so AI coding assistants answer questions about this library accurately:
|
|
118
|
+
|
|
119
|
+
- **llms.txt** — [`/llms.txt`](https://boxlab-ltd.github.io/strapi-typed-client/llms.txt) and [`/llms-full.txt`](https://boxlab-ltd.github.io/strapi-typed-client/llms-full.txt). Add the docs root `https://boxlab-ltd.github.io/strapi-typed-client/` to Cursor (`@Docs`), Continue (`@docs`), or any tool that indexes docs by URL.
|
|
120
|
+
- **context7** — indexed at [`/boxlab-ltd/strapi-typed-client`](https://context7.com/boxlab-ltd/strapi-typed-client); the docs site also embeds the context7 chat widget.
|
|
121
|
+
- **GitMCP** — point any MCP-capable agent at `https://gitmcp.io/BoxLab-Ltd/strapi-typed-client`:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"mcpServers": {
|
|
126
|
+
"strapi-typed-client": {
|
|
127
|
+
"url": "https://gitmcp.io/BoxLab-Ltd/strapi-typed-client"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **DeepWiki** — browse or query the auto-generated wiki at [deepwiki.com/BoxLab-Ltd/strapi-typed-client](https://deepwiki.com/BoxLab-Ltd/strapi-typed-client), or connect its MCP at `https://mcp.deepwiki.com/mcp`.
|
|
134
|
+
|
|
87
135
|
## Issues & Contributing
|
|
88
136
|
|
|
89
137
|
Found a bug or have a feature request? [Open an issue](https://github.com/BoxLab-Ltd/strapi-typed-client/issues) on GitHub.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAYxC,MAAM,WAAW,eAAe;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB;AAID,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC3C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,OAAO,CAAA;CACzB,GAAG,OAAO,CAOV;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC1B,OAAO,EAAE,eAAe,GACzB,OAAO,CAAC,cAAc,CAAC,CAwLzB;AAYD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2D5D"}
|
|
@@ -4,31 +4,9 @@
|
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { createApiClient } from '../utils/api-client.js';
|
|
7
|
-
import { readLocalSchemaHash, readLocalGeneratorVersion, requireOutputDir, } from '../utils/file-writer.js';
|
|
8
|
-
import { Generator } from '../../generator/index.js';
|
|
7
|
+
import { readLocalSchemaHash, readLocalGeneratorVersion, requireOutputDir, isInsideNodeModules, assertOutputDirForFormat, } from '../utils/file-writer.js';
|
|
9
8
|
import { transformSchema } from '../../core/schema-transformer.js';
|
|
10
9
|
import { getGeneratorVersion } from '../../shared/version.js';
|
|
11
|
-
/**
|
|
12
|
-
* Output that lands inside node_modules is ephemeral — a reinstall wipes it,
|
|
13
|
-
* so the types must be regenerated. Used to bar `--format ts` from it and to
|
|
14
|
-
* nudge `--format js` users toward a durable, committable output directory.
|
|
15
|
-
*/
|
|
16
|
-
function isInsideNodeModules(outputDir) {
|
|
17
|
-
return path.resolve(outputDir).split(path.sep).includes('node_modules');
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Shipping raw .ts into node_modules breaks at runtime: Node can't require
|
|
21
|
-
* .ts files and the package.json exports still point at the missing .js.
|
|
22
|
-
* Force consumers to pick a source-tree output instead.
|
|
23
|
-
*/
|
|
24
|
-
function assertOutputDirForFormat(outputDir, format) {
|
|
25
|
-
if (format !== 'ts')
|
|
26
|
-
return;
|
|
27
|
-
if (isInsideNodeModules(outputDir)) {
|
|
28
|
-
throw new Error(`--format ts cannot write into node_modules (${outputDir}). ` +
|
|
29
|
-
`Point --output at your source tree (e.g. ./src/strapi).`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
10
|
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
33
11
|
/**
|
|
34
12
|
* Whether committed output can be reused without regenerating. Requires the
|
|
@@ -120,7 +98,7 @@ export async function generate(options) {
|
|
|
120
98
|
if (!options.silent) {
|
|
121
99
|
console.log(`Fetching schema from ${baseUrl}...`);
|
|
122
100
|
}
|
|
123
|
-
const { schema, endpoints: apiEndpoints, pluginEndpoints, extraTypes, hash, } = await client.getSchema();
|
|
101
|
+
const { schema, endpoints: apiEndpoints, pluginEndpoints, extraTypes, authMode, hash, } = await client.getSchema();
|
|
124
102
|
// Merge API and plugin endpoints for generation
|
|
125
103
|
const endpoints = [...(apiEndpoints || []), ...(pluginEndpoints || [])];
|
|
126
104
|
if (!options.silent) {
|
|
@@ -132,6 +110,9 @@ export async function generate(options) {
|
|
|
132
110
|
if (extraTypes && extraTypes.length > 0) {
|
|
133
111
|
console.log(` Extra types: ${extraTypes.length}`);
|
|
134
112
|
}
|
|
113
|
+
if (authMode === 'refresh') {
|
|
114
|
+
console.log(' Auth mode: refresh (session flow enabled)');
|
|
115
|
+
}
|
|
135
116
|
}
|
|
136
117
|
// Transform JSON schema to ParsedSchema format
|
|
137
118
|
const parsedSchema = transformSchema(schema);
|
|
@@ -139,8 +120,10 @@ export async function generate(options) {
|
|
|
139
120
|
if (!options.silent) {
|
|
140
121
|
console.log('Generating TypeScript types...');
|
|
141
122
|
}
|
|
123
|
+
// lazy: keeps the typescript compiler out of init/check/--help startup
|
|
124
|
+
const { Generator } = await import('../../generator/index.js');
|
|
142
125
|
const generator = new Generator(outputDir);
|
|
143
|
-
await generator.generate(parsedSchema, endpoints, extraTypes, hash, getGeneratorVersion(), format);
|
|
126
|
+
await generator.generate(parsedSchema, endpoints, extraTypes, hash, getGeneratorVersion(), format, options.typecheck ?? true, authMode ?? 'legacy');
|
|
144
127
|
// Track generated files
|
|
145
128
|
const emittedFiles = format === 'ts'
|
|
146
129
|
? ['types.ts', 'client.ts', 'index.ts']
|
|
@@ -187,6 +170,7 @@ export function createGenerateCommand(program) {
|
|
|
187
170
|
.option('-s, --silent', 'Suppress output messages')
|
|
188
171
|
.option('-f, --force', 'Force regeneration even if schema unchanged')
|
|
189
172
|
.option('--format <js|ts>', 'Output format: js (compiled .js + .d.ts, default) or ts (raw .ts for monorepo/source-tree output)', 'js')
|
|
173
|
+
.option('--no-typecheck', 'Write the generated client even if it fails type-checking (escape hatch for strict-only false positives)')
|
|
190
174
|
.action(async (opts) => {
|
|
191
175
|
if (opts.format && opts.format !== 'js' && opts.format !== 'ts') {
|
|
192
176
|
console.error(`Invalid --format value: ${opts.format}. Expected 'js' or 'ts'.`);
|
|
@@ -199,6 +183,7 @@ export function createGenerateCommand(program) {
|
|
|
199
183
|
silent: opts.silent,
|
|
200
184
|
force: opts.force,
|
|
201
185
|
format: opts.format,
|
|
186
|
+
typecheck: opts.typecheck,
|
|
202
187
|
});
|
|
203
188
|
if (!result.success) {
|
|
204
189
|
console.error('Generation failed:', result.error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EACH,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EACH,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAY7D,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,UAAU,CAAC,SAAS,CAAA;AAUvD;;;;;GAKG;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C;YAC1B,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAiC;YAC9C,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;YACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;YACnC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CACP,gBAAgB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CACnD,CAAA;YACL,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init command - scaffolds the committed-codegen workflow: validates the
|
|
3
|
+
* url/output/format choices and writes strapi:generate / strapi:check
|
|
4
|
+
* scripts into the consumer's package.json
|
|
5
|
+
*/
|
|
6
|
+
import type { Command } from 'commander';
|
|
7
|
+
import { type Prompter } from '../utils/prompt.js';
|
|
8
|
+
export interface InitOptions {
|
|
9
|
+
url?: string;
|
|
10
|
+
output?: string;
|
|
11
|
+
format?: string;
|
|
12
|
+
yes?: boolean;
|
|
13
|
+
force?: boolean;
|
|
14
|
+
silent?: boolean;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ScriptConflict {
|
|
18
|
+
name: string;
|
|
19
|
+
current: string;
|
|
20
|
+
proposed: string;
|
|
21
|
+
}
|
|
22
|
+
export interface InitResult {
|
|
23
|
+
success: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
packageJsonPath?: string;
|
|
26
|
+
scriptsAdded: string[];
|
|
27
|
+
scriptsOverwritten: string[];
|
|
28
|
+
scriptsSkipped: string[];
|
|
29
|
+
conflicts: ScriptConflict[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validate a URL destined for a committed script. `new URL` alone accepts
|
|
33
|
+
* scheme-less strings like 'localhost:1337' ('localhost:' parses as the
|
|
34
|
+
* protocol), so the scheme must be checked explicitly.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateStrapiUrl(raw: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize an output path for embedding into a committed script: POSIX
|
|
39
|
+
* separators and a ./ prefix so the script works for every teammate.
|
|
40
|
+
* Absolute paths are relativized against cwd (or rejected when outside it) —
|
|
41
|
+
* a committed absolute path only works on the machine that ran init.
|
|
42
|
+
*/
|
|
43
|
+
export declare function normalizeOutputForScript(output: string, cwd: string): string;
|
|
44
|
+
export interface InitScriptValues {
|
|
45
|
+
output: string;
|
|
46
|
+
format: 'js' | 'ts';
|
|
47
|
+
url?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function buildInitScripts(values: InitScriptValues): Record<string, string>;
|
|
50
|
+
export interface ApplyScriptsResult {
|
|
51
|
+
content: string;
|
|
52
|
+
changed: boolean;
|
|
53
|
+
added: string[];
|
|
54
|
+
overwritten: string[];
|
|
55
|
+
skipped: string[];
|
|
56
|
+
conflicts: ScriptConflict[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add scripts to a package.json string while keeping the file's own dialect
|
|
60
|
+
* (BOM, CRLF, indent, trailing newline) so the resulting diff is only the
|
|
61
|
+
* added lines. Returns the original content untouched when nothing changed,
|
|
62
|
+
* which is what makes re-runs byte-identical.
|
|
63
|
+
*/
|
|
64
|
+
export declare function applyScriptsToPackageJson(raw: string, scripts: Record<string, string>, force: boolean): ApplyScriptsResult;
|
|
65
|
+
/**
|
|
66
|
+
* Scaffold the committed-codegen setup. Never throws and never exits — errors
|
|
67
|
+
* come back in the result (exit codes live in the commander wrapper).
|
|
68
|
+
* `prompter` is injectable for tests; the terminal implementation is only
|
|
69
|
+
* created when prompting will actually happen.
|
|
70
|
+
*/
|
|
71
|
+
export declare function init(options: InitOptions, prompter?: Prompter): Promise<InitResult>;
|
|
72
|
+
/**
|
|
73
|
+
* CLI handler for init command
|
|
74
|
+
*/
|
|
75
|
+
export declare function createInitCommand(program: Command): void;
|
|
76
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAOH,KAAK,QAAQ,EAEhB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,WAAW,WAAW;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB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