Skip to content

Commit 754c037

Browse files
Merge pull request #1 from matthias-wright/fixes
fix: 🐛 Minor fixes and chores
2 parents 86f5748 + 82b6dc4 commit 754c037

File tree

19 files changed

+59
-35
lines changed

19 files changed

+59
-35
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,31 @@ export const runtime = 'edge';
3636
2. **Set environment variables**
3737

3838
```sh
39-
export FLEEK_PROJECT_ID=<your project id>
40-
export FLEEK_PAT=<your personal access token>
39+
export FLEEK_TOKEN=<your personal access token>
4140
```
4241

43-
3. **Build and Deploy**
42+
3. Add `fleek.json` to your project's root dir:
43+
44+
```json
45+
{
46+
"FLEEK_PROJECT_ID": "<your project id>"
47+
}
48+
```
49+
50+
4. **Build and Deploy**
4451

4552
Use the Fleek Next.js adapter to build and deploy your application via the command line:
4653

4754
```sh
48-
npx fleek-next build
55+
npx fleek-next deploy
4956
# or if installed globally
50-
fleek-next build
57+
fleek-next deploy
5158
```
5259

5360
If you are running the command outside of your project's root dir, you can set the path to it with the project path flag `-p`/`--projectPath`:
5461

5562
```sh
56-
fleek-next build -p path/to/my/repo
63+
fleek-next deploy -p path/to/my/repo
5764
```
5865

5966
## Login to Fleek
@@ -92,7 +99,7 @@ fleek projects list | grep '<name of your project>' | awk '{print $1}'
9299

93100
## Additional Options
94101

95-
The `build` command supports several options to customize the build and deployment process:
102+
The `deploy` command supports several options to customize the build and deployment process:
96103

97104
- `-d, --dryrun`: Builds the Next.js app without deploying it to Fleek. Defaults to `false`.
98105
- `-p, --project-path <path>`: The path to your Next.js project's root directory. Defaults to the path where the command is run.

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Command } from 'commander';
44
import { t } from './utils/translation.js';
55
import { Output } from './output/Output.js';
6-
import cmdBuild from './commands/build/index.js';
6+
import cmdBuild from './commands/deploy/index.js';
77

88
const isDebugging = process.argv.includes('--verbose');
99
export const output = new Output({

src/commands/build/prompts/getProjectIdOrPrompt.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/commands/build/action.ts renamed to src/commands/deploy/action.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ type BuildArgs = {
2020
clean?: boolean;
2121
};
2222

23-
export async function sdkClient() {
24-
output.spinner(`${t('fleekSdkAuth')}`);
25-
const sdk = await getSdkClient();
23+
type projectPath = {
24+
path?: string;
25+
};
26+
27+
export async function sdkClient({ path }: projectPath) {
28+
const sdk = await getSdkClient({ path: path });
2629
if (!sdk) {
30+
output.spinner(`${t('fleekSdkAuth')}`);
2731
output.error(t('fleekSdkAuthError'));
2832
throw new UnauthenticatedError();
2933
}
34+
output.spinner(`${t('fleekSdkAuth')}`);
3035
output.success(t('fleekSdkAuthSuccess'));
3136
return sdk;
3237
}
@@ -71,7 +76,7 @@ export const buildAction = async (args: BuildArgs) => {
7176

7277
// Instantiate SDK client
7378
// Make sure we have the needed credentials
74-
const sdk = await sdkClient();
79+
const sdk = await sdkClient({ path: projectPath });
7580

7681
// Clean previous build artifacts
7782
if (clean) {

src/commands/build/index.ts renamed to src/commands/deploy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { buildAction } from './action.js';
55

66
export default (program: Command) => {
77
const cmd = program
8-
.command('build')
8+
.command('deploy')
99
.option('-d, --dryRun', t('dryRun'))
1010
.option('-p, --projectPath <path>', t('path'))
1111
.option('-s, --skipBuild', t('skipBuild'))
File renamed without changes.
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { textPrompt } from '../../../prompts/textPrompt.js';
2+
import { t } from '../../../utils/translation.js';
3+
import { getProjectPathOrPrompt } from '../prompts/getProjectPathOrPrompt.js';
4+
import { loadJSONFromPath } from '../../../utils/json.js';
5+
import nodePath from 'node:path';
6+
7+
type projectPath = {
8+
path?: string;
9+
};
10+
11+
export const getProjectIdOrPrompt = async ({ path }: projectPath) => {
12+
const projectPath = await getProjectPathOrPrompt({ path: path });
13+
if (!projectPath) {
14+
return await textPrompt({
15+
message: `${t('enterProjectId')}:`,
16+
});
17+
}
18+
19+
const configPath = nodePath.join(projectPath, 'fleek.json');
20+
const config: Record<string, string> = loadJSONFromPath(configPath);
21+
22+
return config.FLEEK_PROJECT_ID;
23+
};

src/fleek/sdk.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { FleekSdk, PersonalAccessTokenService } from '@fleekxyz/sdk';
2-
import { getPersonalAccessTokenOrPrompt } from '../commands/build/prompts/getPersonalAccessTokenOrPrompt.js';
3-
import { getProjectIdOrPrompt } from '../commands/build/prompts/getProjectIdOrPrompt.js';
2+
import { getPersonalAccessTokenOrPrompt } from '../commands/deploy/prompts/getPersonalAccessTokenOrPrompt.js';
3+
import { getProjectIdOrPrompt } from '../commands/deploy/prompts/getProjectIdOrPrompt.js';
44
import { MissingPersonalAccessTokenError } from '../errors/MissingPersonalAccessTokenError.js';
55
import { MissingProjectIdError } from '../errors/MissingProjectIdError.js';
66

7-
export async function getSdkClient(): Promise<FleekSdk> {
7+
type projectPath = {
8+
path?: string;
9+
};
10+
11+
export async function getSdkClient({ path }: projectPath): Promise<FleekSdk> {
812
const personalAccessToken = await getPersonalAccessTokenOrPrompt();
913

1014
if (!personalAccessToken) {
1115
throw new MissingPersonalAccessTokenError();
1216
}
1317

14-
const projectId = await getProjectIdOrPrompt();
18+
const projectId = await getProjectIdOrPrompt({ path: path });
1519

1620
if (!projectId) {
1721
throw new MissingProjectIdError();

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { readFileSync } from 'node:fs';
22
import * as path from 'node:path';
33
import * as fs from 'node:fs';
44

5-
import { MiddlewareManifest } from './commands/build/next/types.js';
6-
import { OpenNextOutput } from './commands/build/open-next/types.js';
5+
import { MiddlewareManifest } from './commands/deploy/next/types.js';
6+
import { OpenNextOutput } from './commands/deploy/open-next/types.js';
77

88
export async function copyDir(props: { src: string; dest: string }) {
99
const { src, dest } = props;

src/utils/packageManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function findPackageManager(opts: { projectPath: string }) {
2525

2626
export function getBuildCommand(opts: { packageManager: string }) {
2727
const { packageManager } = opts;
28-
return `${packageManager} build`;
28+
return `${packageManager} run build`;
2929
}
3030

3131
export function getInstallCommand(opts: { packageManager: string }) {

0 commit comments

Comments
 (0)