this.me 2.8.1 → 2.8.2

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.
Files changed (44) hide show
  1. package/README.md +35 -55
  2. package/docs/Me.html +7 -7
  3. package/docs/README.md +31 -55
  4. package/docs/global.html +451 -15
  5. package/docs/index.html +22 -71
  6. package/docs/index.js.html +169 -0
  7. package/docs/module-00-Index.html +243 -0
  8. package/docs/module-CLI.html +6 -769
  9. package/docs/src_cli_ishell_shell.js.html +305 -0
  10. package/docs/{cli_main.js.html → src_cli_main.js.html} +25 -166
  11. package/docs/{me.js.html → src_me.js.html} +3 -3
  12. package/docs/this.me.png +0 -0
  13. package/index.js +6 -0
  14. package/jsdoc.json +1 -1
  15. package/package.json +1 -1
  16. package/src/cli/ascii_art/welcome.js +1 -1
  17. package/src/cli/commands.js +17 -0
  18. package/src/cli/main.js +23 -167
  19. package/src/cli/shell.js +148 -0
  20. package/Cleaker-removebg-preview (1).png +0 -0
  21. package/docs/ThisMe.html +0 -690
  22. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  23. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  24. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  25. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  26. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  27. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  28. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  29. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  30. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  31. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  32. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  33. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  34. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  35. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  36. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  37. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  38. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  39. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  40. package/docs/neurons_logo.png +0 -0
  41. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  42. package/docs/scripts/prettify/lang-css.js +0 -2
  43. package/docs/scripts/prettify/prettify.js +0 -28
  44. package/docs/styles/jsdoc-default.css +0 -358
package/src/cli/main.js CHANGED
@@ -1,193 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
  import os from 'os';
3
- import Me from '../me.js';
4
- import { Command } from 'commander';
5
- const program = new Command();
6
- import inquirer from 'inquirer';
7
- import fs from 'fs';
8
- import path from 'path';
3
+ /** Welcome. */
9
4
  import printWelcome from './ascii_art/welcome.js';
10
- import crypto from 'crypto';
5
+ printWelcome();
6
+ console.log(`Host_Session@ ${os.userInfo().username}`);
7
+ console.log(`v.path@ ${os.homedir()}/.me`);
11
8
  /**
12
9
  * @module CLI
13
10
  * @description
14
- * .Me Command Line Interface Functionalities.
11
+ * .Me - Command Line Interface.
15
12
  * The CLI application's code structure is categorized into two main parts:
16
13
  * Command Definitions and Interactive Shell.*/
17
-
18
- /***Command Definitions.*/
19
- /**
20
- * The 'program' variable is an instance of 'Command' from the commander package.
21
- * It's utilized to define commands and options for the CLI application.*/
22
- program
23
- .command('user <username> <pin>')
24
- .description('Authenticate and start a .me session.')
25
- .action((username, pin) => {
26
- console.log(`Attempting to authenticate user: ${username}`);
27
- // Authentication logic here
28
- });
29
-
30
- program
31
- .option('-o, --options', 'View options and commands');
32
-
33
- /***Welcome message.*/
34
- function welcomeToMe() {
35
- printWelcome();
36
- console.log(`Host_Session@ ${os.userInfo().username}`);
37
- console.log(`v.path@ ${os.homedir()}/.me`);
38
- }
39
-
40
- /**
41
- * Prompts the user to select an action and returns their choice.
42
- * @returns {Promise<string>} The user's choice.
14
+
15
+ /***
16
+ * Command Definitions:
17
+ * Leverages the `commander` package to define the CLI commands and options.
18
+ **/
19
+ import program from './commands.js';
20
+ /***Interactive Shell:
21
+ * Leverages the `inquirer` package to provide an interactive shell experience with prompts.
22
+ * The `main` function orchestrates the CLI interactions.
43
23
  */
44
- async function getUserChoice() {
45
- const choices = ['View Existing Profiles', 'Create New Profile', 'Exit'];
46
- const answer = await inquirer.prompt([{
47
- type: 'list',
48
- name: 'action',
49
- message: 'What would you like to do?',
50
- choices: choices
51
- }]);
52
- return answer.action;
53
- }
54
-
55
- /**
56
- * Prompts the user for details to create a new profile.
57
- * @returns {Promise<Me>} The new Me object with user details.
58
- */
59
- async function getNewProfileDetails() {
60
- const questions = [
61
- {
62
- type: 'input',
63
- name: 'name',
64
- message: 'What is your first name?',
65
- // Add validation as needed
66
- },
67
- {
68
- type: 'input',
69
- name: 'lastname',
70
- message: 'What is your last name?',
71
- // Add validation as needed
72
- },
73
- {
74
- type: 'input',
75
- name: 'birthday',
76
- message: 'What is your birthday? (YYYY-MM-DD)',
77
- validate: function(value) {
78
- const pass = value.match(
79
- /^\d{4}-\d{2}-\d{2}$/
80
- );
81
- if (pass) {
82
- return true;
83
- }
84
- return 'Please enter a valid date (YYYY-MM-DD)';
85
- }
86
- },
87
- {
88
- type: 'password',
89
- name: 'password',
90
- message: 'Choose a password:',
91
- // Add validation as needed
92
- },
93
- {
94
- type: 'input',
95
- name: 'pin',
96
- message: 'Choose a PIN:',
97
- // Add validation as needed
98
- },
99
- // ... Add more questions as needed
100
- ];
101
- const userDetails = await inquirer.prompt(questions);
102
- return new Me(
103
- userDetails.name,
104
- userDetails.lastname,
105
- userDetails.birthday,
106
- userDetails.password,
107
- userDetails.pin
108
- );
109
- }
110
-
111
- /**
112
- * Writes the .me object to the filesystem.
113
- * @param {Me} meProfile - The Me object to be saved.
114
- */
115
- function writeMeObjectToFile(meProfile) {
116
- const meDirectory = path.join(os.homedir(), '.me');
117
- if (!fs.existsSync(meDirectory)) {
118
- fs.mkdirSync(meDirectory, { recursive: true });
119
- }
120
-
121
- const filePath = path.join(meDirectory, `${meProfile.name}.me`);
122
- // Consider encrypting the data here before writing to the filesystem
123
- fs.writeFileSync(filePath, JSON.stringify(meProfile.getIdentityObject()));
124
- console.log('Profile created successfully.');
125
- }
126
-
127
- /**
128
- * Function to display options and commands.
129
- */
130
- function displayOptionsAndCommands() {
131
- console.log(program.helpInformation());
132
- }
133
-
134
- /**
135
- * Lists all the .me profile file paths in the user's .me directory.
136
- * @returns {string[]} An array of full file paths for each .me profile.
137
- */
138
- function listMeProfiles() {
139
- const meDirectory = path.join(os.homedir(), '.me');
140
- if (fs.existsSync(meDirectory)) {
141
- const profileFiles = fs.readdirSync(meDirectory)
142
- .filter(file => file.endsWith('.me'));
143
- return profileFiles.map(file => path.join(meDirectory, file));
144
- } else {
145
- console.log('No profiles found.');
146
- return [];
147
- }
148
- }
149
-
150
- /**
151
- * Prompts the user to select a .me profile or go back to the main menu.
152
- * @returns {Promise<string>} The file path of the selected profile or 'back' to go to the main menu.
153
- */
154
- async function selectProfile() {
155
- const profiles = listMeProfiles();
156
- if (profiles.length === 0) {
157
- console.log('No profiles found.');
158
- return 'back';
159
- }
160
-
161
- const choices = profiles.map(file => ({
162
- name: path.basename(file, '.me'),
163
- value: file
164
- })).concat([{ name: 'Go Back to Main Menu', value: 'back' }]);
165
-
166
- const answer = await inquirer.prompt([{
167
- type: 'list',
168
- name: 'selectedProfile',
169
- message: 'Select a profile to view or go back:',
170
- choices: choices
171
- }]);
172
- return answer.selectedProfile;
173
- }
24
+ import { shell } from './shell.js';
174
25
 
175
26
  /**
176
27
  * Main function to handle the CLI interactions.
177
28
  * Continuously prompts the user for actions until an exit command is given.
178
29
  */
30
+
179
31
  async function main() {
180
- welcomeToMe();
32
+ printWelcome();
181
33
  let exit = false;
182
34
  while (!exit) {
183
- const choice = await getUserChoice();
35
+ const choice = await shell.selectMe();
184
36
  switch (choice) {
185
37
  /**
186
38
  * Handles the 'View Existing Profiles' choice.
187
39
  * Lists and displays all existing .me profiles.
188
40
  */
189
41
  case 'View Existing Profiles':
190
- const selectedProfile = await selectProfile();
42
+ const selectedProfile = await shell.selectProfile();
191
43
  if (selectedProfile === 'back') {
192
44
  break;
193
45
  }
@@ -195,6 +47,10 @@ async function main() {
195
47
  console.log(`Selected profile: ${selectedProfile}`);
196
48
  // Add logic to handle the selected profile
197
49
  break;
50
+ case 'Create New Profile':
51
+ const newProfile = await shell.createMe(); // Or createMe if that's the name you're using
52
+ shell.writeMe(newProfile);
53
+ break;
198
54
  case 'Exit':
199
55
  console.log('Exiting .me CLI.');
200
56
  exit = true;
@@ -0,0 +1,148 @@
1
+ import inquirer from 'inquirer';
2
+ import path from 'path';
3
+ import os from 'os';
4
+ import fs from 'fs';
5
+ import Me from '../me.js';
6
+
7
+ /***Interactive Shell:
8
+ * Leverages the `inquirer` package to provide an interactive shell experience with prompts.
9
+ * The `main` function orchestrates the CLI interactions.
10
+ */
11
+
12
+ /**
13
+ * View Existing Profiles, Create New Profile, Exit.
14
+ * @returns {Promise<string>} The user's choice.
15
+ */
16
+ async function selectMe() {
17
+ const choices = ['View Existing Profiles', 'Create New Profile', 'Exit'];
18
+ const answer = await inquirer.prompt([{
19
+ type: 'list',
20
+ name: 'action',
21
+ message: 'What would you like to do?',
22
+ choices: choices
23
+ }]);
24
+ return answer.action;
25
+ }
26
+
27
+ /**
28
+ * Prompts the user for details to create a new profile.
29
+ * @returns {Promise<Me>} The new Me object with user details.
30
+ */
31
+ async function createMe() {
32
+ const questions = [
33
+ {
34
+ type: 'input',
35
+ name: 'name',
36
+ message: 'What is your first name?',
37
+ // Add validation as needed
38
+ },
39
+ {
40
+ type: 'input',
41
+ name: 'lastname',
42
+ message: 'What is your last name?',
43
+ // Add validation as needed
44
+ },
45
+ {
46
+ type: 'input',
47
+ name: 'birthday',
48
+ message: 'What is your birthday? (YYYY-MM-DD)',
49
+ validate: function(value) {
50
+ const pass = value.match(
51
+ /^\d{4}-\d{2}-\d{2}$/
52
+ );
53
+ if (pass) {
54
+ return true;
55
+ }
56
+ return 'Please enter a valid date (YYYY-MM-DD)';
57
+ }
58
+ },
59
+ {
60
+ type: 'password',
61
+ name: 'password',
62
+ message: 'Choose a password:',
63
+ // Add validation as needed
64
+ },
65
+ {
66
+ type: 'input',
67
+ name: 'pin',
68
+ message: 'Choose a PIN:',
69
+ // Add validation as needed
70
+ },
71
+ // ... Add more questions as needed
72
+ ];
73
+ const userDetails = await inquirer.prompt(questions);
74
+ return new Me(
75
+ userDetails.name,
76
+ userDetails.lastname,
77
+ userDetails.birthday,
78
+ userDetails.password,
79
+ userDetails.pin
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Writes the .me object to the filesystem.
85
+ * @param {Me} meProfile - The Me object to be saved.
86
+ */
87
+ function writeMe(meProfile) {
88
+ const meDirectory = path.join(os.homedir(), '.me');
89
+ if (!fs.existsSync(meDirectory)) {
90
+ fs.mkdirSync(meDirectory, { recursive: true });
91
+ }
92
+
93
+ const filePath = path.join(meDirectory, `${meProfile.name}.me`);
94
+ // Encrypting the data here before writing to the filesystem
95
+ //fs.writeFileSync(filePath, JSON.stringify(meProfile.getIdentityObject()));
96
+ //console.log('Profile created successfully.');
97
+ fs.writeFileSync(filePath, JSON.stringify(meProfile.getIdentityObject()));
98
+ console.log('Profile created successfully.');
99
+ }
100
+
101
+ /**
102
+ * Lists all the .me profile file paths in the user's .me directory.
103
+ * @returns {string[]} An array of full file paths for each .me profile.
104
+ */
105
+ function listMeProfiles() {
106
+ const meDirectory = path.join(os.homedir(), '.me');
107
+ if (fs.existsSync(meDirectory)) {
108
+ const profileFiles = fs.readdirSync(meDirectory)
109
+ .filter(file => file.endsWith('.me'));
110
+ return profileFiles.map(file => path.join(meDirectory, file));
111
+ } else {
112
+ console.log('No profiles found.');
113
+ return [];
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Prompts the user to select a .me profile or go back to the main menu.
119
+ * @returns {Promise<string>} The file path of the selected profile or 'back' to go to the main menu.
120
+ */
121
+ async function selectProfile() {
122
+ const profiles = listMeProfiles();
123
+ if (profiles.length === 0) {
124
+ console.log('No profiles found.');
125
+ return 'back';
126
+ }
127
+
128
+ const choices = profiles.map(file => ({
129
+ name: path.basename(file, '.me'),
130
+ value: file
131
+ })).concat([{ name: 'Go Back to Main Menu', value: 'back' }]);
132
+
133
+ const answer = await inquirer.prompt([{
134
+ type: 'list',
135
+ name: 'selectedProfile',
136
+ message: 'Select a profile to view or go back:',
137
+ choices: choices
138
+ }]);
139
+ return answer.selectedProfile;
140
+ }
141
+
142
+ export const shell = {
143
+ selectMe,
144
+ createMe,
145
+ writeMe,
146
+ listMeProfiles,
147
+ selectProfile,
148
+ };
Binary file