@trendify/cli 0.1.6 → 0.1.8

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 (74) hide show
  1. package/README.md +26 -0
  2. package/dist/app.component.d.ts +14 -0
  3. package/dist/app.component.d.ts.map +1 -0
  4. package/dist/app.component.js +448 -0
  5. package/dist/app.d.ts +9 -1
  6. package/dist/app.d.ts.map +1 -1
  7. package/dist/app.js +84 -27
  8. package/dist/cli-update-service.d.ts +29 -0
  9. package/dist/cli-update-service.d.ts.map +1 -0
  10. package/dist/cli-update-service.js +206 -0
  11. package/dist/cli.entry.d.ts +3 -0
  12. package/dist/cli.entry.d.ts.map +1 -0
  13. package/dist/cli.entry.js +51 -0
  14. package/dist/cli.js +24 -1
  15. package/dist/modules/auth/pages/login.page.d.ts +12 -0
  16. package/dist/modules/auth/pages/login.page.d.ts.map +1 -0
  17. package/dist/modules/auth/pages/login.page.js +22 -0
  18. package/dist/modules/auth/pages/profile.page.d.ts +12 -0
  19. package/dist/modules/auth/pages/profile.page.d.ts.map +1 -0
  20. package/dist/modules/auth/pages/profile.page.js +180 -0
  21. package/dist/modules/auth/services/auth-storage.service.d.ts +11 -0
  22. package/dist/modules/auth/services/auth-storage.service.d.ts.map +1 -0
  23. package/dist/modules/auth/services/auth-storage.service.js +65 -0
  24. package/dist/modules/auth/services/auth.service.d.ts +60 -0
  25. package/dist/modules/auth/services/auth.service.d.ts.map +1 -0
  26. package/dist/modules/auth/services/auth.service.js +494 -0
  27. package/dist/modules/auth/utils/auth-user.util.d.ts +3 -0
  28. package/dist/modules/auth/utils/auth-user.util.d.ts.map +1 -0
  29. package/dist/modules/auth/utils/auth-user.util.js +10 -0
  30. package/dist/modules/discovery/components/discovery-step-header.component.d.ts +7 -0
  31. package/dist/modules/discovery/components/discovery-step-header.component.d.ts.map +1 -0
  32. package/dist/modules/discovery/components/discovery-step-header.component.js +5 -0
  33. package/dist/modules/discovery/pages/discovery.page.d.ts +11 -0
  34. package/dist/modules/discovery/pages/discovery.page.d.ts.map +1 -0
  35. package/dist/modules/discovery/pages/discovery.page.js +58 -0
  36. package/dist/modules/profile/pages/profile.page.d.ts +12 -0
  37. package/dist/modules/profile/pages/profile.page.d.ts.map +1 -0
  38. package/dist/modules/profile/pages/profile.page.js +180 -0
  39. package/dist/shared/components/action-menu.component.d.ts +13 -0
  40. package/dist/shared/components/action-menu.component.d.ts.map +1 -0
  41. package/dist/shared/components/action-menu.component.js +7 -0
  42. package/dist/shared/components/app-logo.component.d.ts +2 -0
  43. package/dist/shared/components/app-logo.component.d.ts.map +1 -0
  44. package/dist/shared/components/app-logo.component.js +13 -0
  45. package/dist/shared/components/app-menu.component.d.ts +17 -0
  46. package/dist/shared/components/app-menu.component.d.ts.map +1 -0
  47. package/dist/shared/components/app-menu.component.js +85 -0
  48. package/dist/shared/components/app-shell.component.d.ts +12 -0
  49. package/dist/shared/components/app-shell.component.d.ts.map +1 -0
  50. package/dist/shared/components/app-shell.component.js +15 -0
  51. package/dist/shared/components/radio-select.component.d.ts +12 -0
  52. package/dist/shared/components/radio-select.component.d.ts.map +1 -0
  53. package/dist/shared/components/radio-select.component.js +16 -0
  54. package/dist/shared/components/step-header.component.d.ts +7 -0
  55. package/dist/shared/components/step-header.component.d.ts.map +1 -0
  56. package/dist/shared/components/step-header.component.js +5 -0
  57. package/dist/shared/components/text-field.component.d.ts +12 -0
  58. package/dist/shared/components/text-field.component.d.ts.map +1 -0
  59. package/dist/shared/components/text-field.component.js +6 -0
  60. package/dist/shared/config/app-paths.config.d.ts +4 -0
  61. package/dist/shared/config/app-paths.config.d.ts.map +1 -0
  62. package/dist/shared/config/app-paths.config.js +5 -0
  63. package/dist/shared/config/env.config.d.ts +14 -0
  64. package/dist/shared/config/env.config.d.ts.map +1 -0
  65. package/dist/shared/config/env.config.js +58 -0
  66. package/dist/shared/constants/app-version.constant.d.ts +2 -0
  67. package/dist/shared/constants/app-version.constant.d.ts.map +1 -0
  68. package/dist/shared/constants/app-version.constant.js +1 -0
  69. package/dist/shared/services/cli-update.service.d.ts +29 -0
  70. package/dist/shared/services/cli-update.service.d.ts.map +1 -0
  71. package/dist/shared/services/cli-update.service.js +206 -0
  72. package/dist/version.d.ts +1 -1
  73. package/dist/version.js +1 -1
  74. package/package.json +4 -4
@@ -0,0 +1,206 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { spawn } from 'node:child_process';
3
+ const DEFAULT_PACKAGE_NAME = '@trendify/cli';
4
+ const VERSION_PATTERN = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/u;
5
+ function getPackageManifestPath() {
6
+ return new URL('../package.json', import.meta.url);
7
+ }
8
+ function getNpmCommand() {
9
+ return process.platform === 'win32' ? 'npm.cmd' : 'npm';
10
+ }
11
+ function toErrorMessage(error) {
12
+ if (error instanceof Error && error.message.trim()) {
13
+ return error.message;
14
+ }
15
+ return 'Nao foi possivel concluir a operacao.';
16
+ }
17
+ function readInstalledPackageMetadata() {
18
+ try {
19
+ const manifestContents = readFileSync(getPackageManifestPath(), 'utf8');
20
+ const manifest = JSON.parse(manifestContents);
21
+ const packageName = typeof manifest.name === 'string' && manifest.name.trim().length > 0
22
+ ? manifest.name.trim()
23
+ : DEFAULT_PACKAGE_NAME;
24
+ return { packageName };
25
+ }
26
+ catch {
27
+ return { packageName: DEFAULT_PACKAGE_NAME };
28
+ }
29
+ }
30
+ function parseVersion(version) {
31
+ const match = VERSION_PATTERN.exec(version.trim());
32
+ if (!match) {
33
+ return null;
34
+ }
35
+ const [, major, minor, patch, prerelease] = match;
36
+ if (!major || !minor || !patch) {
37
+ return null;
38
+ }
39
+ return {
40
+ major: Number.parseInt(major, 10),
41
+ minor: Number.parseInt(minor, 10),
42
+ patch: Number.parseInt(patch, 10),
43
+ prerelease: prerelease ?? null,
44
+ };
45
+ }
46
+ function compareVersions(left, right) {
47
+ const parsedLeft = parseVersion(left);
48
+ const parsedRight = parseVersion(right);
49
+ if (!parsedLeft || !parsedRight) {
50
+ return left.localeCompare(right, undefined, { numeric: true, sensitivity: 'base' });
51
+ }
52
+ if (parsedLeft.major !== parsedRight.major) {
53
+ return parsedLeft.major - parsedRight.major;
54
+ }
55
+ if (parsedLeft.minor !== parsedRight.minor) {
56
+ return parsedLeft.minor - parsedRight.minor;
57
+ }
58
+ if (parsedLeft.patch !== parsedRight.patch) {
59
+ return parsedLeft.patch - parsedRight.patch;
60
+ }
61
+ if (parsedLeft.prerelease === parsedRight.prerelease) {
62
+ return 0;
63
+ }
64
+ if (parsedLeft.prerelease === null) {
65
+ return 1;
66
+ }
67
+ if (parsedRight.prerelease === null) {
68
+ return -1;
69
+ }
70
+ return parsedLeft.prerelease.localeCompare(parsedRight.prerelease, undefined, {
71
+ numeric: true,
72
+ sensitivity: 'base',
73
+ });
74
+ }
75
+ function runCommand(command, args) {
76
+ return new Promise((resolve, reject) => {
77
+ const child = spawn(command, [...args], {
78
+ env: process.env,
79
+ stdio: ['ignore', 'pipe', 'pipe'],
80
+ });
81
+ let stdout = '';
82
+ let stderr = '';
83
+ child.stdout.on('data', (chunk) => {
84
+ stdout += chunk.toString();
85
+ });
86
+ child.stderr.on('data', (chunk) => {
87
+ stderr += chunk.toString();
88
+ });
89
+ child.on('error', (error) => {
90
+ reject(error);
91
+ });
92
+ child.on('close', (code) => {
93
+ resolve({
94
+ code: code ?? 1,
95
+ stderr,
96
+ stdout,
97
+ });
98
+ });
99
+ });
100
+ }
101
+ async function fetchLatestPublishedVersion(packageName) {
102
+ const commandResult = await runCommand(getNpmCommand(), ['view', packageName, 'version', '--json', '--silent']);
103
+ if (commandResult.code !== 0) {
104
+ const message = commandResult.stderr.trim() || commandResult.stdout.trim() || 'Falha ao consultar o npm.';
105
+ throw new Error(message);
106
+ }
107
+ const stdout = commandResult.stdout.trim();
108
+ if (!stdout) {
109
+ throw new Error('O npm nao retornou a versao publicada mais recente.');
110
+ }
111
+ try {
112
+ const parsedOutput = JSON.parse(stdout);
113
+ if (typeof parsedOutput === 'string' && parsedOutput.trim()) {
114
+ return parsedOutput.trim();
115
+ }
116
+ }
117
+ catch {
118
+ if (stdout) {
119
+ return stdout.replace(/^"+|"+$/gu, '').trim();
120
+ }
121
+ }
122
+ throw new Error('Nao foi possivel interpretar a versao publicada retornada pelo npm.');
123
+ }
124
+ async function runCommandWithInheritedStdio(command, args) {
125
+ return new Promise((resolve, reject) => {
126
+ const child = spawn(command, [...args], {
127
+ env: process.env,
128
+ stdio: 'inherit',
129
+ });
130
+ child.on('error', (error) => {
131
+ reject(error);
132
+ });
133
+ child.on('close', (code) => {
134
+ resolve(code ?? 1);
135
+ });
136
+ });
137
+ }
138
+ async function restartCli() {
139
+ const entrypoint = process.argv[1];
140
+ if (!entrypoint) {
141
+ throw new Error('Nao foi possivel identificar o entrypoint atual da CLI para reiniciar o processo.');
142
+ }
143
+ await new Promise((resolve, reject) => {
144
+ const child = spawn(process.execPath, [...process.execArgv, entrypoint, ...process.argv.slice(2)], {
145
+ env: process.env,
146
+ stdio: 'inherit',
147
+ });
148
+ child.on('error', (error) => {
149
+ reject(error);
150
+ });
151
+ child.on('spawn', () => {
152
+ resolve();
153
+ });
154
+ });
155
+ }
156
+ export async function checkForCliUpdate(currentVersion) {
157
+ const { packageName } = readInstalledPackageMetadata();
158
+ try {
159
+ const latestVersion = await fetchLatestPublishedVersion(packageName);
160
+ if (compareVersions(latestVersion, currentVersion) > 0) {
161
+ return {
162
+ currentVersion,
163
+ latestVersion,
164
+ packageName,
165
+ status: 'available',
166
+ };
167
+ }
168
+ return {
169
+ currentVersion,
170
+ latestVersion,
171
+ packageName,
172
+ status: 'current',
173
+ };
174
+ }
175
+ catch (error) {
176
+ return {
177
+ currentVersion,
178
+ message: toErrorMessage(error),
179
+ packageName,
180
+ status: 'error',
181
+ };
182
+ }
183
+ }
184
+ export async function runCliSelfUpdate(packageName, latestVersion) {
185
+ try {
186
+ const exitCode = await runCommandWithInheritedStdio(getNpmCommand(), [
187
+ 'install',
188
+ '--global',
189
+ `${packageName}@${latestVersion}`,
190
+ ]);
191
+ if (exitCode !== 0) {
192
+ return {
193
+ error: `O npm encerrou a atualizacao com codigo ${exitCode}.`,
194
+ ok: false,
195
+ };
196
+ }
197
+ await restartCli();
198
+ return { ok: true };
199
+ }
200
+ catch (error) {
201
+ return {
202
+ error: toErrorMessage(error),
203
+ ok: false,
204
+ };
205
+ }
206
+ }
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const APP_VERSION = "0.1.6";
1
+ export declare const APP_VERSION = "0.1.8";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const APP_VERSION = '0.1.6';
1
+ export const APP_VERSION = '0.1.8';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@trendify/cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "CLI do Trendify para descoberta de temas e fluxos de conta.",
5
5
  "type": "module",
6
- "main": "dist/cli.js",
7
- "types": "dist/cli.d.ts",
6
+ "main": "dist/cli.entry.js",
7
+ "types": "dist/cli.entry.d.ts",
8
8
  "bin": {
9
- "trendify": "dist/cli.js"
9
+ "trendify": "dist/cli.entry.js"
10
10
  },
11
11
  "files": [
12
12
  "dist",