create-nextblock 0.2.2 → 0.2.4

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.
@@ -131,6 +131,9 @@ async function handleCommand(projectDirectory, options) {
131
131
  await ensureEnvExample(projectDir);
132
132
  console.log(chalk.green('.env.example ready.'));
133
133
 
134
+ await ensureSupabaseAssets(projectDir);
135
+ console.log(chalk.green('Supabase migrations ready.'));
136
+
134
137
  if (!yes) {
135
138
  await runSetupWizard(projectDir, projectName);
136
139
  } else {
@@ -194,21 +197,41 @@ async function runSetupWizard(projectDir, projectName) {
194
197
  await execa('npx', ['supabase', 'login'], { stdio: 'inherit', cwd: projectPath });
195
198
 
196
199
  clack.note('Now, please select your NextBlock project in the browser.');
197
- await execa('npx', ['supabase', 'link'], { stdio: 'inherit', cwd: projectPath });
200
+ let linkOutput = '';
201
+ const linkProcess = execa('npx', ['supabase', 'link'], {
202
+ cwd: projectPath,
203
+ stdin: 'inherit',
204
+ stdout: 'pipe',
205
+ stderr: 'inherit',
206
+ });
207
+ if (linkProcess.stdout) {
208
+ linkProcess.stdout.on('data', (chunk) => {
209
+ const text = chunk.toString();
210
+ linkOutput += text;
211
+ process.stdout.write(text);
212
+ });
213
+ }
214
+ await linkProcess;
198
215
 
199
216
  const configTomlPath = resolve(projectPath, 'supabase', 'config.toml');
200
217
  let configToml = '';
201
218
  if (!(await fs.pathExists(configTomlPath))) {
202
- const manualProjectId = await clack.text({
203
- message:
204
- 'supabase/config.toml was not created. Enter your Supabase project ref (from the link output, e.g., abcdefghijklmnopqrstu):',
205
- validate: (val) => (!val ? 'Project ref is required' : undefined),
206
- });
207
- if (clack.isCancel(manualProjectId)) {
208
- handleWizardCancel('Setup cancelled.');
219
+ const parsedRef = linkOutput.match(/Selected project:\s*([a-z0-9-]+)/i)?.[1];
220
+ let projectRef = parsedRef;
221
+
222
+ if (!projectRef) {
223
+ const manualProjectId = await clack.text({
224
+ message:
225
+ 'supabase/config.toml was not created. Enter your Supabase project ref (from the link output, e.g., abcdefghijklmnopqrstu):',
226
+ validate: (val) => (!val ? 'Project ref is required' : undefined),
227
+ });
228
+ if (clack.isCancel(manualProjectId)) {
229
+ handleWizardCancel('Setup cancelled.');
230
+ }
231
+ projectRef = manualProjectId.trim();
209
232
  }
210
- const trimmed = manualProjectId.trim();
211
- configToml = `project_id = "${trimmed}"\n`;
233
+
234
+ configToml = `project_id = "${projectRef}"\n`;
212
235
  await fs.writeFile(configTomlPath, configToml);
213
236
  clack.note('Created supabase/config.toml from the provided project ref.');
214
237
  } else {
@@ -287,7 +310,7 @@ async function runSetupWizard(projectDir, projectName) {
287
310
 
288
311
  if (canWriteEnv) {
289
312
  await fs.writeFile(envPath, envLines.join('\n'));
290
- clack.success('Supabase configuration saved to .env');
313
+ clack.note('Supabase configuration saved to .env');
291
314
  }
292
315
 
293
316
  clack.note('Setting up your database...');
@@ -357,7 +380,7 @@ async function runSetupWizard(projectDir, projectName) {
357
380
 
358
381
  if (canWriteEnv) {
359
382
  await fs.appendFile(envPath, r2Env);
360
- clack.success('Cloudflare R2 configuration saved!');
383
+ clack.note('Cloudflare R2 configuration saved!');
361
384
  } else {
362
385
  clack.note('Add the following R2 values to your existing .env:\n' + r2Env);
363
386
  }
@@ -419,7 +442,7 @@ async function runSetupWizard(projectDir, projectName) {
419
442
 
420
443
  if (canWriteEnv) {
421
444
  await fs.appendFile(envPath, smtpEnv);
422
- clack.success('SMTP configuration saved!');
445
+ clack.note('SMTP configuration saved!');
423
446
  } else {
424
447
  clack.note('Add the following SMTP values to your existing .env:\n' + smtpEnv);
425
448
  }
@@ -605,11 +628,11 @@ async function ensureGitignore(projectDir) {
605
628
  }
606
629
  }
607
630
 
608
- async function ensureEnvExample(projectDir) {
609
- const destination = resolve(projectDir, '.env.example');
610
- if (await fs.pathExists(destination)) {
611
- return;
612
- }
631
+ async function ensureEnvExample(projectDir) {
632
+ const destination = resolve(projectDir, '.env.example');
633
+ if (await fs.pathExists(destination)) {
634
+ return;
635
+ }
613
636
 
614
637
  const templatePaths = [
615
638
  resolve(TEMPLATE_DIR, '.env.example'),
@@ -653,12 +676,35 @@ SMTP_FROM_NAME=
653
676
 
654
677
  await fs.writeFile(destination, placeholder);
655
678
  }
656
-
657
- async function ensureClientComponents(projectDir) {
658
- const relativePaths = [
659
- 'components/env-var-warning.tsx',
660
- 'app/providers.tsx',
661
- 'app/ToasterProvider.tsx',
679
+
680
+ async function ensureSupabaseAssets(projectDir) {
681
+ const sourceSupabaseDir = resolve(REPO_ROOT, 'libs/db/src/supabase');
682
+ const destSupabaseDir = resolve(projectDir, 'supabase');
683
+
684
+ if (!(await fs.pathExists(sourceSupabaseDir))) {
685
+ return;
686
+ }
687
+
688
+ await fs.ensureDir(destSupabaseDir);
689
+
690
+ const sourceConfig = resolve(sourceSupabaseDir, 'config.toml');
691
+ const destConfig = resolve(destSupabaseDir, 'config.toml');
692
+ if (!(await fs.pathExists(destConfig)) && (await fs.pathExists(sourceConfig))) {
693
+ await fs.copy(sourceConfig, destConfig);
694
+ }
695
+
696
+ const sourceMigrations = resolve(sourceSupabaseDir, 'migrations');
697
+ const destMigrations = resolve(destSupabaseDir, 'migrations');
698
+ if (await fs.pathExists(sourceMigrations)) {
699
+ await fs.copy(sourceMigrations, destMigrations, { overwrite: false, errorOnExist: false });
700
+ }
701
+ }
702
+
703
+ async function ensureClientComponents(projectDir) {
704
+ const relativePaths = [
705
+ 'components/env-var-warning.tsx',
706
+ 'app/providers.tsx',
707
+ 'app/ToasterProvider.tsx',
662
708
  'context/AuthContext.tsx',
663
709
  'context/CurrentContentContext.tsx',
664
710
  'context/LanguageContext.tsx',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nextblock",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {