jr-auth-cli 1.0.0 → 1.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.
- package/index.js +76 -25
- package/package.json +8 -4
- package/templates/betterauth/auth-client.ts +5 -0
- package/templates/betterauth/route.ts +1 -0
package/index.js
CHANGED
|
@@ -9,12 +9,13 @@ import { fileURLToPath } from 'url';
|
|
|
9
9
|
import { exec } from 'child_process';
|
|
10
10
|
import util from 'util';
|
|
11
11
|
import ora from 'ora';
|
|
12
|
+
import crypto from 'crypto';
|
|
12
13
|
|
|
13
14
|
const execPromise = util.promisify(exec);
|
|
14
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
16
|
const __dirname = path.dirname(__filename);
|
|
16
17
|
|
|
17
|
-
// Inquirer
|
|
18
|
+
// Inquirer Fix for ESM
|
|
18
19
|
const prompt = inquirer.prompt ?? inquirer.default?.prompt ?? inquirer.default;
|
|
19
20
|
|
|
20
21
|
const DEPENDENCIES = {
|
|
@@ -31,11 +32,42 @@ function getPackageManager() {
|
|
|
31
32
|
return 'npm install';
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// 🔥 ENV টেমপ্লেট জেনারেটর
|
|
36
|
+
function getEnvTemplate(provider) {
|
|
37
|
+
if (provider === 'betterauth') {
|
|
38
|
+
const secret = crypto.randomBytes(32).toString('hex');
|
|
39
|
+
return `
|
|
40
|
+
# Better Auth Configuration (Generated by jr-auth)
|
|
41
|
+
BETTER_AUTH_SECRET="${secret}"
|
|
42
|
+
BETTER_AUTH_URL="http://localhost:3000"
|
|
43
|
+
# Add your database connection string below
|
|
44
|
+
DATABASE_URL=""
|
|
45
|
+
# Social Providers (Optional)
|
|
46
|
+
GOOGLE_CLIENT_ID=""
|
|
47
|
+
GOOGLE_CLIENT_SECRET=""
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (provider === 'firebase') {
|
|
52
|
+
return `
|
|
53
|
+
# Firebase Configuration
|
|
54
|
+
NEXT_PUBLIC_FIREBASE_API_KEY=""
|
|
55
|
+
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=""
|
|
56
|
+
NEXT_PUBLIC_FIREBASE_PROJECT_ID=""
|
|
57
|
+
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=""
|
|
58
|
+
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=""
|
|
59
|
+
NEXT_PUBLIC_FIREBASE_APP_ID=""
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
|
|
34
66
|
const program = new Command();
|
|
35
67
|
|
|
36
68
|
program
|
|
37
|
-
.name('
|
|
38
|
-
.description('
|
|
69
|
+
.name('jr-auth')
|
|
70
|
+
.description('Production Ready Auth CLI')
|
|
39
71
|
.version('1.0.0');
|
|
40
72
|
|
|
41
73
|
program
|
|
@@ -54,58 +86,77 @@ program
|
|
|
54
86
|
]);
|
|
55
87
|
|
|
56
88
|
const providerName = answers.provider.toLowerCase().replace(/\s/g, '');
|
|
57
|
-
const spinner = ora('Initializing setup...').start();
|
|
58
|
-
|
|
59
|
-
// সোর্স টেমপ্লেট পাথ
|
|
60
89
|
const templatePath = path.join(__dirname, 'templates', providerName);
|
|
90
|
+
|
|
91
|
+
const spinner = ora('Checking requirements...').start();
|
|
61
92
|
|
|
62
93
|
if (!fs.existsSync(templatePath)) {
|
|
63
|
-
spinner.fail(chalk.red(`Template
|
|
94
|
+
spinner.fail(chalk.red(`Template not found!`));
|
|
64
95
|
return;
|
|
65
96
|
}
|
|
66
97
|
|
|
67
|
-
|
|
98
|
+
// ১. ফাইল কপি করা
|
|
99
|
+
spinner.text = 'Generating boilerplate...';
|
|
68
100
|
|
|
69
|
-
// 🔥 Better Auth এর জন্য স্পেশাল লজিক
|
|
70
101
|
if (providerName === 'betterauth') {
|
|
71
|
-
|
|
72
|
-
// ১. কনফিগারেশন ফাইল (auth.ts) যাবে lib ফোল্ডারে
|
|
102
|
+
// Auth Config -> lib/auth.ts
|
|
73
103
|
const libPath = path.join(process.cwd(), 'lib');
|
|
74
104
|
await fs.ensureDir(libPath);
|
|
75
|
-
await fs.copy(
|
|
76
|
-
path.join(templatePath, 'auth.ts'),
|
|
77
|
-
path.join(libPath, 'auth.ts')
|
|
78
|
-
);
|
|
105
|
+
await fs.copy(path.join(templatePath, 'auth.ts'), path.join(libPath, 'auth.ts'));
|
|
79
106
|
|
|
80
|
-
//
|
|
107
|
+
// API Route -> app/api/auth/[...all]/route.ts
|
|
81
108
|
const apiPath = path.join(process.cwd(), 'app', 'api', 'auth', '[...all]');
|
|
82
|
-
await fs.ensureDir(apiPath);
|
|
83
|
-
|
|
109
|
+
await fs.ensureDir(apiPath);
|
|
110
|
+
await fs.copy(path.join(templatePath, 'route.ts'), path.join(apiPath, 'route.ts'));
|
|
111
|
+
|
|
112
|
+
// Client Helper -> lib/auth-client.ts
|
|
84
113
|
await fs.copy(
|
|
85
|
-
path.join(templatePath, '
|
|
86
|
-
path.join(
|
|
114
|
+
path.join(templatePath, 'auth-client.ts'),
|
|
115
|
+
path.join(libPath, 'auth-client.ts')
|
|
87
116
|
);
|
|
88
117
|
|
|
89
|
-
|
|
118
|
+
// Success Message (Updated)
|
|
119
|
+
spinner.succeed(chalk.green(`Generated: lib/auth.ts, lib/auth-client.ts, api routes`));
|
|
90
120
|
|
|
91
121
|
} else {
|
|
92
|
-
//
|
|
122
|
+
// Firebase / JWT
|
|
93
123
|
const targetPath = path.join(process.cwd(), 'lib', 'auth', providerName);
|
|
94
124
|
await fs.copy(templatePath, targetPath);
|
|
95
|
-
|
|
125
|
+
|
|
126
|
+
spinner.succeed(chalk.green(`Files generated successfully.`));
|
|
96
127
|
}
|
|
97
128
|
|
|
98
|
-
//
|
|
129
|
+
// ২. .env ফাইল সেটআপ
|
|
130
|
+
const envData = getEnvTemplate(providerName);
|
|
131
|
+
if (envData) {
|
|
132
|
+
const envPath = path.join(process.cwd(), '.env.local');
|
|
133
|
+
try {
|
|
134
|
+
if (fs.existsSync(envPath)) {
|
|
135
|
+
await fs.appendFile(envPath, envData);
|
|
136
|
+
console.log(chalk.blue(`ℹ️ Added env variables to existing .env.local`));
|
|
137
|
+
} else {
|
|
138
|
+
await fs.writeFile(envPath, envData);
|
|
139
|
+
console.log(chalk.blue(`ℹ️ Created .env.local file`));
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.log(chalk.yellow('⚠️ Could not create .env file (Permission issue?)'));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ৩. ডিপেন্ডেন্সি ইনস্টল
|
|
99
147
|
const packagesToInstall = DEPENDENCIES[providerName];
|
|
100
148
|
if (packagesToInstall) {
|
|
101
149
|
const installCmd = getPackageManager();
|
|
102
|
-
const installSpinner = ora(`${chalk.yellow('Installing:')} ${packagesToInstall}...`).start();
|
|
150
|
+
const installSpinner = ora(`${chalk.yellow('Installing dependencies:')} ${packagesToInstall}...`).start();
|
|
151
|
+
|
|
103
152
|
await execPromise(`${installCmd} ${packagesToInstall}`);
|
|
153
|
+
|
|
104
154
|
installSpinner.succeed(chalk.green('Dependencies installed!'));
|
|
105
155
|
}
|
|
106
156
|
|
|
107
157
|
console.log('');
|
|
108
158
|
console.log(chalk.bold.cyan('🎉 Setup Complete!'));
|
|
159
|
+
console.log(chalk.yellow('👉 Action Required: Open .env.local and fill in your API keys.'));
|
|
109
160
|
|
|
110
161
|
} catch (err) {
|
|
111
162
|
console.error(chalk.red('\n❌ Error:'), err);
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jr-auth-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "An awesome CLI to setup authentication instantly for your JavaScript/TypeScript projects using NextAuth.js, Firebase Auth, or custom JWT-based solutions.",
|
|
5
|
-
|
|
6
5
|
"main": "index.js",
|
|
7
6
|
"bin": {
|
|
8
7
|
"jr-auth": "./index.js"
|
|
@@ -10,7 +9,13 @@
|
|
|
10
9
|
"scripts": {
|
|
11
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
11
|
},
|
|
13
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"auth",
|
|
14
|
+
"cli",
|
|
15
|
+
"nextjs",
|
|
16
|
+
"better-auth",
|
|
17
|
+
"firebase"
|
|
18
|
+
],
|
|
14
19
|
"author": "MD. JUWEL RANA",
|
|
15
20
|
"license": "ISC",
|
|
16
21
|
"type": "module",
|
|
@@ -25,7 +30,6 @@
|
|
|
25
30
|
"inquirer": "^13.1.0",
|
|
26
31
|
"ora": "^9.0.0"
|
|
27
32
|
},
|
|
28
|
-
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@types/bcryptjs": "^2.4.6",
|
|
31
35
|
"@types/jsonwebtoken": "^9.0.10",
|