Skip to content

Commit 915d20d

Browse files
authored
Merge pull request #77 from reynaldichernando/validate-login-interactive-commands
Add checkLogin for non interactive commands
2 parents 1992c61 + 0a78350 commit 915d20d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

bin/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import { startShell } from '../src/commands/shell.js';
77
import { PROJECT_NAME, getLatestVersion } from '../src/commons.js';
88
import { appInfo, createApp, listApps, deleteApp, updateApp } from '../src/commands/apps.js';
99
import inquirer from 'inquirer';
10-
import { initProfileModule } from '../src/modules/ProfileModule.js';
10+
import { initProfileModule, getProfileModule } from '../src/modules/ProfileModule.js';
1111
import { initPuterModule } from '../src/modules/PuterModule.js';
1212
import { createSite, infoSite, listSites, deleteSite } from '../src/commands/sites.js';
1313

1414
async function main() {
1515
initProfileModule();
1616
initPuterModule();
1717

18+
const profileModule = getProfileModule();
19+
1820
const version = await getLatestVersion(PROJECT_NAME);
1921

2022
const program = new Command();
@@ -60,6 +62,7 @@ async function main() {
6062
.description('List all your apps')
6163
.argument('[period]', 'period: today, yesterday, 7d, 30d, this_month, last_month')
6264
.action(async (period) => {
65+
await profileModule.checkLogin();
6366
await listApps({
6467
statsPeriod: period || 'all'
6568
});
@@ -75,6 +78,7 @@ async function main() {
7578
.description('Get application information')
7679
.argument('<app_name>', 'Name of the application')
7780
.action(async (app_name) => {
81+
await profileModule.checkLogin();
7882
await appInfo([app_name]);
7983
process.exit(0);
8084
});
@@ -86,6 +90,7 @@ async function main() {
8690
.argument('<remote_dir>', 'Remote directory URL')
8791
.action(async (name, remote_dir) => {
8892
try {
93+
await profileModule.checkLogin();
8994
await createApp({
9095
name: name,
9196
directory: remote_dir || '',
@@ -104,6 +109,7 @@ async function main() {
104109
.argument('<name>', 'Name of the application')
105110
.argument('[dir]', 'Directory path', '.')
106111
.action(async (name, dir) => {
112+
await profileModule.checkLogin();
107113
await updateApp([name, dir]);
108114
process.exit(0);
109115
});
@@ -114,6 +120,7 @@ async function main() {
114120
.argument('<name>', 'Name of the application')
115121
.option('-f, --force', 'Force deletion without confirmation')
116122
.action(async (name, options) => {
123+
await profileModule.checkLogin();
117124
let shouldDelete = options.force;
118125

119126
if (!shouldDelete) {
@@ -140,6 +147,7 @@ async function main() {
140147
.command('sites')
141148
.description('List sites and subdomains')
142149
.action(async () => {
150+
await profileModule.checkLogin();
143151
await listSites();
144152
process.exit(0);
145153
});
@@ -153,6 +161,7 @@ async function main() {
153161
.description('Get site information by UID')
154162
.argument('<site_uid>', 'Site UID')
155163
.action(async (site_uid) => {
164+
await profileModule.checkLogin();
156165
await infoSite([site_uid]);
157166
process.exit(0);
158167
});
@@ -164,6 +173,7 @@ async function main() {
164173
.argument('[dir]', 'Directory path')
165174
.option('--subdomain <name>', 'Subdomain name')
166175
.action(async (app_name, dir, options) => {
176+
await profileModule.checkLogin();
167177
const args = [app_name];
168178
if (dir) args.push(dir);
169179
if (options.subdomain) args.push(`--subdomain=${options.subdomain}`)
@@ -178,6 +188,7 @@ async function main() {
178188
.argument('[local_dir]', 'Local directory path')
179189
.argument('[subdomain]', 'Deployment subdomain (<subdomain>.puter.site)')
180190
.action(async (local_dir, subdomain) => {
191+
await profileModule.checkLogin();
181192
if (!local_dir) {
182193
const answer = await inquirer.prompt([
183194
{
@@ -211,6 +222,7 @@ async function main() {
211222
.argument('<uid>', 'Site UID')
212223
.option('-f, --force', 'Force deletion without confirmation')
213224
.action(async (uid, options) => {
225+
await profileModule.checkLogin();
214226
let shouldDelete = options.force;
215227

216228
if (!shouldDelete) {

src/commands/init.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import ora from 'ora';
44
import { promises as fs } from 'fs';
55
import path from 'path';
66
import { generateAppName, getDefaultHomePage } from '../commons.js';
7+
import { getProfileModule } from '../modules/ProfileModule.js';
78

89
const JS_BUNDLERS = ['Vite', 'Webpack', 'Parcel', 'esbuild', 'Farm'];
910
const FULLSTACK_FRAMEWORKS = ['Next', 'Nuxt', 'SvelteKit', 'Astro'];
1011
const JS_LIBRARIES = ['React', 'Vue', 'Angular', 'Svelte', 'jQuery'];
1112
const CSS_LIBRARIES = ['Bootstrap', 'Bulma', 'shadcn', 'Tailwind', 'Material-UI', 'Semantic UI', 'AntDesign', 'Element-Plus', 'PostCSS', 'AutoPrefixer'];
1213

1314
export async function init() {
15+
const profileModule = getProfileModule();
16+
await profileModule.checkLogin();
17+
1418
const answers = await inquirer.prompt([
1519
{
1620
type: 'input',

0 commit comments

Comments
 (0)