@wabot-dev/create 0.0.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.
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander'
4
+ import chalk from 'chalk'
5
+ import degit from 'degit'
6
+ import prompts from 'prompts'
7
+ import path from 'path'
8
+ import fs from 'fs/promises'
9
+
10
+ async function createProject(projectName, options) {
11
+ try {
12
+ // Get the absolute path for the project
13
+ const targetDir = path.resolve(process.cwd(), projectName)
14
+
15
+ // Check if directory exists
16
+ try {
17
+ await fs.access(targetDir)
18
+ console.error(chalk.red(`Error: Directory ${projectName} already exists`))
19
+ process.exit(1)
20
+ } catch {
21
+ // Directory doesn't exist, we can proceed
22
+ }
23
+
24
+ // Clone the template repository
25
+ console.log(chalk.blue(`Creating a new Wabot project in ${chalk.green(targetDir)}`))
26
+
27
+ const emitter = degit('wabot-dev/wabot-template', {
28
+ cache: false,
29
+ force: true,
30
+ verbose: true,
31
+ })
32
+
33
+ await emitter.clone(targetDir)
34
+
35
+ // Read the template's package.json
36
+ const packageJsonPath = path.join(targetDir, 'package.json')
37
+ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'))
38
+
39
+ // Update package.json with the new project name
40
+ packageJson.name = projectName
41
+
42
+ // Write the updated package.json
43
+ await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
44
+
45
+ console.log(chalk.green('\nSuccess! 🎉 Created', projectName))
46
+ console.log('\nInside that directory, you can run several commands:')
47
+ console.log(chalk.cyan('\n npm install'))
48
+ console.log(' Install the project dependencies')
49
+ console.log(chalk.cyan('\n npm start'))
50
+ console.log(' Starts the development server')
51
+ console.log('\nWe suggest that you begin by typing:')
52
+ console.log(chalk.cyan(`\n cd ${projectName}`))
53
+ console.log(chalk.cyan(' npm install'))
54
+ console.log(chalk.cyan(' npm start'))
55
+ console.log('\nHappy hacking! 🚀\n')
56
+ } catch (error) {
57
+ console.error(chalk.red('Error:'), error)
58
+ process.exit(1)
59
+ }
60
+ }
61
+
62
+ // Set up the CLI
63
+ program
64
+ .name('create-wabot')
65
+ .description('Create a new Wabot project')
66
+ .argument('[project-directory]', 'project name')
67
+ .action(async (projectDirectory) => {
68
+ let projectName = projectDirectory
69
+
70
+ if (!projectName) {
71
+ const response = await prompts({
72
+ type: 'text',
73
+ name: 'projectName',
74
+ message: 'What is your project named?',
75
+ initial: 'my-wabot-app',
76
+ })
77
+
78
+ if (!response.projectName) {
79
+ console.log(chalk.red('Project name is required'))
80
+ process.exit(1)
81
+ }
82
+
83
+ projectName = response.projectName
84
+ }
85
+
86
+ await createProject(projectName)
87
+ })
88
+
89
+ program.parse()
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@wabot-dev/create",
3
+ "version": "0.0.1",
4
+ "description": "Project creator for Wabot Framework",
5
+ "license": "ISC",
6
+ "author": "",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "bin": {
13
+ "create-wabot": "./bin/create-wabot.mjs"
14
+ },
15
+ "files": [
16
+ "bin"
17
+ ],
18
+ "dependencies": {
19
+ "chalk": "^5.4.1",
20
+ "commander": "^14.0.0",
21
+ "degit": "^2.8.4",
22
+ "prompts": "^2.4.2"
23
+ }
24
+ }