Skip to content

Commit e5fa44a

Browse files
authored
Merge pull request #2 from fleetbase/feature/registry-developer-account-registration
feat: Add Registry Developer Account Registration
2 parents 79a2148 + d5d0118 commit e5fa44a

2 files changed

Lines changed: 167 additions & 1 deletion

File tree

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ flb set-auth [token] --path /fleetbase
5656

5757
- `-p, --path`: (Optional) The path to the fleetbase instance directory. Defaults to the current directory.
5858

59+
### Login to the Fleetbase Registry
60+
61+
Login to the Fleetbase registry. This command authenticates you with the Fleetbase registry by saving your credentials to your local `.npmrc` file.
62+
63+
```bash
64+
flb login [options]
65+
```
66+
67+
- `-u, --username <username>`: Username for the registry.
68+
- `-p, --password <password>`: Password for the registry.
69+
- `-e, --email <email>`: Email associated with your account.
70+
- `-r, --registry <registry>`: Registry URL (default: `https://registry.fleetbase.io`).
71+
- `--scope <scope>`: Scope for the registry (optional).
72+
- `--quotes <quotes>`: Quotes option for `npm-cli-login` (optional).
73+
- `--config-path <configPath>`: Path to the npm config file (optional).
74+
5975
### Scaffolding a Extension
6076

6177
Fleetbase CLI has the ability to scaffold a starter extension if you intend to develop your own extension. This greatly speeds up the development process as it gives you a correct starting point to build on.
@@ -97,6 +113,52 @@ flb uninstall [extension] --path /fleetbase
97113
- `[extension]`: The name of the extension to install.
98114
- `-p, --path`: (Optional) The path to the fleetbase instance directory. Defaults to the current directory.
99115

116+
### Bundling a Extension
117+
118+
To bundle a extension, use:
119+
120+
```bash
121+
flb bundle
122+
```
123+
124+
or to bundle and upload the created bundle, use:
125+
126+
```bash
127+
flb bundle --upload
128+
```
129+
130+
- `-p, --path <path>`: Path of the Fleetbase extension (default: `.`).
131+
- `--upload`: After bundling, upload the bundle to the Fleetbase registry using your authentication token.
132+
- `--auth-token <token>`: Auth token for uploading the bundle (used with `--upload` option).
133+
- `-r, --registry <registry>`: Registry URL (default: `https://registry.fleetbase.io`).
134+
135+
### Uploading a Extension Bundle
136+
137+
To upload an extension bundle, use:
138+
139+
```bash
140+
flb bundle-upload
141+
```
142+
143+
- `[bundleFile]`: Path to the bundle file to upload. If not provided, it will look for the bundle in the current directory.
144+
- `-p, --path <path>`: Path where the bundle is located (default: `.`).
145+
- `--auth-token <token>`: Auth token for uploading the bundle. If not provided, the token will be read from the `.npmrc` file.
146+
- `-r, --registry <registry>`: Registry URL (default: `https://registry.fleetbase.io`).
147+
148+
### Version Bump and Extension
149+
150+
To bump the version on an extension, use:
151+
152+
```bash
153+
flb version-bump
154+
```
155+
156+
- `-p, --path <path>`: Path of the Fleetbase extension (default: `.`).
157+
- `--major`: Bump major version (e.g., `1.0.0``2.0.0`).
158+
- `--minor`: Bump minor version (e.g., `1.0.0``1.1.0`).
159+
- `--patch`: Bump patch version (e.g., `1.0.0``1.0.1`). This is the default if no flag is provided.
160+
- `--pre-release [identifier]`: Add a pre-release identifier (e.g., `1.0.0``1.0.0-beta`).
161+
100162
### Setting a Custom Registry
101163

102164
To specify a custom registry for publishing and unpublishing, use the `-r` or `--registry` option:

index.js

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,102 @@ async function versionBump (options) {
721721
}
722722
}
723723

724-
// Command to handle login
724+
// Command to handle registration
725+
async function registerCommand(options) {
726+
const registrationApi = 'https://api.fleetbase.io/~registry/v1/developer-account/register';
727+
728+
try {
729+
// Collect registration information
730+
const answers = await prompt([
731+
{
732+
type: 'input',
733+
name: 'username',
734+
message: 'Username:',
735+
initial: options.username,
736+
skip: !!options.username,
737+
validate: (value) => {
738+
if (!value || value.length < 3) {
739+
return 'Username must be at least 3 characters';
740+
}
741+
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
742+
return 'Username can only contain letters, numbers, hyphens, and underscores';
743+
}
744+
return true;
745+
}
746+
},
747+
{
748+
type: 'input',
749+
name: 'email',
750+
message: 'Email:',
751+
initial: options.email,
752+
skip: !!options.email,
753+
validate: (value) => {
754+
if (!value || !value.includes('@')) {
755+
return 'Please enter a valid email address';
756+
}
757+
return true;
758+
}
759+
},
760+
{
761+
type: 'password',
762+
name: 'password',
763+
message: 'Password:',
764+
skip: !!options.password,
765+
validate: (value) => {
766+
if (!value || value.length < 8) {
767+
return 'Password must be at least 8 characters';
768+
}
769+
return true;
770+
}
771+
},
772+
{
773+
type: 'input',
774+
name: 'name',
775+
message: 'Full Name (optional):',
776+
initial: options.name
777+
}
778+
]);
779+
780+
const registrationData = {
781+
username: options.username || answers.username,
782+
email: options.email || answers.email,
783+
password: options.password || answers.password,
784+
name: options.name || answers.name || undefined
785+
};
786+
787+
console.log('\nRegistering account...');
788+
789+
// Make API call to register
790+
const response = await axios.post(registrationApi, registrationData);
791+
792+
if (response.data.status === 'success') {
793+
console.log('\n✓ Account created successfully!');
794+
console.log('✓ Please check your email to verify your account.');
795+
console.log(`\n✓ Once verified, you can login with: flb login -u ${registrationData.username}`);
796+
} else {
797+
console.error('Registration failed:', response.data.message || 'Unknown error');
798+
process.exit(1);
799+
}
800+
} catch (error) {
801+
if (error.response && error.response.data) {
802+
const errorData = error.response.data;
803+
if (errorData.errors) {
804+
console.error('\nRegistration failed with the following errors:');
805+
Object.keys(errorData.errors).forEach(field => {
806+
errorData.errors[field].forEach(message => {
807+
console.error(` - ${field}: ${message}`);
808+
});
809+
});
810+
} else {
811+
console.error('Registration failed:', errorData.message || 'Unknown error');
812+
}
813+
} else {
814+
console.error('Registration failed:', error.message);
815+
}
816+
process.exit(1);
817+
}
818+
}
819+
725820
function loginCommand (options) {
726821
const npmLogin = require('npm-cli-login');
727822
const username = options.username;
@@ -875,6 +970,15 @@ program
875970
.option('--pre-release [identifier]', 'Add pre-release identifier')
876971
.action(versionBump);
877972

973+
program
974+
.command('register')
975+
.description('Register a new Registry Developer Account')
976+
.option('-u, --username <username>', 'Username for the registry')
977+
.option('-e, --email <email>', 'Email address')
978+
.option('-p, --password <password>', 'Password')
979+
.option('-n, --name <name>', 'Your full name (optional)')
980+
.action(registerCommand);
981+
878982
program
879983
.command('login')
880984
.description('Log in to the Fleetbase registry')

0 commit comments

Comments
 (0)