-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mjs
152 lines (117 loc) · 4.86 KB
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env node
/*
* Copyright (c) 2023. Selldone® Business OS™
*
* Author: M.Pajuhaan
* Web: https://selldone.com
* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*
* All rights reserved. In the weave of time, where traditions and innovations intermingle, this content was crafted.
* From the essence of thought, through the corridors of creativity, each word, and sentiment has been molded.
* Not just to exist, but to inspire. Like an artist's stroke or a sculptor's chisel, every nuance is deliberate.
* Our journey is not just about reaching a destination, but about creating a masterpiece.
* Tread carefully, for you're treading on dreams.
*/
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';
import inquirer from 'inquirer';
import Config from "./src/config.mjs";
import {Authentication} from "./src/authentication.mjs";
import {ApiLayoutsList} from "./src/apis/api-layouts-list.mjs";
import './src/console/console-extend.mjs';
const COMMAND_DEPLOY = 'deploy';
const COMMAND_LOGIN = 'login';
const COMMAND_LOGOUT = 'logout';
const COMMAND_SHOW_LAYOUTS = 'show:layouts';
const COMMAND_EXIT = 'exit';
const COMMAND_CREATE_NEW_PROJECT = 'project:new';
async function promptForCommand() {
const IS_LOGIN = Authentication.getAccessToken();
function fix(text){
const _arr=text.split('|')
return _arr[0].padEnd(20)+(_arr.length>1?_arr[1]:'')
}
const response = await inquirer.prompt([
{
type: 'list',
name: 'commandToRun',
message: 'Please select an action:',
choices: [
{value: COMMAND_CREATE_NEW_PROJECT, name: fix("New | Creat new layout project.")},
{value: COMMAND_DEPLOY, name: fix("Deploy | Build and upload your Vue storefront layout.")},
...(IS_LOGIN ?
// --------- Login User ---------
[
{value: COMMAND_SHOW_LAYOUTS, name: fix("Layouts | Show all layouts in your account.")},
{
value: COMMAND_LOGOUT,
name: fix("Logout | Remove access token from your computer.")
},
] :
// --------- Guest ---------
[
{value: COMMAND_LOGIN, name: fix("Login | Login to your Selldone account.")}
]),
{value: COMMAND_EXIT, name: fix("Exit")}
],
default: COMMAND_DEPLOY
}
]);
console.log(`You selected: ${response.commandToRun}`);
return response.commandToRun;
}
async function runCommand(command) {
switch (command) {
case COMMAND_CREATE_NEW_PROJECT:
const _new_project = await import('./src/create-project/new-project.mjs');
await _new_project.run();
break;
case COMMAND_DEPLOY:
const deploy = await import('./deploy.mjs');
await deploy.default();
break;
case COMMAND_LOGOUT:
Authentication.logout()
process.exit(0);
break;
case COMMAND_LOGIN:
await Authentication.auth(()=>{
console.log("🔐 You are logged in as: 🦋 "+Authentication.USER.name+" ("+Authentication.USER.email+")");
process.exit(0);
})
break;
case COMMAND_SHOW_LAYOUTS:
await ApiLayoutsList.getLayoutsList()
break;
case COMMAND_EXIT:
process.exit(0);
break;
// Handle other commands here
default:
console.log(`Command '${command}' is not recognized.`);
break;
}
}
console.log("");
console.log("▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆");
console.log("🪅 Selldone® Business OS™ Storefront Project");
console.log("The #1 operating system for fast-growing companies.");
console.log("Visit: https://selldone.com");
console.log("▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆");
console.log("");
// Set up yargs
const argv = yargs(hideBin(process.argv))
.command('deploy', 'Build and deploy your Vue storefront project [Layout].', async () => {
await runCommand('deploy');
})
.parse();
let DEBUG = argv.debug; // Run:
if (DEBUG) {
Config.InitDebugMode();
console.log("🐞 DEBUG MODE ENABLED!\n");
}
// If no command provided, show the prompt
if (argv._ && !argv._.length) {
const commandToRun = await promptForCommand();
await runCommand(commandToRun);
}