create-nextblock 0.2.20 → 0.2.21
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-nextblock.js +44 -49
- package/package.json +1 -1
package/bin/create-nextblock.js
CHANGED
|
@@ -188,8 +188,9 @@ async function runSetupWizard(projectDir, projectName) {
|
|
|
188
188
|
clack.note('I will now open your browser to log into Supabase.');
|
|
189
189
|
await runSupabaseCli(['login'], { cwd: projectPath });
|
|
190
190
|
|
|
191
|
+
const assetsState = await ensureSupabaseAssets(projectPath, { required: true, resetProjectRef: true });
|
|
191
192
|
clack.note('Now, please select your NextBlock project when prompted.');
|
|
192
|
-
|
|
193
|
+
await runSupabaseCli(['link'], { cwd: projectPath });
|
|
193
194
|
if (process.stdin.isTTY) {
|
|
194
195
|
try {
|
|
195
196
|
process.stdin.setRawMode(false);
|
|
@@ -200,8 +201,7 @@ async function runSetupWizard(projectDir, projectName) {
|
|
|
200
201
|
process.stdin.resume();
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
|
|
204
|
-
let projectId = extractProjectRefFromOutput(linkResult.stdout || '');
|
|
204
|
+
let projectId = await readSupabaseProjectRef(projectPath);
|
|
205
205
|
|
|
206
206
|
if (!projectId && assetsState.projectId) {
|
|
207
207
|
projectId = assetsState.projectId;
|
|
@@ -719,7 +719,7 @@ SMTP_FROM_NAME=
|
|
|
719
719
|
}
|
|
720
720
|
|
|
721
721
|
async function ensureSupabaseAssets(projectDir, options = {}) {
|
|
722
|
-
const { required = false } = options;
|
|
722
|
+
const { required = false, resetProjectRef = false } = options;
|
|
723
723
|
const destSupabaseDir = resolve(projectDir, 'supabase');
|
|
724
724
|
await fs.ensureDir(destSupabaseDir);
|
|
725
725
|
|
|
@@ -759,6 +759,14 @@ async function ensureSupabaseAssets(projectDir, options = {}) {
|
|
|
759
759
|
migrationsCopied = true;
|
|
760
760
|
}
|
|
761
761
|
|
|
762
|
+
if (resetProjectRef) {
|
|
763
|
+
const tempDir = resolve(destSupabaseDir, '.temp');
|
|
764
|
+
const projectRefPath = resolve(tempDir, 'project-ref');
|
|
765
|
+
if (await fs.pathExists(projectRefPath)) {
|
|
766
|
+
await fs.writeFile(projectRefPath, '');
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
762
770
|
if (required) {
|
|
763
771
|
if (!configCopied) {
|
|
764
772
|
throw new Error('Missing supabase/config.toml in the installed @nextblock-cms/db package.');
|
|
@@ -775,7 +783,15 @@ async function resolvePackageSupabaseDir() {
|
|
|
775
783
|
try {
|
|
776
784
|
const pkgPath = require.resolve('@nextblock-cms/db/package.json');
|
|
777
785
|
const pkgDir = dirname(pkgPath);
|
|
778
|
-
const
|
|
786
|
+
const candidateSegments = [
|
|
787
|
+
'supabase',
|
|
788
|
+
'src/supabase',
|
|
789
|
+
'dist/supabase',
|
|
790
|
+
'dist/libs/db/supabase',
|
|
791
|
+
'dist/lib/supabase',
|
|
792
|
+
'lib/supabase',
|
|
793
|
+
];
|
|
794
|
+
const candidates = candidateSegments.map((segment) => resolve(pkgDir, segment));
|
|
779
795
|
for (const candidate of candidates) {
|
|
780
796
|
if (await fs.pathExists(candidate)) {
|
|
781
797
|
return candidate;
|
|
@@ -787,6 +803,27 @@ async function resolvePackageSupabaseDir() {
|
|
|
787
803
|
return null;
|
|
788
804
|
}
|
|
789
805
|
|
|
806
|
+
async function readSupabaseProjectRef(projectDir) {
|
|
807
|
+
const configTomlPath = resolve(projectDir, 'supabase', 'config.toml');
|
|
808
|
+
if (await fs.pathExists(configTomlPath)) {
|
|
809
|
+
const config = await fs.readFile(configTomlPath, 'utf8');
|
|
810
|
+
const configMatch = config.match(/project_id\s*=\s*"([^"]+)"/);
|
|
811
|
+
if (configMatch?.[1] && !configMatch[1].includes('env(')) {
|
|
812
|
+
return configMatch[1];
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const projectRefPath = resolve(projectDir, 'supabase', '.temp', 'project-ref');
|
|
817
|
+
if (await fs.pathExists(projectRefPath)) {
|
|
818
|
+
const value = (await fs.readFile(projectRefPath, 'utf8')).trim();
|
|
819
|
+
if (/^[a-z0-9]{20,}$/i.test(value)) {
|
|
820
|
+
return value;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
|
|
790
827
|
async function ensureClientComponents(projectDir) {
|
|
791
828
|
const relativePaths = [
|
|
792
829
|
'components/env-var-warning.tsx',
|
|
@@ -1282,22 +1319,7 @@ async function runSupabaseCli(args, options = {}) {
|
|
|
1282
1319
|
const child = spawn('npx', ['supabase', ...args], {
|
|
1283
1320
|
cwd,
|
|
1284
1321
|
shell: IS_WINDOWS,
|
|
1285
|
-
stdio:
|
|
1286
|
-
});
|
|
1287
|
-
|
|
1288
|
-
let stdout = '';
|
|
1289
|
-
let stderr = '';
|
|
1290
|
-
|
|
1291
|
-
child.stdout?.on('data', (chunk) => {
|
|
1292
|
-
const text = chunk.toString();
|
|
1293
|
-
stdout += text;
|
|
1294
|
-
process.stdout.write(text);
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
child.stderr?.on('data', (chunk) => {
|
|
1298
|
-
const text = chunk.toString();
|
|
1299
|
-
stderr += text;
|
|
1300
|
-
process.stderr.write(text);
|
|
1322
|
+
stdio: 'inherit',
|
|
1301
1323
|
});
|
|
1302
1324
|
|
|
1303
1325
|
child.on('error', (error) => {
|
|
@@ -1306,7 +1328,7 @@ async function runSupabaseCli(args, options = {}) {
|
|
|
1306
1328
|
|
|
1307
1329
|
child.on('close', (code) => {
|
|
1308
1330
|
if (code === 0) {
|
|
1309
|
-
resolve(
|
|
1331
|
+
resolve();
|
|
1310
1332
|
} else {
|
|
1311
1333
|
reject(new Error(`supabase ${args.join(' ')} exited with code ${code}`));
|
|
1312
1334
|
}
|
|
@@ -1314,33 +1336,6 @@ async function runSupabaseCli(args, options = {}) {
|
|
|
1314
1336
|
});
|
|
1315
1337
|
}
|
|
1316
1338
|
|
|
1317
|
-
function extractProjectRefFromOutput(output) {
|
|
1318
|
-
const sanitized = stripAnsiCodes(output);
|
|
1319
|
-
const regexes = [
|
|
1320
|
-
/project(?:\s+ref(?:erence)?)?\s*[:=]\s*([a-z0-9]{20,})/i,
|
|
1321
|
-
/project_ref\s*[:=]\s*([a-z0-9]{20,})/i,
|
|
1322
|
-
/\(ref:\s*([a-z0-9]{20,})\s*\)/i,
|
|
1323
|
-
];
|
|
1324
|
-
|
|
1325
|
-
for (const regex of regexes) {
|
|
1326
|
-
const match = sanitized.match(regex);
|
|
1327
|
-
if (match?.[1]) {
|
|
1328
|
-
return match[1];
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
const fallback = sanitized.match(/\b[a-z0-9]{20,}\b/gi);
|
|
1333
|
-
if (fallback?.length === 1) {
|
|
1334
|
-
return fallback[0];
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
return null;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
function stripAnsiCodes(input = '') {
|
|
1341
|
-
return input.replace(/\x1b\[[0-9;]*m/g, '').replace(/\u001b\[[0-9;]*[A-Za-z]/g, '');
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
1339
|
function buildNextConfigContent(editorUtilNames) {
|
|
1345
1340
|
const aliasLines = [];
|
|
1346
1341
|
|