@briine/create-bot 0.0.1 → 0.0.2

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,15 @@ 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
+ 'API_HOST=arena.briine.workers.dev',
17
+ 'USERNAME=your-briine-username',
18
+ '__BOT_ENV_PREFIX___NAME=your-agent-name',
19
+ '__BOT_ENV_PREFIX___VERSION=0.0.1',
20
+ '__BOT_ENV_PREFIX___SECRET=replace-with-agent-secret',
21
+ '',
22
+ ].join('\n');
14
23
 
15
24
  function printUsage() {
16
25
  console.log('Usage: npm create @briine/bot@latest [project-name]');
@@ -105,11 +114,14 @@ async function writeReadme(targetDir, projectName, envPrefix) {
105
114
 
106
115
  async function writeEnvExample(targetDir, envPrefix) {
107
116
  const envExamplePath = path.join(targetDir, '.env.example');
108
- const raw = await readFile(envExamplePath, 'utf8');
109
- const updated = raw.replaceAll('__BOT_ENV_PREFIX__', envPrefix);
117
+ const updated = envExampleTemplate.replaceAll('__BOT_ENV_PREFIX__', envPrefix);
110
118
  await writeFile(envExamplePath, updated);
111
119
  }
112
120
 
121
+ async function writeGitignore(targetDir) {
122
+ await writeFile(path.join(targetDir, '.gitignore'), gitignoreContents);
123
+ }
124
+
113
125
  async function installDependencies(targetDir) {
114
126
  await new Promise((resolve, reject) => {
115
127
  const child = spawn('npm', ['install'], {
@@ -159,12 +171,11 @@ async function main() {
159
171
 
160
172
  await mkdir(targetDir, { recursive: true });
161
173
  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
174
 
165
175
  await writePackageJson(targetDir, projectName);
166
176
  await writeSourceTemplate(targetDir, className, envPrefix);
167
177
  await writeReadme(targetDir, projectName, envPrefix);
178
+ await writeGitignore(targetDir);
168
179
  await writeEnvExample(targetDir, envPrefix);
169
180
 
170
181
  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.2",
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
  );