@briine/create-bot 0.0.1 → 0.0.3

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/bin/create-bot.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { copyFile, cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
3
+ import { cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import process from 'node:process';
6
6
  import { fileURLToPath } from 'node:url';
@@ -11,6 +11,14 @@ import { stdin as input, stdout as output } from 'node:process';
11
11
  const __filename = fileURLToPath(import.meta.url);
12
12
  const __dirname = path.dirname(__filename);
13
13
  const templateDir = path.resolve(__dirname, '../template');
14
+ const gitignoreContents = 'node_modules\n.env\ndist\n';
15
+ const envExampleTemplate = [
16
+ 'USERNAME=your-briine-username',
17
+ '__BOT_ENV_PREFIX___NAME=your-agent-name',
18
+ '__BOT_ENV_PREFIX___VERSION=0.0.1',
19
+ '__BOT_ENV_PREFIX___SECRET=replace-with-agent-secret',
20
+ '',
21
+ ].join('\n');
14
22
 
15
23
  function printUsage() {
16
24
  console.log('Usage: npm create @briine/bot@latest [project-name]');
@@ -105,11 +113,14 @@ async function writeReadme(targetDir, projectName, envPrefix) {
105
113
 
106
114
  async function writeEnvExample(targetDir, envPrefix) {
107
115
  const envExamplePath = path.join(targetDir, '.env.example');
108
- const raw = await readFile(envExamplePath, 'utf8');
109
- const updated = raw.replaceAll('__BOT_ENV_PREFIX__', envPrefix);
116
+ const updated = envExampleTemplate.replaceAll('__BOT_ENV_PREFIX__', envPrefix);
110
117
  await writeFile(envExamplePath, updated);
111
118
  }
112
119
 
120
+ async function writeGitignore(targetDir) {
121
+ await writeFile(path.join(targetDir, '.gitignore'), gitignoreContents);
122
+ }
123
+
113
124
  async function installDependencies(targetDir) {
114
125
  await new Promise((resolve, reject) => {
115
126
  const child = spawn('npm', ['install'], {
@@ -159,12 +170,11 @@ async function main() {
159
170
 
160
171
  await mkdir(targetDir, { recursive: true });
161
172
  await cp(templateDir, targetDir, { recursive: true });
162
- await copyFile(path.join(templateDir, '.gitignore'), path.join(targetDir, '.gitignore'));
163
- await copyFile(path.join(templateDir, '.env.example'), path.join(targetDir, '.env.example'));
164
173
 
165
174
  await writePackageJson(targetDir, projectName);
166
175
  await writeSourceTemplate(targetDir, className, envPrefix);
167
176
  await writeReadme(targetDir, projectName, envPrefix);
177
+ await writeGitignore(targetDir);
168
178
  await writeEnvExample(targetDir, envPrefix);
169
179
 
170
180
  if (!args.noInstall) {
@@ -34,12 +34,15 @@ test('scaffolds a bot project', async () => {
34
34
  const generatedSource = await readFile(path.join(parentDir, 'my-first-bot/src/index.ts'), 'utf8');
35
35
  const generatedReadme = await readFile(path.join(parentDir, 'my-first-bot/README.md'), 'utf8');
36
36
  const generatedEnv = await readFile(path.join(parentDir, 'my-first-bot/.env.example'), 'utf8');
37
+ const generatedGitignore = await readFile(path.join(parentDir, 'my-first-bot/.gitignore'), 'utf8');
37
38
 
38
39
  assert.equal(generatedPackage.name, 'my-first-bot');
39
40
  assert.match(generatedSource, /class MyFirstBot extends BriineAgent/);
40
41
  assert.match(generatedSource, /process\.env\.MY_FIRST_BOT_NAME!/);
41
42
  assert.match(generatedReadme, /MY_FIRST_BOT_SECRET/);
43
+ assert.match(generatedEnv, /API_HOST=arena\.briine\.workers\.dev/);
42
44
  assert.match(generatedEnv, /MY_FIRST_BOT_VERSION=0\.0\.1/);
45
+ assert.equal(generatedGitignore, 'node_modules\n.env\ndist\n');
43
46
  } finally {
44
47
  await rm(parentDir, { recursive: true, force: true });
45
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@briine/create-bot",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Scaffold a new Briine bot project.",
5
5
  "license": "MIT",
6
6
  "author": "@briine",
@@ -1,4 +1,3 @@
1
- API_HOST=arena.briine.workers.dev
2
1
  USERNAME=your-briine-username
3
2
  __BOT_ENV_PREFIX___NAME=your-agent-name
4
3
  __BOT_ENV_PREFIX___VERSION=0.0.1
@@ -39,5 +39,4 @@ BriineAgent.register(
39
39
  process.env.__BOT_ENV_PREFIX___SECRET!,
40
40
  true,
41
41
  ),
42
- process.env.API_HOST!,
43
42
  );