create-vapi-app 0.0.0-stage → 0.1.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/LICENSE +198 -0
- package/README.md +63 -2
- package/bin/create-vapi-app.js +4 -0
- package/bin/launch.js +34 -0
- package/dist/index.js +597 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format.
|
|
185
|
+
|
|
186
|
+
Copyright 2025-present Vapi AI
|
|
187
|
+
|
|
188
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
189
|
+
you may not use this file except in compliance with the License.
|
|
190
|
+
You may obtain a copy of the License at
|
|
191
|
+
|
|
192
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
193
|
+
|
|
194
|
+
Unless required by applicable law or agreed to in writing, software
|
|
195
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
196
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
197
|
+
See the License for the specific language governing permissions and
|
|
198
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-vapi-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Creates a private copy of the [Vapi gitops repo](https://github.com/VapiAI/gitops), installs it, and runs its setup wizard to connect your Vapi org. It's like `create-next-app`, for managing Vapi assistants, squads, tools and simulations as code.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-vapi-app@latest my-agents
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Or, with npm's `create` shorthand (the `create-vapi` alias):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create vapi@latest my-agents
|
|
13
|
+
# npm create needs -- before flags:
|
|
14
|
+
npm create vapi@latest my-agents -- --yes
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`npx create-phone-agent@latest` is another alias for the same tool.
|
|
18
|
+
|
|
19
|
+
## What it does
|
|
20
|
+
|
|
21
|
+
1. Checks that Node.js, git and the target folder are ready.
|
|
22
|
+
2. Fetches gitops at the version pinned to this release. By default it keeps gitops' history, with gitops as the `upstream` remote, so later updates are `git fetch upstream && git merge upstream/main`.
|
|
23
|
+
3. Runs `npm ci`.
|
|
24
|
+
4. Hands off to the repo's own `npm run setup`, which asks for your org name, API key and region.
|
|
25
|
+
|
|
26
|
+
If anything fails or you press Ctrl-C before setup starts, the folder is removed. A folder that already existed (and was empty) is kept.
|
|
27
|
+
|
|
28
|
+
Keep your copy private. The gitops README warns against public forks.
|
|
29
|
+
|
|
30
|
+
## Options
|
|
31
|
+
|
|
32
|
+
| Option | What it does |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `[project-name]` | Target folder. Use `.` for the current folder; it must be empty. |
|
|
35
|
+
| `--org <name>` | Org folder name passed to `npm run setup` (for example `my-org`) |
|
|
36
|
+
| `--region us\|eu` | Vapi region for setup. Needs `--org`. |
|
|
37
|
+
| `--resources all\|none` | Download the org's existing resources, or start empty. Needs `--org`. |
|
|
38
|
+
| `--skip-install` | Don't run `npm ci`. This also skips setup, which needs the dev dependencies. |
|
|
39
|
+
| `--skip-setup` | Clone and install only; connect an org later. |
|
|
40
|
+
| `--disable-git` | Create no git repo. |
|
|
41
|
+
| `--clean-history` | Start a fresh git history instead of keeping gitops' upstream history. |
|
|
42
|
+
| `--github` | Create a **private** GitHub repo with the `gh` CLI and push to it. Not available with `--clean-history` or `--disable-git`. |
|
|
43
|
+
| `--ref <sha\|tag\|branch>` | Use a different gitops version. A commit SHA must be the full 40 characters. |
|
|
44
|
+
| `-y, --yes` | Use defaults and never prompt. Setup runs only when `--org` is given and its key is in the environment; otherwise the setup command is printed. |
|
|
45
|
+
|
|
46
|
+
### For agents and CI
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
VAPI_PRIVATE_API_KEY_ACME_DEV=... npx --yes create-vapi-app@latest acme-agents --org acme-dev --resources none --yes
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The API key is never accepted as an argument, because argv ends up in shell history, process listings and agent transcripts. Setup reads it from `VAPI_PRIVATE_API_KEY_<ORG>` (`my-org` becomes `VAPI_PRIVATE_API_KEY_MY_ORG`), then `VAPI_PRIVATE_API_KEY`, or asks for it. Keys are also removed from the environment of `git`, `npm ci` and `gh`. Only setup sees them.
|
|
53
|
+
|
|
54
|
+
## Requirements
|
|
55
|
+
|
|
56
|
+
- Node.js 20.12+, 22.13+ or 23.5+. gitops pins Node 22.
|
|
57
|
+
- git, unless you pass `--disable-git`.
|
|
58
|
+
- macOS or Linux. Windows isn't supported yet.
|
|
59
|
+
|
|
60
|
+
`npm ci` may print node-gyp errors for the optional `speaker` and `mic` packages, which `npm run call` uses for live audio. These errors are harmless: everything else installs.
|
|
61
|
+
|
|
62
|
+
## Usage measurement
|
|
63
|
+
|
|
64
|
+
`npm run setup` is started with `VAPI_GITOPS_RUN_ID=<command>--<random hex>`, for example `create-vapi-app--3f2a…`. gitops sends this run id to the Vapi API in its `x-vapi-client` header, as it does for every run. This lets Vapi count installs that came from this tool. Nothing else is sent: no telemetry, no paths, and no org names beyond what the Vapi API already sees.
|
package/bin/launch.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Shared entry for every bin (create-vapi-app and its aliases). Plain JS with
|
|
2
|
+
// no static imports, so an unsupported Node prints a fix instead of failing
|
|
3
|
+
// to link the bundle. Keep the range in step with "engines" in package.json.
|
|
4
|
+
|
|
5
|
+
function nodeSupported(version) {
|
|
6
|
+
const parts = version.split('.').map(Number);
|
|
7
|
+
const major = parts[0];
|
|
8
|
+
const minor = parts[1];
|
|
9
|
+
if (major === 20) return minor >= 12;
|
|
10
|
+
if (major === 22) return minor >= 13;
|
|
11
|
+
if (major === 23) return minor >= 5;
|
|
12
|
+
return major >= 24;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function launch(cliName) {
|
|
16
|
+
const version = process.versions.node;
|
|
17
|
+
if (!nodeSupported(version)) {
|
|
18
|
+
console.error(
|
|
19
|
+
`${cliName} needs Node.js 20.12+, 22.13+ or 23.5+ (you have ${version}).\n` +
|
|
20
|
+
'The gitops repo pins Node 22 in .nvmrc: install it with your version manager, e.g. `nvm install 22`.',
|
|
21
|
+
);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
import('../dist/index.js')
|
|
26
|
+
.then(({ run }) => run(process.argv.slice(2), { cliName }))
|
|
27
|
+
.then((code) => {
|
|
28
|
+
process.exitCode = code;
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
console.error(`${cliName}: unexpected error: ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
});
|
|
34
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
// src/args.ts
|
|
2
|
+
import { parseArgs } from "util";
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var GITOPS_REPO = "VapiAI/gitops";
|
|
6
|
+
var GITOPS_GIT_URL = `https://github.com/${GITOPS_REPO}.git`;
|
|
7
|
+
var GITOPS_REF = "34cb5a356e41f9e0b8796fcf5b2d52480dc00902";
|
|
8
|
+
var DEFAULT_PROJECT_NAME = "my-vapi-gitops";
|
|
9
|
+
var API_KEYS_URL = "https://dashboard.vapi.ai/org/api-keys";
|
|
10
|
+
var SECRET_FLAG_RE = /^--(token|api-key|apikey|key|vapi-token)(=|$)/i;
|
|
11
|
+
var SLUG_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
12
|
+
var UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
13
|
+
var REF_RE = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,99}$/;
|
|
14
|
+
var HEX_RE = /^[0-9a-f]+$/i;
|
|
15
|
+
var PROJECT_NAME_RE = /^[A-Za-z0-9._-]+$/;
|
|
16
|
+
var IGNORABLE_ENTRIES = [".DS_Store", "Thumbs.db"];
|
|
17
|
+
|
|
18
|
+
// src/args.ts
|
|
19
|
+
var PASTED_KEY_MESSAGE = "That looks like a Vapi API key. Never pass a key as an argument: it ends up in shell history and logs. Export VAPI_PRIVATE_API_KEY_<ORG> instead, or let `npm run setup` ask for it.";
|
|
20
|
+
function error(message) {
|
|
21
|
+
return { kind: "error", message };
|
|
22
|
+
}
|
|
23
|
+
function argsParse(argv) {
|
|
24
|
+
if (argv.some((arg) => SECRET_FLAG_RE.test(arg))) {
|
|
25
|
+
return error(
|
|
26
|
+
"Refusing to read an API key from the command line (it would leak into shell history and logs). Export VAPI_PRIVATE_API_KEY_<ORG> instead."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (argv.some((arg) => UUID_RE.test(arg))) {
|
|
30
|
+
return error(PASTED_KEY_MESSAGE);
|
|
31
|
+
}
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = parseArgs({
|
|
35
|
+
args: argv,
|
|
36
|
+
strict: true,
|
|
37
|
+
allowPositionals: true,
|
|
38
|
+
options: {
|
|
39
|
+
org: { type: "string" },
|
|
40
|
+
region: { type: "string" },
|
|
41
|
+
resources: { type: "string" },
|
|
42
|
+
"skip-install": { type: "boolean", default: false },
|
|
43
|
+
"skip-setup": { type: "boolean", default: false },
|
|
44
|
+
"disable-git": { type: "boolean", default: false },
|
|
45
|
+
"clean-history": { type: "boolean", default: false },
|
|
46
|
+
github: { type: "boolean", default: false },
|
|
47
|
+
ref: { type: "string", default: GITOPS_REF },
|
|
48
|
+
yes: { type: "boolean", short: "y", default: false },
|
|
49
|
+
help: { type: "boolean", short: "h", default: false },
|
|
50
|
+
version: { type: "boolean", short: "v", default: false }
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} catch (caught) {
|
|
54
|
+
return error(caught instanceof Error ? caught.message : String(caught));
|
|
55
|
+
}
|
|
56
|
+
const { values, positionals } = parsed;
|
|
57
|
+
if (values.help) return { kind: "help" };
|
|
58
|
+
if (values.version) return { kind: "version" };
|
|
59
|
+
if (positionals.length > 1) {
|
|
60
|
+
return error("Too many arguments: expected at most one project name.");
|
|
61
|
+
}
|
|
62
|
+
const { org, region, resources, ref } = values;
|
|
63
|
+
if (org !== void 0 && !SLUG_RE.test(org)) {
|
|
64
|
+
return error("Invalid --org: use lowercase letters, digits and hyphens (e.g. my-org).");
|
|
65
|
+
}
|
|
66
|
+
if (region !== void 0 && region !== "us" && region !== "eu") {
|
|
67
|
+
return error('Invalid --region: expected "us" or "eu".');
|
|
68
|
+
}
|
|
69
|
+
if (resources !== void 0 && resources !== "all" && resources !== "none") {
|
|
70
|
+
return error('Invalid --resources: expected "all" or "none".');
|
|
71
|
+
}
|
|
72
|
+
if ((region !== void 0 || resources !== void 0) && org === void 0) {
|
|
73
|
+
return error("--region and --resources need --org, because they configure `npm run setup -- <org>`.");
|
|
74
|
+
}
|
|
75
|
+
if (!REF_RE.test(ref) || ref.includes("..")) {
|
|
76
|
+
return error("Invalid --ref: expected a gitops commit SHA, tag or branch name.");
|
|
77
|
+
}
|
|
78
|
+
if (HEX_RE.test(ref) && ref.length !== 40) {
|
|
79
|
+
return error("Invalid --ref: a commit SHA must be the full 40 characters.");
|
|
80
|
+
}
|
|
81
|
+
if (values.github && (values["clean-history"] || values["disable-git"])) {
|
|
82
|
+
return error("--github needs gitops history, so it cannot be combined with --clean-history or --disable-git.");
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
kind: "run",
|
|
86
|
+
options: {
|
|
87
|
+
projectName: positionals[0],
|
|
88
|
+
org,
|
|
89
|
+
region,
|
|
90
|
+
resources,
|
|
91
|
+
skipInstall: values["skip-install"],
|
|
92
|
+
skipSetup: values["skip-setup"],
|
|
93
|
+
disableGit: values["disable-git"],
|
|
94
|
+
cleanHistory: values["clean-history"],
|
|
95
|
+
github: values.github,
|
|
96
|
+
ref,
|
|
97
|
+
yes: values.yes
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/help.ts
|
|
103
|
+
function helpText(cliName) {
|
|
104
|
+
return `Usage: ${cliName} [project-name] [options]
|
|
105
|
+
|
|
106
|
+
Creates a private copy of the Vapi gitops repo (${GITOPS_REPO}), installs it,
|
|
107
|
+
and runs its setup wizard to connect your Vapi org.
|
|
108
|
+
|
|
109
|
+
Options:
|
|
110
|
+
--org <name> Org folder name passed to \`npm run setup\` (e.g. my-org)
|
|
111
|
+
--region us|eu Vapi region for setup (needs --org)
|
|
112
|
+
--resources all|none Download existing resources, or start empty (needs --org)
|
|
113
|
+
--skip-install Don't run npm ci (also skips setup)
|
|
114
|
+
--skip-setup Clone and install only; connect an org later
|
|
115
|
+
--disable-git No git repo at all
|
|
116
|
+
--clean-history Fresh git history instead of keeping gitops' upstream history
|
|
117
|
+
--github Create a PRIVATE GitHub repo with the gh CLI and push to it
|
|
118
|
+
--ref <sha|tag|branch> gitops version to use (default ${GITOPS_REF.slice(0, 12)}).
|
|
119
|
+
A commit SHA must be the full 40 characters.
|
|
120
|
+
-y, --yes Use defaults and never prompt. Runs setup only when
|
|
121
|
+
--org is given and its API key is in the environment.
|
|
122
|
+
-h, --help Show this help
|
|
123
|
+
-v, --version Show the version
|
|
124
|
+
|
|
125
|
+
The API key is never accepted as an argument. Setup reads it from
|
|
126
|
+
VAPI_PRIVATE_API_KEY_<ORG> (my-org -> VAPI_PRIVATE_API_KEY_MY_ORG) or asks for it.
|
|
127
|
+
|
|
128
|
+
Examples:
|
|
129
|
+
${cliName} my-agents
|
|
130
|
+
VAPI_PRIVATE_API_KEY_ACME_DEV=... ${cliName} acme-agents --org acme-dev --resources none --yes
|
|
131
|
+
|
|
132
|
+
Default project name: ${DEFAULT_PROJECT_NAME}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/projectNameProblem.ts
|
|
137
|
+
import { basename, resolve } from "path";
|
|
138
|
+
function projectNameProblem(name) {
|
|
139
|
+
if (UUID_RE.test(name)) {
|
|
140
|
+
return "That looks like a Vapi API key, not a folder name. Never pass a key as an argument.";
|
|
141
|
+
}
|
|
142
|
+
const folder = basename(resolve(name));
|
|
143
|
+
if (!PROJECT_NAME_RE.test(folder) || folder.startsWith("-")) {
|
|
144
|
+
return "Invalid project name: use letters, digits, dots, hyphens and underscores (e.g. my-agents).";
|
|
145
|
+
}
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/projectNamePrompt.ts
|
|
150
|
+
import { stdin, stdout } from "process";
|
|
151
|
+
import { createInterface } from "readline/promises";
|
|
152
|
+
async function projectNamePrompt({ defaultName, validate }) {
|
|
153
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
154
|
+
const aborter = new AbortController();
|
|
155
|
+
rl.on("SIGINT", () => aborter.abort());
|
|
156
|
+
rl.on("close", () => aborter.abort());
|
|
157
|
+
try {
|
|
158
|
+
for (; ; ) {
|
|
159
|
+
const answer = (await rl.question(`What is your project named? (${defaultName}) `, { signal: aborter.signal })).trim();
|
|
160
|
+
const name = answer || defaultName;
|
|
161
|
+
const problem = validate(name);
|
|
162
|
+
if (!problem) return name;
|
|
163
|
+
stdout.write(`${problem}
|
|
164
|
+
`);
|
|
165
|
+
}
|
|
166
|
+
} catch (caught) {
|
|
167
|
+
if (aborter.signal.aborted) {
|
|
168
|
+
stdout.write("\n");
|
|
169
|
+
return void 0;
|
|
170
|
+
}
|
|
171
|
+
throw caught;
|
|
172
|
+
} finally {
|
|
173
|
+
rl.close();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/scaffold.ts
|
|
178
|
+
import { resolve as resolve2 } from "path";
|
|
179
|
+
|
|
180
|
+
// src/apiKey.ts
|
|
181
|
+
function usable(value) {
|
|
182
|
+
const trimmed = value?.trim();
|
|
183
|
+
return Boolean(trimmed) && !/^your-.*-here$/i.test(trimmed ?? "") && trimmed !== "<your-key>";
|
|
184
|
+
}
|
|
185
|
+
function apiKeyPresence(org, env) {
|
|
186
|
+
const varName = `VAPI_PRIVATE_API_KEY_${org.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`;
|
|
187
|
+
const present = [varName, "VAPI_PRIVATE_API_KEY", "VAPI_TOKEN"].some((name) => usable(env[name]));
|
|
188
|
+
return { present, varName };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/envScrub.ts
|
|
192
|
+
function envScrub(env) {
|
|
193
|
+
return Object.fromEntries(Object.entries(env).filter(([name]) => !/^VAPI_.*(KEY|TOKEN)/i.test(name)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/exec.ts
|
|
197
|
+
import { spawn } from "child_process";
|
|
198
|
+
function exec(command, args, { cwd, env, stdio = "inherit" } = {}) {
|
|
199
|
+
return new Promise((resolvePromise, reject) => {
|
|
200
|
+
const child = spawn(command, args, { cwd, env, stdio: ["inherit", stdio, stdio] });
|
|
201
|
+
child.once("error", reject);
|
|
202
|
+
child.once("close", (code, signal) => {
|
|
203
|
+
resolvePromise(signal ? { code: code ?? 130, signal } : { code: code ?? 1 });
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/githubRepoCreate.ts
|
|
209
|
+
import { basename as basename2 } from "path";
|
|
210
|
+
async function githubRepoCreate(dir, env) {
|
|
211
|
+
const name = basename2(dir);
|
|
212
|
+
process.stdout.write(`
|
|
213
|
+
Creating private GitHub repo ${name} with gh...
|
|
214
|
+
`);
|
|
215
|
+
try {
|
|
216
|
+
const { code } = await exec("gh", ["repo", "create", name, "--private", "--source", dir, "--remote", "origin", "--push"], {
|
|
217
|
+
env
|
|
218
|
+
});
|
|
219
|
+
if (code === 0) {
|
|
220
|
+
process.stdout.write("Pushed. Note gitops' GitHub Actions workflows will run in the new repo.\n");
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
process.stderr.write("Couldn't create the GitHub repo; the next steps show how to push by hand.\n");
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/nextSteps.ts
|
|
230
|
+
function nextSteps({
|
|
231
|
+
displayDir,
|
|
232
|
+
org,
|
|
233
|
+
setup,
|
|
234
|
+
setupCode,
|
|
235
|
+
setupOrgs = [],
|
|
236
|
+
runId,
|
|
237
|
+
keyVarName,
|
|
238
|
+
skipInstall,
|
|
239
|
+
cleanHistory,
|
|
240
|
+
disableGit,
|
|
241
|
+
githubPushed
|
|
242
|
+
}) {
|
|
243
|
+
const orgArg = org ?? (setupOrgs.length === 1 ? setupOrgs[0] : void 0) ?? "<org>";
|
|
244
|
+
const lines = ["Next steps:", "", ` cd ${displayDir}`];
|
|
245
|
+
if (skipInstall) lines.push(" npm ci");
|
|
246
|
+
const setupRan = setup.mode !== "skip" && setupCode === 0;
|
|
247
|
+
const wizardFits = org === void 0 && (setup.mode === "wizard" || setup.mode === "skip" && (setup.reason === "skip-setup" || setup.reason === "skip-install"));
|
|
248
|
+
if (!setupRan && setupOrgs.length > 0) {
|
|
249
|
+
for (const setupOrg of setupOrgs) lines.push(` npm run pull -- ${setupOrg}`);
|
|
250
|
+
} else if (!setupRan) {
|
|
251
|
+
if (wizardFits) {
|
|
252
|
+
lines.push(` VAPI_GITOPS_RUN_ID=${runId} npm run setup`);
|
|
253
|
+
} else {
|
|
254
|
+
lines.push(
|
|
255
|
+
` export ${keyVarName ?? "VAPI_PRIVATE_API_KEY_<ORG>"}=<your private API key from ${API_KEYS_URL}>`,
|
|
256
|
+
` VAPI_GITOPS_RUN_ID=${runId} npm run setup -- ${orgArg}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
} else if (setup.mode === "direct" && !disableGit) {
|
|
260
|
+
lines.push(` git add .vapi-state.${orgArg}.json resources/${orgArg} && git commit -m "Connect ${orgArg}"`);
|
|
261
|
+
}
|
|
262
|
+
lines.push(` npm run apply -- ${orgArg}`);
|
|
263
|
+
if (!disableGit && !githubPushed) {
|
|
264
|
+
lines.push("", "Push it to a PRIVATE repo of your own (never a public fork):", "");
|
|
265
|
+
if (cleanHistory) lines.push(' git add -A && git commit -m "Initial commit from create-vapi-app"');
|
|
266
|
+
lines.push(" git remote add origin <your-private-repo-url>", " git push -u origin main");
|
|
267
|
+
}
|
|
268
|
+
return `${lines.join("\n")}
|
|
269
|
+
`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/nodeVersionSupported.ts
|
|
273
|
+
function nodeVersionSupported(version) {
|
|
274
|
+
const [major = 0, minor = 0] = version.replace(/^v/, "").split(".").map(Number);
|
|
275
|
+
if (major === 20) return minor >= 12;
|
|
276
|
+
if (major === 22) return minor >= 13;
|
|
277
|
+
if (major === 23) return minor >= 5;
|
|
278
|
+
return major >= 24;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/targetDirInspect.ts
|
|
282
|
+
import { readdir, stat } from "fs/promises";
|
|
283
|
+
async function targetDirInspect(dir) {
|
|
284
|
+
let isDirectory;
|
|
285
|
+
try {
|
|
286
|
+
isDirectory = (await stat(dir)).isDirectory();
|
|
287
|
+
} catch {
|
|
288
|
+
return { existed: false, entries: [] };
|
|
289
|
+
}
|
|
290
|
+
if (!isDirectory) {
|
|
291
|
+
return { existed: true, entries: [], problem: `${dir} already exists and is not a folder.` };
|
|
292
|
+
}
|
|
293
|
+
const entries = await readdir(dir);
|
|
294
|
+
if (entries.some((entry) => !IGNORABLE_ENTRIES.includes(entry))) {
|
|
295
|
+
return {
|
|
296
|
+
existed: true,
|
|
297
|
+
entries,
|
|
298
|
+
problem: `${dir} already exists and is not empty. Choose a new project name, or empty that folder.`
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { existed: true, entries };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/toolPresent.ts
|
|
305
|
+
async function toolPresent(command, args) {
|
|
306
|
+
try {
|
|
307
|
+
return (await exec(command, args, { stdio: "ignore" })).code === 0;
|
|
308
|
+
} catch {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/preflight.ts
|
|
314
|
+
async function preflight(dir, projectName, options) {
|
|
315
|
+
if (!nodeVersionSupported(process.versions.node)) {
|
|
316
|
+
throw new Error(`Node.js 20.12+, 22.13+ or 23.5+ is required (you have ${process.versions.node}).`);
|
|
317
|
+
}
|
|
318
|
+
const nameProblem = projectNameProblem(projectName);
|
|
319
|
+
if (nameProblem) throw new Error(nameProblem);
|
|
320
|
+
const usesTarball = options.cleanHistory || options.disableGit;
|
|
321
|
+
if (!options.disableGit && !await toolPresent("git", ["--version"])) {
|
|
322
|
+
throw new Error("git is not installed. Install it (on a Mac: `xcode-select --install`), or pass --disable-git.");
|
|
323
|
+
}
|
|
324
|
+
if (usesTarball && !await toolPresent("tar", ["--version"])) {
|
|
325
|
+
throw new Error("tar is not installed, and --clean-history / --disable-git need it.");
|
|
326
|
+
}
|
|
327
|
+
if (options.github) {
|
|
328
|
+
if (!await toolPresent("gh", ["--version"])) {
|
|
329
|
+
throw new Error("--github needs the GitHub CLI: install it from https://cli.github.com, or drop --github.");
|
|
330
|
+
}
|
|
331
|
+
if (!await toolPresent("gh", ["auth", "status"])) {
|
|
332
|
+
throw new Error("--github needs you signed in to the GitHub CLI: run `gh auth login`, or drop --github.");
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const inspection = await targetDirInspect(dir);
|
|
336
|
+
if (inspection.problem) throw new Error(inspection.problem);
|
|
337
|
+
return inspection;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/repoFetchHistory.ts
|
|
341
|
+
async function repoFetchHistory({ dir, ref, env }) {
|
|
342
|
+
const gitEnv = { ...env, GIT_TERMINAL_PROMPT: "0" };
|
|
343
|
+
const steps = [
|
|
344
|
+
["init", ["-c", "init.defaultBranch=main", "init", "-q", dir]],
|
|
345
|
+
["remote add", ["-C", dir, "remote", "add", "upstream", GITOPS_GIT_URL]],
|
|
346
|
+
["fetch", ["-C", dir, "fetch", "--quiet", "upstream", ref]],
|
|
347
|
+
["checkout", ["-C", dir, "checkout", "-q", "-B", "main", "FETCH_HEAD"]]
|
|
348
|
+
];
|
|
349
|
+
for (const [label, args] of steps) {
|
|
350
|
+
const { code } = await exec("git", args, { env: gitEnv });
|
|
351
|
+
if (code !== 0) throw new Error(`Couldn't get ${GITOPS_REPO} at ${ref} (git ${label} failed).`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/repoFetchTarball.ts
|
|
356
|
+
import { spawn as spawn2 } from "child_process";
|
|
357
|
+
import { mkdir } from "fs/promises";
|
|
358
|
+
import { Readable } from "stream";
|
|
359
|
+
import { pipeline } from "stream/promises";
|
|
360
|
+
async function repoFetchTarball({ dir, ref, env, gitInit, signal }) {
|
|
361
|
+
const url = `https://codeload.github.com/${GITOPS_REPO}/tar.gz/${ref}`;
|
|
362
|
+
const response = await fetch(url, { signal });
|
|
363
|
+
if (!response.ok || !response.body) {
|
|
364
|
+
throw new Error(`Couldn't download ${GITOPS_REPO} at ${ref} (HTTP ${response.status}).`);
|
|
365
|
+
}
|
|
366
|
+
await mkdir(dir, { recursive: true });
|
|
367
|
+
const tar = spawn2("tar", ["-xzf", "-", "--strip-components=1", "-C", dir], {
|
|
368
|
+
env,
|
|
369
|
+
stdio: ["pipe", "inherit", "inherit"]
|
|
370
|
+
});
|
|
371
|
+
const exited = new Promise((resolvePromise, reject) => {
|
|
372
|
+
tar.once("error", reject);
|
|
373
|
+
tar.once("close", (code2) => resolvePromise(code2 ?? 1));
|
|
374
|
+
});
|
|
375
|
+
const body = Readable.fromWeb(response.body);
|
|
376
|
+
const [, code] = await Promise.all([pipeline(body, tar.stdin, { signal }), exited]);
|
|
377
|
+
if (code !== 0) {
|
|
378
|
+
throw new Error(`Couldn't extract ${GITOPS_REPO} (tar exited with ${code}).`);
|
|
379
|
+
}
|
|
380
|
+
if (gitInit) {
|
|
381
|
+
const { code: initCode } = await exec("git", ["-c", "init.defaultBranch=main", "init", "-q", dir], { env });
|
|
382
|
+
if (initCode !== 0) throw new Error("git init failed.");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/rollback.ts
|
|
387
|
+
import { readdir as readdir2, rm } from "fs/promises";
|
|
388
|
+
import { join } from "path";
|
|
389
|
+
async function rollback({ dir, existed, entries }) {
|
|
390
|
+
if (!existed) {
|
|
391
|
+
await rm(dir, { recursive: true, force: true });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
let current;
|
|
395
|
+
try {
|
|
396
|
+
current = await readdir2(dir);
|
|
397
|
+
} catch {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
for (const entry of current) {
|
|
401
|
+
if (!entries.includes(entry)) await rm(join(dir, entry), { recursive: true, force: true });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/runId.ts
|
|
406
|
+
import { randomBytes } from "crypto";
|
|
407
|
+
function runIdBuild(cliName) {
|
|
408
|
+
return `${cliName}--${randomBytes(16).toString("hex")}`;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// src/setupArgsBuild.ts
|
|
412
|
+
function setupArgsBuild({ mode, org, region, resources }) {
|
|
413
|
+
if (mode === "wizard" || org === void 0) return ["run", "setup"];
|
|
414
|
+
return [
|
|
415
|
+
"run",
|
|
416
|
+
"setup",
|
|
417
|
+
"--",
|
|
418
|
+
org,
|
|
419
|
+
...region ? ["--region", region] : [],
|
|
420
|
+
...resources ? ["--resources", resources] : []
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/setupDecide.ts
|
|
425
|
+
function setupDecide({ org, yes, tty, skipInstall, skipSetup, keyPresent }) {
|
|
426
|
+
if (skipSetup) return { mode: "skip", reason: "skip-setup" };
|
|
427
|
+
if (skipInstall) return { mode: "skip", reason: "skip-install" };
|
|
428
|
+
if (org !== void 0) {
|
|
429
|
+
return keyPresent ? { mode: "direct" } : { mode: "skip", reason: "no-key" };
|
|
430
|
+
}
|
|
431
|
+
if (yes) return { mode: "skip", reason: "no-org" };
|
|
432
|
+
return tty ? { mode: "wizard" } : { mode: "skip", reason: "not-interactive" };
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/setupOrgsFind.ts
|
|
436
|
+
import { readdir as readdir3 } from "fs/promises";
|
|
437
|
+
import { join as join2 } from "path";
|
|
438
|
+
async function setupOrgsFind(dir) {
|
|
439
|
+
try {
|
|
440
|
+
const entries = await readdir3(join2(dir, "resources"), { withFileTypes: true });
|
|
441
|
+
return entries.filter((entry) => entry.isDirectory() && SLUG_RE.test(entry.name)).map((entry) => entry.name).sort();
|
|
442
|
+
} catch {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/scaffold.ts
|
|
448
|
+
async function scaffold({ cliName, options, projectName, tty }) {
|
|
449
|
+
const dir = resolve2(projectName);
|
|
450
|
+
let inspection;
|
|
451
|
+
try {
|
|
452
|
+
inspection = await preflight(dir, projectName, options);
|
|
453
|
+
} catch (caught) {
|
|
454
|
+
process.stderr.write(`${cliName}: ${caught instanceof Error ? caught.message : String(caught)}
|
|
455
|
+
`);
|
|
456
|
+
return 1;
|
|
457
|
+
}
|
|
458
|
+
const runId = runIdBuild(cliName);
|
|
459
|
+
const childEnv = envScrub(process.env);
|
|
460
|
+
const aborter = new AbortController();
|
|
461
|
+
let interrupted = false;
|
|
462
|
+
let inSetup = false;
|
|
463
|
+
const onSigint = () => {
|
|
464
|
+
if (inSetup || interrupted) return;
|
|
465
|
+
interrupted = true;
|
|
466
|
+
aborter.abort();
|
|
467
|
+
};
|
|
468
|
+
process.on("SIGINT", onSigint);
|
|
469
|
+
try {
|
|
470
|
+
process.stdout.write(`Creating a Vapi gitops project in ${dir}
|
|
471
|
+
|
|
472
|
+
`);
|
|
473
|
+
try {
|
|
474
|
+
process.stdout.write(`Getting ${GITOPS_REPO} at ${options.ref.slice(0, 12)}...
|
|
475
|
+
`);
|
|
476
|
+
if (options.cleanHistory || options.disableGit) {
|
|
477
|
+
await repoFetchTarball({
|
|
478
|
+
dir,
|
|
479
|
+
ref: options.ref,
|
|
480
|
+
env: childEnv,
|
|
481
|
+
gitInit: !options.disableGit,
|
|
482
|
+
signal: aborter.signal
|
|
483
|
+
});
|
|
484
|
+
} else {
|
|
485
|
+
await repoFetchHistory({ dir, ref: options.ref, env: childEnv });
|
|
486
|
+
}
|
|
487
|
+
if (interrupted) throw new Error("Cancelled.");
|
|
488
|
+
if (!options.skipInstall) {
|
|
489
|
+
process.stdout.write("\nInstalling dependencies with npm ci...\n");
|
|
490
|
+
const { code } = await exec("npm", ["ci", "--no-fund", "--no-audit"], { cwd: dir, env: childEnv });
|
|
491
|
+
if (code !== 0) throw new Error(`npm ci failed (exit code ${code}).`);
|
|
492
|
+
}
|
|
493
|
+
if (interrupted) throw new Error("Cancelled.");
|
|
494
|
+
} catch (caught) {
|
|
495
|
+
await rollback({ dir, existed: inspection.existed, entries: inspection.entries });
|
|
496
|
+
if (interrupted) {
|
|
497
|
+
process.stderr.write(`
|
|
498
|
+
Cancelled. Removed what was created in ${dir}.
|
|
499
|
+
`);
|
|
500
|
+
return 130;
|
|
501
|
+
}
|
|
502
|
+
process.stderr.write(
|
|
503
|
+
`
|
|
504
|
+
${cliName}: ${caught instanceof Error ? caught.message : String(caught)}
|
|
505
|
+
Removed what was created in ${dir}.
|
|
506
|
+
`
|
|
507
|
+
);
|
|
508
|
+
return 1;
|
|
509
|
+
}
|
|
510
|
+
const githubPushed = options.github && await githubRepoCreate(dir, childEnv);
|
|
511
|
+
const key = options.org === void 0 ? void 0 : apiKeyPresence(options.org, process.env);
|
|
512
|
+
const setup = setupDecide({
|
|
513
|
+
org: options.org,
|
|
514
|
+
yes: options.yes,
|
|
515
|
+
tty,
|
|
516
|
+
skipInstall: options.skipInstall,
|
|
517
|
+
skipSetup: options.skipSetup,
|
|
518
|
+
keyPresent: key?.present ?? false
|
|
519
|
+
});
|
|
520
|
+
let setupCode;
|
|
521
|
+
if (setup.mode !== "skip") {
|
|
522
|
+
inSetup = true;
|
|
523
|
+
const args = setupArgsBuild({ mode: setup.mode, org: options.org, region: options.region, resources: options.resources });
|
|
524
|
+
process.stdout.write(`
|
|
525
|
+
Running npm ${args.join(" ")}...
|
|
526
|
+
`);
|
|
527
|
+
try {
|
|
528
|
+
({ code: setupCode } = await exec("npm", args, {
|
|
529
|
+
cwd: dir,
|
|
530
|
+
env: { ...process.env, VAPI_GITOPS_RUN_ID: runId, VAPI_GITOPS_COMMAND: "setup" }
|
|
531
|
+
}));
|
|
532
|
+
} catch (caught) {
|
|
533
|
+
process.stderr.write(`Couldn't start setup: ${caught instanceof Error ? caught.message : String(caught)}
|
|
534
|
+
`);
|
|
535
|
+
setupCode = 1;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
process.stdout.write(
|
|
539
|
+
setupCode === void 0 || setupCode === 0 ? `
|
|
540
|
+
Success! Created ${projectName} at ${dir}
|
|
541
|
+
|
|
542
|
+
` : `
|
|
543
|
+
Created ${projectName} at ${dir}, but setup didn't finish.
|
|
544
|
+
|
|
545
|
+
`
|
|
546
|
+
);
|
|
547
|
+
process.stdout.write(
|
|
548
|
+
nextSteps({
|
|
549
|
+
displayDir: projectName,
|
|
550
|
+
org: options.org,
|
|
551
|
+
setup,
|
|
552
|
+
setupCode,
|
|
553
|
+
setupOrgs: setupCode ? await setupOrgsFind(dir) : [],
|
|
554
|
+
runId,
|
|
555
|
+
keyVarName: key?.varName,
|
|
556
|
+
skipInstall: options.skipInstall,
|
|
557
|
+
cleanHistory: options.cleanHistory,
|
|
558
|
+
disableGit: options.disableGit,
|
|
559
|
+
githubPushed
|
|
560
|
+
})
|
|
561
|
+
);
|
|
562
|
+
return setupCode ?? 0;
|
|
563
|
+
} finally {
|
|
564
|
+
process.off("SIGINT", onSigint);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/run.ts
|
|
569
|
+
async function run(argv, { cliName }) {
|
|
570
|
+
const parsed = argsParse(argv);
|
|
571
|
+
if (parsed.kind === "help") {
|
|
572
|
+
process.stdout.write(helpText(cliName));
|
|
573
|
+
return 0;
|
|
574
|
+
}
|
|
575
|
+
if (parsed.kind === "version") {
|
|
576
|
+
process.stdout.write(`${"0.1.1"}
|
|
577
|
+
`);
|
|
578
|
+
return 0;
|
|
579
|
+
}
|
|
580
|
+
if (parsed.kind === "error") {
|
|
581
|
+
process.stderr.write(`${cliName}: ${parsed.message}
|
|
582
|
+
Run \`${cliName} --help\` for usage.
|
|
583
|
+
`);
|
|
584
|
+
return 1;
|
|
585
|
+
}
|
|
586
|
+
const { options } = parsed;
|
|
587
|
+
const tty = Boolean(process.stdin.isTTY);
|
|
588
|
+
let projectName = options.projectName;
|
|
589
|
+
if (projectName === void 0) {
|
|
590
|
+
projectName = tty && !options.yes ? await projectNamePrompt({ defaultName: DEFAULT_PROJECT_NAME, validate: projectNameProblem }) : DEFAULT_PROJECT_NAME;
|
|
591
|
+
if (projectName === void 0) return 130;
|
|
592
|
+
}
|
|
593
|
+
return scaffold({ cliName, options, projectName, tty });
|
|
594
|
+
}
|
|
595
|
+
export {
|
|
596
|
+
run
|
|
597
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vapi-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Scaffold a private copy of the Vapi gitops repo (VapiAI/gitops) and connect it to your Vapi org.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vapi",
|
|
7
|
+
"gitops",
|
|
8
|
+
"voice-ai",
|
|
9
|
+
"create",
|
|
10
|
+
"scaffold"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/VapiAI/create-vapi-app.git",
|
|
16
|
+
"directory": "packages/create-vapi-app"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/VapiAI/create-vapi-app#readme",
|
|
19
|
+
"bugs": "https://github.com/VapiAI/create-vapi-app/issues",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"create-vapi-app": "bin/create-vapi-app.js"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/index.js",
|
|
26
|
+
"./launch": "./bin/launch.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": "^20.12.0 || ^22.13.0 || >=23.5.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"prepack": "npm run build"
|
|
39
|
+
}
|
|
40
|
+
}
|