@sidgaikwad/db-setup 1.0.0 → 1.2.0
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/dist/index.js +161 -154
- package/dist/providers/supabase.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23867,7 +23867,165 @@ ${databaseUrl}
|
|
|
23867
23867
|
};
|
|
23868
23868
|
|
|
23869
23869
|
// src/providers/supabase.ts
|
|
23870
|
-
import { spawnSync as
|
|
23870
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
23871
|
+
|
|
23872
|
+
// src/utils/db-utils.ts
|
|
23873
|
+
var genAlphanumericPassword = (length = 24) => {
|
|
23874
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
23875
|
+
let result = "";
|
|
23876
|
+
for (let i = 0;i < length; i++) {
|
|
23877
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
23878
|
+
}
|
|
23879
|
+
return result;
|
|
23880
|
+
};
|
|
23881
|
+
var genRandomIdentifier = (length = 10) => {
|
|
23882
|
+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
23883
|
+
let result = "";
|
|
23884
|
+
for (let i = 0;i < length; i++) {
|
|
23885
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
23886
|
+
}
|
|
23887
|
+
return result;
|
|
23888
|
+
};
|
|
23889
|
+
|
|
23890
|
+
// src/providers/supabase.ts
|
|
23891
|
+
var checkSupabaseAuth = () => {
|
|
23892
|
+
process.stdout.write(source_default.blueBright(`
|
|
23893
|
+
Checking Supabase authentication... `));
|
|
23894
|
+
const authCheckResult = spawnSync2("npx", ["supabase", "orgs", "list"], {
|
|
23895
|
+
encoding: "utf-8",
|
|
23896
|
+
shell: true,
|
|
23897
|
+
stdio: "pipe"
|
|
23898
|
+
});
|
|
23899
|
+
if (authCheckResult.status !== 0) {
|
|
23900
|
+
console.log(source_default.yellowBright("not logged in"));
|
|
23901
|
+
console.log(source_default.blueBright(`
|
|
23902
|
+
⏳ Launching Supabase login...`));
|
|
23903
|
+
console.log(source_default.gray(`Please complete authentication in your browser.
|
|
23904
|
+
`));
|
|
23905
|
+
spawnSync2("npx", ["supabase", "login"], { stdio: "inherit", shell: true });
|
|
23906
|
+
console.log(source_default.greenBright(`
|
|
23907
|
+
✅ Authentication completed!`));
|
|
23908
|
+
return false;
|
|
23909
|
+
}
|
|
23910
|
+
console.log(source_default.greenBright("✓"));
|
|
23911
|
+
return true;
|
|
23912
|
+
};
|
|
23913
|
+
var getOrCreateSupabaseOrg = async () => {
|
|
23914
|
+
const orgListResult = spawnSync2("npx", ["supabase", "orgs", "list"], {
|
|
23915
|
+
encoding: "utf-8",
|
|
23916
|
+
shell: true
|
|
23917
|
+
});
|
|
23918
|
+
if (orgListResult.status !== 0) {
|
|
23919
|
+
console.error(source_default.red("❌ Failed to list Supabase orgs."));
|
|
23920
|
+
process.exit(1);
|
|
23921
|
+
}
|
|
23922
|
+
const lines2 = orgListResult.stdout.split(`
|
|
23923
|
+
`).map((l) => l.trim()).filter(Boolean);
|
|
23924
|
+
const sepIdx = lines2.findIndex((line) => line.includes("|") && line.includes("-"));
|
|
23925
|
+
if (lines2.length <= sepIdx + 1) {
|
|
23926
|
+
console.log(source_default.yellowBright("No Supabase organizations found."));
|
|
23927
|
+
const createOrg = await esm_default2({
|
|
23928
|
+
message: source_default.cyan("Would you like to create a new Supabase organization now?"),
|
|
23929
|
+
default: true
|
|
23930
|
+
});
|
|
23931
|
+
if (!createOrg) {
|
|
23932
|
+
console.log(source_default.red("❌ Cannot continue without a Supabase organization. Exiting."));
|
|
23933
|
+
process.exit(1);
|
|
23934
|
+
}
|
|
23935
|
+
const orgName = await esm_default3({
|
|
23936
|
+
message: source_default.cyan("Enter a name for your new Supabase organization:"),
|
|
23937
|
+
validate: (inputValue) => {
|
|
23938
|
+
if (!inputValue || inputValue.length < 3) {
|
|
23939
|
+
return "Organization name must be at least 3 characters";
|
|
23940
|
+
}
|
|
23941
|
+
return true;
|
|
23942
|
+
}
|
|
23943
|
+
});
|
|
23944
|
+
console.log(source_default.blueBright(`
|
|
23945
|
+
Creating Supabase organization '${orgName}'...`));
|
|
23946
|
+
const createOrgResult = spawnSync2("npx", ["supabase", "orgs", "create", orgName], {
|
|
23947
|
+
stdio: "inherit",
|
|
23948
|
+
encoding: "utf-8",
|
|
23949
|
+
shell: true
|
|
23950
|
+
});
|
|
23951
|
+
if (createOrgResult.status !== 0) {
|
|
23952
|
+
console.error(source_default.red("❌ Failed to create Supabase organization."));
|
|
23953
|
+
process.exit(1);
|
|
23954
|
+
}
|
|
23955
|
+
}
|
|
23956
|
+
};
|
|
23957
|
+
var createSupabaseProject = async (projectName, dbPassword) => {
|
|
23958
|
+
console.log(source_default.blueBright(`
|
|
23959
|
+
Creating Supabase project '${projectName}'...`));
|
|
23960
|
+
const createResult = spawnSync2("npx", [
|
|
23961
|
+
"supabase",
|
|
23962
|
+
"projects",
|
|
23963
|
+
"create",
|
|
23964
|
+
projectName,
|
|
23965
|
+
"--db-password",
|
|
23966
|
+
dbPassword
|
|
23967
|
+
], { stdio: "inherit", encoding: "utf-8", shell: true });
|
|
23968
|
+
if (createResult.status !== 0) {
|
|
23969
|
+
console.error(source_default.red("❌ Failed to create Supabase project."));
|
|
23970
|
+
process.exit(1);
|
|
23971
|
+
}
|
|
23972
|
+
const listResult = spawnSync2("npx", ["supabase", "projects", "list", "--output", "json"], {
|
|
23973
|
+
encoding: "utf-8",
|
|
23974
|
+
shell: true
|
|
23975
|
+
});
|
|
23976
|
+
if (listResult.status !== 0) {
|
|
23977
|
+
console.error(source_default.red("❌ Failed to list Supabase projects."));
|
|
23978
|
+
process.exit(1);
|
|
23979
|
+
}
|
|
23980
|
+
const projects = JSON.parse(listResult.stdout);
|
|
23981
|
+
const found = projects.find((p) => p.name === projectName);
|
|
23982
|
+
if (!found) {
|
|
23983
|
+
console.error(source_default.red("❌ Failed to find new Supabase project."));
|
|
23984
|
+
process.exit(1);
|
|
23985
|
+
}
|
|
23986
|
+
return {
|
|
23987
|
+
projectId: found.id,
|
|
23988
|
+
region: found.region
|
|
23989
|
+
};
|
|
23990
|
+
};
|
|
23991
|
+
var setupSupabase = async () => {
|
|
23992
|
+
console.log(source_default.magentaBright(`
|
|
23993
|
+
================ Supabase Setup ================
|
|
23994
|
+
`));
|
|
23995
|
+
checkSupabaseAuth();
|
|
23996
|
+
await getOrCreateSupabaseOrg();
|
|
23997
|
+
const projectName = await esm_default3({
|
|
23998
|
+
message: source_default.cyan("Enter a name for your Supabase project:"),
|
|
23999
|
+
default: "ZeroStarter-oss-db",
|
|
24000
|
+
validate: (inputValue) => {
|
|
24001
|
+
if (!inputValue || inputValue.trim().length === 0) {
|
|
24002
|
+
return "Project name cannot be empty";
|
|
24003
|
+
}
|
|
24004
|
+
if (inputValue.length > 64) {
|
|
24005
|
+
return "Project name must be 64 characters or less";
|
|
24006
|
+
}
|
|
24007
|
+
if (!/^[a-z0-9-]+$/.test(inputValue)) {
|
|
24008
|
+
return "Project name must contain only lowercase letters, numbers, and hyphens";
|
|
24009
|
+
}
|
|
24010
|
+
return true;
|
|
24011
|
+
}
|
|
24012
|
+
});
|
|
24013
|
+
const dbPassword = genAlphanumericPassword(24);
|
|
24014
|
+
const { projectId, region } = await createSupabaseProject(projectName, dbPassword);
|
|
24015
|
+
const databaseUrl = `postgresql://postgres.${projectId}:${dbPassword}@aws-0-${region}.pooler.supabase.com:6543/postgres`;
|
|
24016
|
+
console.log(source_default.greenBright(`
|
|
24017
|
+
Generated DB password: ${dbPassword}
|
|
24018
|
+
`));
|
|
24019
|
+
console.log(source_default.greenBright(`
|
|
24020
|
+
Your DATABASE_URL is:
|
|
24021
|
+
${databaseUrl}
|
|
24022
|
+
`));
|
|
24023
|
+
console.log(source_default.yellow("--------------------------------"));
|
|
24024
|
+
return databaseUrl;
|
|
24025
|
+
};
|
|
24026
|
+
|
|
24027
|
+
// src/providers/railway-pg.ts
|
|
24028
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
23871
24029
|
|
|
23872
24030
|
// node_modules/@inquirer/core/dist/lib/key.js
|
|
23873
24031
|
var isUpKey2 = (key4, keybindings = []) => key4.name === "up" || keybindings.includes("vim") && key4.name === "k" || keybindings.includes("emacs") && key4.ctrl && key4.name === "p";
|
|
@@ -25644,7 +25802,7 @@ var dist_default3 = createPrompt4((config, done) => {
|
|
|
25644
25802
|
// node_modules/@inquirer/external-editor/dist/index.js
|
|
25645
25803
|
var import_chardet = __toESM(require_lib5(), 1);
|
|
25646
25804
|
var import_iconv_lite = __toESM(require_lib6(), 1);
|
|
25647
|
-
import { spawn, spawnSync as
|
|
25805
|
+
import { spawn, spawnSync as spawnSync3 } from "child_process";
|
|
25648
25806
|
import { readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
25649
25807
|
import path from "node:path";
|
|
25650
25808
|
import os2 from "node:os";
|
|
@@ -25822,7 +25980,7 @@ class ExternalEditor {
|
|
|
25822
25980
|
}
|
|
25823
25981
|
launchEditor() {
|
|
25824
25982
|
try {
|
|
25825
|
-
const editorProcess =
|
|
25983
|
+
const editorProcess = spawnSync3(this.editor.bin, this.editor.args.concat([this.tempFile]), { stdio: "inherit" });
|
|
25826
25984
|
this.lastExitStatus = editorProcess.status ?? 0;
|
|
25827
25985
|
} catch (launchError) {
|
|
25828
25986
|
throw new LaunchEditorError(launchError);
|
|
@@ -27537,158 +27695,7 @@ var inquirer = {
|
|
|
27537
27695
|
};
|
|
27538
27696
|
var dist_default15 = inquirer;
|
|
27539
27697
|
|
|
27540
|
-
// src/utils/db-utils.ts
|
|
27541
|
-
var genAlphanumericPassword = (length = 24) => {
|
|
27542
|
-
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
27543
|
-
let result = "";
|
|
27544
|
-
for (let i = 0;i < length; i++) {
|
|
27545
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
27546
|
-
}
|
|
27547
|
-
return result;
|
|
27548
|
-
};
|
|
27549
|
-
var genRandomIdentifier = (length = 10) => {
|
|
27550
|
-
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
27551
|
-
let result = "";
|
|
27552
|
-
for (let i = 0;i < length; i++) {
|
|
27553
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
27554
|
-
}
|
|
27555
|
-
return result;
|
|
27556
|
-
};
|
|
27557
|
-
|
|
27558
|
-
// src/providers/supabase.ts
|
|
27559
|
-
var checkSupabaseAuth = () => {
|
|
27560
|
-
console.log(source_default.blueBright(`
|
|
27561
|
-
Checking Supabase authentication...`));
|
|
27562
|
-
const authCheckResult = spawnSync3("npx", ["supabase", "orgs", "list"], {
|
|
27563
|
-
encoding: "utf-8",
|
|
27564
|
-
shell: true,
|
|
27565
|
-
stdio: "pipe"
|
|
27566
|
-
});
|
|
27567
|
-
if (authCheckResult.status !== 0) {
|
|
27568
|
-
console.log(source_default.yellowBright("Not logged in to Supabase."));
|
|
27569
|
-
console.log(source_default.blueBright("Launching Supabase login..."));
|
|
27570
|
-
spawnSync3("npx", ["supabase", "login"], { stdio: "inherit", shell: true });
|
|
27571
|
-
return false;
|
|
27572
|
-
}
|
|
27573
|
-
console.log(source_default.greenBright("✅ Already logged in to Supabase."));
|
|
27574
|
-
return true;
|
|
27575
|
-
};
|
|
27576
|
-
var getOrCreateSupabaseOrg = async () => {
|
|
27577
|
-
const orgListResult = spawnSync3("npx", ["supabase", "orgs", "list"], {
|
|
27578
|
-
encoding: "utf-8",
|
|
27579
|
-
shell: true
|
|
27580
|
-
});
|
|
27581
|
-
if (orgListResult.status !== 0) {
|
|
27582
|
-
console.error(source_default.red("❌ Failed to list Supabase orgs."));
|
|
27583
|
-
process.exit(1);
|
|
27584
|
-
}
|
|
27585
|
-
const lines2 = orgListResult.stdout.split(`
|
|
27586
|
-
`).map((l) => l.trim()).filter(Boolean);
|
|
27587
|
-
const sepIdx = lines2.findIndex((line) => line.includes("|") && line.includes("-"));
|
|
27588
|
-
if (lines2.length <= sepIdx + 1) {
|
|
27589
|
-
console.log(source_default.yellowBright("No Supabase organizations found."));
|
|
27590
|
-
const { createOrg } = await dist_default15.prompt([
|
|
27591
|
-
{
|
|
27592
|
-
type: "confirm",
|
|
27593
|
-
name: "createOrg",
|
|
27594
|
-
message: source_default.cyan("Would you like to create a new Supabase organization now?"),
|
|
27595
|
-
default: true
|
|
27596
|
-
}
|
|
27597
|
-
]);
|
|
27598
|
-
if (!createOrg) {
|
|
27599
|
-
console.log(source_default.red("❌ Cannot continue without a Supabase organization. Exiting."));
|
|
27600
|
-
process.exit(1);
|
|
27601
|
-
}
|
|
27602
|
-
const { orgName } = await dist_default15.prompt([
|
|
27603
|
-
{
|
|
27604
|
-
type: "input",
|
|
27605
|
-
name: "orgName",
|
|
27606
|
-
message: source_default.cyan("Enter a name for your new Supabase organization:"),
|
|
27607
|
-
validate: (input) => input && input.length > 2
|
|
27608
|
-
}
|
|
27609
|
-
]);
|
|
27610
|
-
console.log(source_default.blueBright(`
|
|
27611
|
-
Creating Supabase organization '${orgName}'...`));
|
|
27612
|
-
const createOrgResult = spawnSync3("npx", ["supabase", "orgs", "create", orgName], {
|
|
27613
|
-
stdio: "inherit",
|
|
27614
|
-
encoding: "utf-8",
|
|
27615
|
-
shell: true
|
|
27616
|
-
});
|
|
27617
|
-
if (createOrgResult.status !== 0) {
|
|
27618
|
-
console.error(source_default.red("❌ Failed to create Supabase organization."));
|
|
27619
|
-
process.exit(1);
|
|
27620
|
-
}
|
|
27621
|
-
}
|
|
27622
|
-
};
|
|
27623
|
-
var createSupabaseProject = async (projectName, dbPassword) => {
|
|
27624
|
-
console.log(source_default.blueBright(`
|
|
27625
|
-
Creating Supabase project '${projectName}'...`));
|
|
27626
|
-
const createResult = spawnSync3("npx", ["supabase", "projects", "create", projectName, "--db-password", dbPassword], { stdio: "inherit", encoding: "utf-8", shell: true });
|
|
27627
|
-
if (createResult.status !== 0) {
|
|
27628
|
-
console.error(source_default.red("❌ Failed to create Supabase project."));
|
|
27629
|
-
process.exit(1);
|
|
27630
|
-
}
|
|
27631
|
-
const listResult = spawnSync3("npx", ["supabase", "projects", "list", "--output", "json"], {
|
|
27632
|
-
encoding: "utf-8",
|
|
27633
|
-
shell: true
|
|
27634
|
-
});
|
|
27635
|
-
if (listResult.status !== 0) {
|
|
27636
|
-
console.error(source_default.red("❌ Failed to list Supabase projects."));
|
|
27637
|
-
process.exit(1);
|
|
27638
|
-
}
|
|
27639
|
-
const projects = JSON.parse(listResult.stdout);
|
|
27640
|
-
const found = projects.find((p) => p.name === projectName);
|
|
27641
|
-
if (!found) {
|
|
27642
|
-
console.error(source_default.red("❌ Failed to find new Supabase project."));
|
|
27643
|
-
process.exit(1);
|
|
27644
|
-
}
|
|
27645
|
-
return {
|
|
27646
|
-
projectId: found.id,
|
|
27647
|
-
region: found.region
|
|
27648
|
-
};
|
|
27649
|
-
};
|
|
27650
|
-
var setupSupabase = async () => {
|
|
27651
|
-
console.log(source_default.magentaBright(`
|
|
27652
|
-
================ Supabase Setup ================
|
|
27653
|
-
`));
|
|
27654
|
-
checkSupabaseAuth();
|
|
27655
|
-
await getOrCreateSupabaseOrg();
|
|
27656
|
-
const { projectName } = await dist_default15.prompt([
|
|
27657
|
-
{
|
|
27658
|
-
type: "input",
|
|
27659
|
-
name: "projectName",
|
|
27660
|
-
message: source_default.cyan("Enter a name for your Supabase project:"),
|
|
27661
|
-
default: "ZeroStarter-oss-db",
|
|
27662
|
-
validate: (input) => {
|
|
27663
|
-
if (!input || input.trim().length === 0) {
|
|
27664
|
-
return "Project name cannot be empty";
|
|
27665
|
-
}
|
|
27666
|
-
if (input.length > 64) {
|
|
27667
|
-
return "Project name must be 64 characters or less";
|
|
27668
|
-
}
|
|
27669
|
-
if (!/^[a-z0-9-]+$/.test(input)) {
|
|
27670
|
-
return "Project name must contain only lowercase letters, numbers, and hyphens";
|
|
27671
|
-
}
|
|
27672
|
-
return true;
|
|
27673
|
-
}
|
|
27674
|
-
}
|
|
27675
|
-
]);
|
|
27676
|
-
const dbPassword = genAlphanumericPassword(24);
|
|
27677
|
-
const { projectId, region } = await createSupabaseProject(projectName, dbPassword);
|
|
27678
|
-
const databaseUrl = `postgresql://postgres.${projectId}:${dbPassword}@aws-0-${region}.pooler.supabase.com:6543/postgres`;
|
|
27679
|
-
console.log(source_default.greenBright(`
|
|
27680
|
-
Generated DB password: ${dbPassword}
|
|
27681
|
-
`));
|
|
27682
|
-
console.log(source_default.greenBright(`
|
|
27683
|
-
Your DATABASE_URL is:
|
|
27684
|
-
${databaseUrl}
|
|
27685
|
-
`));
|
|
27686
|
-
console.log(source_default.yellow("--------------------------------"));
|
|
27687
|
-
return databaseUrl;
|
|
27688
|
-
};
|
|
27689
|
-
|
|
27690
27698
|
// src/providers/railway-pg.ts
|
|
27691
|
-
import { spawnSync as spawnSync4 } from "child_process";
|
|
27692
27699
|
var railway = (args, inherit = false) => spawnSync4("bunx", ["@railway/cli", ...args], {
|
|
27693
27700
|
shell: true,
|
|
27694
27701
|
stdio: inherit ? "inherit" : "pipe",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/providers/supabase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/providers/supabase.ts"],"names":[],"mappings":"AA4KA;;GAEG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,CA8CpD,CAAC"}
|
package/package.json
CHANGED