fabrica-e-commerce 0.1.4 → 0.1.5
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/README.md +2 -2
- package/package.json +1 -1
- package/src/github.js +58 -32
- package/src/system.js +1 -0
- package/src/ui.js +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ On Windows CMD, these commands do not require Unix tools such as `find` or `xarg
|
|
|
38
38
|
|
|
39
39
|
## Commands
|
|
40
40
|
|
|
41
|
-
- `build` — checks dependencies (git, GitHub CLI, Vercel CLI), creates a Fabrica Connect Supabase job, opens the OAuth bridge, asks for required secrets, clones `https://github.com/trucount/fabrica-final-e-c.git`, verifies/logs in to Vercel (`vercel login`),
|
|
41
|
+
- `build` — checks dependencies (git, GitHub CLI, Vercel CLI), creates a Fabrica Connect Supabase job, opens the OAuth bridge, asks for required secrets, clones `https://github.com/trucount/fabrica-final-e-c.git`, verifies/logs in to Vercel (`vercel login`), publishes that code to a **new GitHub repository** under your account, connects the Vercel project to that repo for continuous deployment, writes every environment variable to production/preview/development, and deploys with `vercel --prod`.
|
|
42
42
|
- `list` — shows locally saved deployments and lets you replace a saved project's Vercel environment variable (across production, preview, and development), then redeploys.
|
|
43
43
|
- `vins` — verifies the CLI's external dependencies (`git`, GitHub CLI `gh`, and the Vercel CLI via `npx`) and automatically installs anything missing using your system's package manager (`apt-get`/`dnf`/`pacman` on Linux, `brew` on macOS, `winget`/`choco` on Windows). Prints manual install links for anything it can't install automatically.
|
|
44
44
|
- `info` / `.info` — prints package, bridge, repository, and local data paths.
|
|
@@ -62,7 +62,7 @@ On Windows CMD, these commands do not require Unix tools such as `find` or `xarg
|
|
|
62
62
|
5. Adds `SUPABASE_URL` and `SUPABASE_ANON_KEY` from the bridge response.
|
|
63
63
|
6. **Step 3 — deploy:**
|
|
64
64
|
- Verifies you're logged in to Vercel (`vercel whoami`); if not, runs an interactive `vercel login` and waits for it to finish.
|
|
65
|
-
- Logs in to the GitHub CLI if needed (`gh auth login`), detaches the cloned code from the template's git history, and
|
|
65
|
+
- Logs in to the GitHub CLI if needed (`gh auth login`), detaches the cloned code from the template's git history, and publishes it to a **brand new private GitHub repository** under your account using the GitHub API, avoiding separate `git push` credential prompts.
|
|
66
66
|
- Links a new Vercel project with `vercel link --yes --project <name>` and connects it to the new GitHub repo with `vercel git connect` so future pushes auto-deploy.
|
|
67
67
|
- Writes every collected environment variable (including the Supabase URL/anon key) to the **production, preview, and development** environments with `vercel env add`, so the values are permanent for the project, not just the first deploy.
|
|
68
68
|
- Creates the production deployment with `vercel --prod --yes`.
|
package/package.json
CHANGED
package/src/github.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import process from 'node:process';
|
|
2
4
|
import { commandExists, runCommand, runCommandCapture } from './system.js';
|
|
3
5
|
import { choose } from './prompt.js';
|
|
@@ -35,12 +37,12 @@ export async function ensureGithubLogin() {
|
|
|
35
37
|
kv('GitHub', 'Logged in');
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
const gitSpin = spinner('Configuring GitHub credentials
|
|
40
|
+
const gitSpin = spinner('Configuring GitHub API credentials');
|
|
39
41
|
if (await setupGithubGitCredentials()) {
|
|
40
|
-
gitSpin.succeed('GitHub credentials ready
|
|
42
|
+
gitSpin.succeed('GitHub API credentials ready');
|
|
41
43
|
} else {
|
|
42
44
|
gitSpin.fail('Could not configure GitHub git credentials automatically');
|
|
43
|
-
console.log('
|
|
45
|
+
console.log('Continuing with GitHub API publishing; if Git later asks for credentials, run: gh auth setup-git');
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -59,7 +61,7 @@ async function ensureGithubRepo(owner, repoName) {
|
|
|
59
61
|
const fullName = `${owner}/${repoName}`;
|
|
60
62
|
if (await githubRepoExists(owner, repoName)) {
|
|
61
63
|
const action = await choose(`GitHub repo ${fullName} already exists. What should Fabrica do?`, [
|
|
62
|
-
{ name: 'Use the existing repo and
|
|
64
|
+
{ name: 'Use the existing repo and publish this storefront to it', value: 'use' },
|
|
63
65
|
{ name: 'Stop so I can choose a different Vercel project/repo name', value: 'stop' }
|
|
64
66
|
]);
|
|
65
67
|
if (action === 'stop') throw new Error(`GitHub repo ${fullName} already exists. Re-run build with a different project name.`);
|
|
@@ -84,41 +86,65 @@ async function setOrigin(project, repoUrl) {
|
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
async function pushWithCredentialFallback(project) {
|
|
88
|
-
const spin = spinner('Pushing storefront to GitHub');
|
|
89
|
-
let push = await runCommandCapture('git', ['push', '-u', 'origin', 'main'], { cwd: project.target });
|
|
90
|
-
if (push.code === 0) {
|
|
91
|
-
spin.succeed('Pushed storefront to GitHub');
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
89
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
async function ghApiJson(args, body) {
|
|
91
|
+
const result = await runCommandCapture('gh', ['api', ...args, '--input', '-'], { input: JSON.stringify(body) });
|
|
92
|
+
if (result.code !== 0) throw new Error(result.stderr || result.stdout || `gh api ${args.join(' ')} failed`);
|
|
93
|
+
return result.stdout ? JSON.parse(result.stdout) : {};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function ghApiGet(args) {
|
|
97
|
+
const result = await runCommandCapture('gh', ['api', ...args]);
|
|
98
|
+
if (result.code !== 0) return null;
|
|
99
|
+
return result.stdout ? JSON.parse(result.stdout) : {};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function listTrackedFiles(project) {
|
|
103
|
+
const result = await runCommandCapture('git', ['ls-files', '-z'], { cwd: project.target });
|
|
104
|
+
if (result.code !== 0) throw new Error(result.stderr || 'Could not list storefront files for GitHub upload.');
|
|
105
|
+
return result.stdout.split('\0').filter(Boolean);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function createGithubBlob(project, owner, repoName, filePath) {
|
|
109
|
+
const absolute = path.join(project.target, filePath);
|
|
110
|
+
const content = await fs.readFile(absolute);
|
|
111
|
+
const blob = await ghApiJson([`repos/${owner}/${repoName}/git/blobs`], {
|
|
112
|
+
content: content.toString('base64'),
|
|
113
|
+
encoding: 'base64'
|
|
114
|
+
});
|
|
115
|
+
return { path: filePath.replace(/\\/g, '/'), mode: '100644', type: 'blob', sha: blob.sha };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function publishWithGithubApi(project, owner, repoName) {
|
|
119
|
+
const spin = spinner('Publishing storefront through GitHub API');
|
|
120
|
+
const files = await listTrackedFiles(project);
|
|
121
|
+
const treeItems = [];
|
|
122
|
+
for (const filePath of files) {
|
|
123
|
+
treeItems.push(await createGithubBlob(project, owner, repoName, filePath));
|
|
102
124
|
}
|
|
103
125
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
const tree = await ghApiJson([`repos/${owner}/${repoName}/git/trees`], { tree: treeItems });
|
|
127
|
+
|
|
128
|
+
const existingRef = await ghApiGet([`repos/${owner}/${repoName}/git/ref/heads/main`]);
|
|
129
|
+
const parents = existingRef?.object?.sha ? [existingRef.object.sha] : [];
|
|
130
|
+
const commit = await ghApiJson([`repos/${owner}/${repoName}/git/commits`], {
|
|
131
|
+
message: 'Initial commit from Fabrica storefront',
|
|
132
|
+
tree: tree.sha,
|
|
133
|
+
parents
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (existingRef?.ref) {
|
|
137
|
+
await ghApiJson([`repos/${owner}/${repoName}/git/refs/heads/main`, '--method', 'PATCH'], { sha: commit.sha, force: true });
|
|
138
|
+
} else {
|
|
139
|
+
await ghApiJson([`repos/${owner}/${repoName}/git/refs`], { ref: 'refs/heads/main', sha: commit.sha });
|
|
115
140
|
}
|
|
116
|
-
|
|
141
|
+
spin.succeed('Published storefront to GitHub without git push');
|
|
117
142
|
}
|
|
118
143
|
|
|
144
|
+
|
|
119
145
|
// Re-homes the cloned storefront code into a brand new GitHub repository
|
|
120
146
|
// owned by the logged-in user, so the deployed Vercel project can stay
|
|
121
|
-
// connected to that repo (
|
|
147
|
+
// connected to that repo (future changes can auto deploy) instead of the original
|
|
122
148
|
// template repository.
|
|
123
149
|
export async function createGithubRepoFromClone(project) {
|
|
124
150
|
section('GitHub repository');
|
|
@@ -140,7 +166,7 @@ export async function createGithubRepoFromClone(project) {
|
|
|
140
166
|
|
|
141
167
|
await ensureGithubRepo(owner, repoName);
|
|
142
168
|
await setOrigin(project, repoUrl);
|
|
143
|
-
await
|
|
169
|
+
await publishWithGithubApi(project, owner, repoName);
|
|
144
170
|
|
|
145
171
|
const browserUrl = `https://github.com/${owner}/${repoName}`;
|
|
146
172
|
kv('GitHub repo', browserUrl);
|
package/src/system.js
CHANGED
|
@@ -46,6 +46,7 @@ export function runCommandCapture(command, args, options = {}) {
|
|
|
46
46
|
let child;
|
|
47
47
|
try {
|
|
48
48
|
child = spawn(executable(command), args, spawnOptions(command, options, 'pipe'));
|
|
49
|
+
if (options.input) child.stdin.end(options.input);
|
|
49
50
|
} catch (error) {
|
|
50
51
|
resolve({ code: null, stdout: '', stderr: '', error });
|
|
51
52
|
return;
|
package/src/ui.js
CHANGED
|
@@ -21,7 +21,7 @@ export function help() {
|
|
|
21
21
|
banner();
|
|
22
22
|
console.log(`
|
|
23
23
|
${orange('Commands')}
|
|
24
|
-
${bold('build')} Connect Supabase, collect secrets, clone the store,
|
|
24
|
+
${bold('build')} Connect Supabase, collect secrets, clone the store, publish to a new GitHub repo, deploy to Vercel
|
|
25
25
|
${bold('list')} Show deployed Fabrica projects and edit env variables
|
|
26
26
|
${bold('vins')} Verify CLI dependencies (git, gh, vercel) and auto-install anything missing
|
|
27
27
|
${bold('info')} Show package, bridge, repo, and local storage information
|