create-rubrica 0.3.16 → 1.0.0
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.
- package/README.md +61 -51
- package/dist/index.js +539 -285
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -156,8 +156,9 @@ var LAYOUT_FILES = {
|
|
|
156
156
|
pages: ["Home.tsx", "Resume.tsx", "Portfolio.tsx", "About.tsx", "Blog.tsx"]
|
|
157
157
|
},
|
|
158
158
|
swiss: {
|
|
159
|
-
copy: ["Layout.tsx", "Sidebar.tsx"],
|
|
160
|
-
remove: ["Navbar.tsx", "Footer.tsx"]
|
|
159
|
+
copy: ["Layout.tsx", "Sidebar.tsx", "SwissShared.tsx"],
|
|
160
|
+
remove: ["Navbar.tsx", "Footer.tsx"],
|
|
161
|
+
pages: ["Home.tsx", "Resume.tsx", "Portfolio.tsx", "About.tsx", "Blog.tsx"]
|
|
161
162
|
},
|
|
162
163
|
bento: {
|
|
163
164
|
copy: ["Layout.tsx", "FloatingDock.tsx"],
|
|
@@ -214,40 +215,34 @@ async function applyLayout(layout, options, fsModule = defaultFs) {
|
|
|
214
215
|
// src/transforms/applyTheme.ts
|
|
215
216
|
import * as nodeFsPromises2 from "fs/promises";
|
|
216
217
|
var PRESETS = {
|
|
217
|
-
"editorial-cream": {
|
|
218
|
-
|
|
219
|
-
--text: #
|
|
220
|
-
--primary: #
|
|
221
|
-
--accent: #ef4444;`,
|
|
222
|
-
dark: ``
|
|
223
|
-
},
|
|
224
|
-
"paper-noir": {
|
|
225
|
-
root: ` --bg: #f0eee9;
|
|
226
|
-
--text: #0a0a0a;
|
|
227
|
-
--primary: #ef4444;
|
|
228
|
-
--accent: #3b82f6;`,
|
|
229
|
-
dark: ``
|
|
230
|
-
},
|
|
231
|
-
"midnight-blue": {
|
|
232
|
-
root: ` --bg: #0a1224;
|
|
233
|
-
--text: #e8e6e0;
|
|
234
|
-
--primary: #06b6d4;
|
|
235
|
-
--accent: #facc15;`,
|
|
236
|
-
dark: ``
|
|
237
|
-
},
|
|
238
|
-
"solar-warm": {
|
|
239
|
-
root: ` --bg: #1a1410;
|
|
240
|
-
--text: #f2ede4;
|
|
241
|
-
--primary: #f97316;
|
|
242
|
-
--accent: #facc15;`,
|
|
243
|
-
dark: ``
|
|
244
|
-
}
|
|
218
|
+
"editorial-cream": { "--bg": "#faf7f2", "--text": "#1a1614", "--primary": "#a855f7", "--accent": "#ef4444" },
|
|
219
|
+
"paper-noir": { "--bg": "#f0eee9", "--text": "#0a0a0a", "--primary": "#ef4444", "--accent": "#3b82f6" },
|
|
220
|
+
"midnight-blue": { "--bg": "#0a1224", "--text": "#e8e6e0", "--primary": "#06b6d4", "--accent": "#facc15" },
|
|
221
|
+
"solar-warm": { "--bg": "#1a1410", "--text": "#f2ede4", "--primary": "#f97316", "--accent": "#facc15" }
|
|
245
222
|
};
|
|
246
|
-
function
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
223
|
+
function escapeRegExp(s) {
|
|
224
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
225
|
+
}
|
|
226
|
+
function setVars(css, selector, vars, addMissing) {
|
|
227
|
+
const blockRe = new RegExp(`(^|\\n)(\\s*${escapeRegExp(selector)}\\s*\\{)([^}]*)(\\})`);
|
|
228
|
+
return css.replace(blockRe, (_m, lead, open, body, close) => {
|
|
229
|
+
let updated = body;
|
|
230
|
+
const missing = [];
|
|
231
|
+
for (const [name, value] of Object.entries(vars)) {
|
|
232
|
+
const declRe = new RegExp(`(^|[\\s;{])(${escapeRegExp(name)}\\s*:)[^;}]*`);
|
|
233
|
+
if (declRe.test(updated)) {
|
|
234
|
+
updated = updated.replace(declRe, `$1$2 ${value}`);
|
|
235
|
+
} else if (addMissing) {
|
|
236
|
+
missing.push(` ${name}: ${value};`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (missing.length) {
|
|
240
|
+
updated = `${updated.replace(/\s*$/, "")}
|
|
241
|
+
${missing.join("\n")}
|
|
242
|
+
`;
|
|
243
|
+
}
|
|
244
|
+
return `${lead}${open}${updated}${close}`;
|
|
245
|
+
});
|
|
251
246
|
}
|
|
252
247
|
async function applyTheme(options, cssPath, fsModule = nodeFsPromises2) {
|
|
253
248
|
const theme = PRESETS[options.preset];
|
|
@@ -255,10 +250,8 @@ async function applyTheme(options, cssPath, fsModule = nodeFsPromises2) {
|
|
|
255
250
|
throw new Error(`applyTheme: preset "${options.preset}" n\xE3o encontrado.`);
|
|
256
251
|
}
|
|
257
252
|
const css = await fsModule.readFile(cssPath, "utf-8");
|
|
258
|
-
let updated =
|
|
259
|
-
|
|
260
|
-
updated = replaceBlock(updated, ".dark", theme.dark);
|
|
261
|
-
}
|
|
253
|
+
let updated = setVars(css, ":root", theme, true);
|
|
254
|
+
updated = setVars(updated, ".dark", theme, false);
|
|
262
255
|
await fsModule.writeFile(cssPath, updated);
|
|
263
256
|
}
|
|
264
257
|
|
|
@@ -441,6 +434,36 @@ async function writeState(projectDir, partial, fsModule = nodeFsPromises8) {
|
|
|
441
434
|
return merged;
|
|
442
435
|
}
|
|
443
436
|
|
|
437
|
+
// src/transforms/identityInputs.ts
|
|
438
|
+
function rubricaConfigInput(identity, fontSans, fontMono) {
|
|
439
|
+
return {
|
|
440
|
+
siteName: identity.siteName,
|
|
441
|
+
siteUrl: identity.siteUrl,
|
|
442
|
+
siteDescription: identity.siteDescription,
|
|
443
|
+
authorName: identity.authorName,
|
|
444
|
+
authorEmail: identity.authorEmail,
|
|
445
|
+
twitterHandle: identity.twitterHandle,
|
|
446
|
+
lang: identity.lang,
|
|
447
|
+
seoHomeTitle: identity.siteName,
|
|
448
|
+
seoHomeDescription: identity.siteDescription,
|
|
449
|
+
rssTitle: identity.siteName,
|
|
450
|
+
rssDescription: identity.siteDescription,
|
|
451
|
+
ogImageUrl: `${identity.siteUrl}/og.png`,
|
|
452
|
+
fontSans,
|
|
453
|
+
fontMono
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
function indexHtmlInput(identity, fontSans) {
|
|
457
|
+
return {
|
|
458
|
+
fontFamily: fontSans,
|
|
459
|
+
themeColor: "",
|
|
460
|
+
siteName: identity.siteName,
|
|
461
|
+
siteUrl: identity.siteUrl,
|
|
462
|
+
twitterHandle: identity.twitterHandle,
|
|
463
|
+
authorName: identity.authorName
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
444
467
|
// src/commands/create.ts
|
|
445
468
|
var TEMPLATE_FONTS = {
|
|
446
469
|
cyberpunk: { fontSans: "Chakra Petch", fontMono: "JetBrains Mono" },
|
|
@@ -477,14 +500,14 @@ function validateProjectName(name) {
|
|
|
477
500
|
);
|
|
478
501
|
}
|
|
479
502
|
}
|
|
480
|
-
async function removeDir(dirPath,
|
|
481
|
-
if (await
|
|
482
|
-
await
|
|
503
|
+
async function removeDir(dirPath, fs3) {
|
|
504
|
+
if (await fs3.exists(dirPath)) {
|
|
505
|
+
await fs3.rm(dirPath, { recursive: true, force: true });
|
|
483
506
|
}
|
|
484
507
|
}
|
|
485
508
|
async function runCreate(projectName, deps) {
|
|
486
509
|
validateProjectName(projectName);
|
|
487
|
-
const
|
|
510
|
+
const fs3 = deps.fs ?? {
|
|
488
511
|
...nodeFsPromises9,
|
|
489
512
|
exists: async (p) => {
|
|
490
513
|
try {
|
|
@@ -525,7 +548,7 @@ async function runCreate(projectName, deps) {
|
|
|
525
548
|
await applyLayoutFn(
|
|
526
549
|
layout,
|
|
527
550
|
{ projectDir, templatesDir: `${projectDir}/templates` },
|
|
528
|
-
|
|
551
|
+
fs3
|
|
529
552
|
);
|
|
530
553
|
const themeChoice = await select2({
|
|
531
554
|
message: "Tema visual",
|
|
@@ -539,7 +562,7 @@ async function runCreate(projectName, deps) {
|
|
|
539
562
|
await applyThemeFn(
|
|
540
563
|
{ preset: themeChoice },
|
|
541
564
|
`${projectDir}/src/index.css`,
|
|
542
|
-
|
|
565
|
+
fs3
|
|
543
566
|
);
|
|
544
567
|
const recommendedFonts = TEMPLATE_FONTS[layout] ?? { fontSans: "", fontMono: "" };
|
|
545
568
|
const recommendedSans = Array.isArray(recommendedFonts.fontSans) ? recommendedFonts.fontSans : [recommendedFonts.fontSans];
|
|
@@ -569,14 +592,14 @@ async function runCreate(projectName, deps) {
|
|
|
569
592
|
await applyFontFn(
|
|
570
593
|
{ fontSans, fontMono },
|
|
571
594
|
{ css: `${projectDir}/src/index.css`, html: `${projectDir}/index.html` },
|
|
572
|
-
|
|
595
|
+
fs3
|
|
573
596
|
);
|
|
574
597
|
const selectedPlugins = await multiselect({
|
|
575
598
|
message: "Plugins ativos",
|
|
576
599
|
options: [
|
|
577
600
|
{ value: "contact-wizard", label: "Contact Wizard \u2014 formul\xE1rio de contato multi-etapas", hint: "recomendado" },
|
|
578
601
|
{ value: "proposals", label: "Propostas \u2014 propostas comerciais com assinatura eletr\xF4nica", hint: "recomendado" },
|
|
579
|
-
{ value: "payments", label: "Pagamentos \u2014
|
|
602
|
+
{ value: "payments", label: "Pagamentos \u2014 checkout com PIX, boleto e cart\xE3o via Asaas" },
|
|
580
603
|
{ value: "blog", label: "Blog \u2014 listagem e leitura de posts", hint: "recomendado" },
|
|
581
604
|
{ value: "portfolio", label: "Portfolio \u2014 galeria de projetos", hint: "recomendado" },
|
|
582
605
|
{ value: "resume", label: "Curr\xEDculo \u2014 curr\xEDculo interativo com download de PDF", hint: "recomendado" },
|
|
@@ -597,50 +620,29 @@ async function runCreate(projectName, deps) {
|
|
|
597
620
|
await applyPluginsFn(
|
|
598
621
|
pluginsRecord,
|
|
599
622
|
`${projectDir}/convex/pluginRegistry.ts`,
|
|
600
|
-
|
|
623
|
+
fs3
|
|
601
624
|
);
|
|
602
625
|
const identity = await doIdentityPrompt();
|
|
603
626
|
await applyIndexHtmlFn(
|
|
604
|
-
|
|
605
|
-
fontFamily: fontSans,
|
|
606
|
-
themeColor: "",
|
|
607
|
-
siteName: identity.siteName,
|
|
608
|
-
siteUrl: identity.siteUrl,
|
|
609
|
-
twitterHandle: identity.twitterHandle,
|
|
610
|
-
authorName: identity.authorName
|
|
611
|
-
},
|
|
627
|
+
indexHtmlInput(identity, fontSans),
|
|
612
628
|
`${projectDir}/index.html`,
|
|
613
|
-
|
|
629
|
+
fs3
|
|
614
630
|
);
|
|
615
631
|
await applyRubricalConfigFn(
|
|
616
|
-
|
|
617
|
-
siteName: identity.siteName,
|
|
618
|
-
siteUrl: identity.siteUrl,
|
|
619
|
-
siteDescription: identity.siteDescription,
|
|
620
|
-
authorName: identity.authorName,
|
|
621
|
-
authorEmail: identity.authorEmail,
|
|
622
|
-
twitterHandle: identity.twitterHandle,
|
|
623
|
-
lang: identity.lang,
|
|
624
|
-
seoHomeTitle: identity.siteName,
|
|
625
|
-
seoHomeDescription: identity.siteDescription,
|
|
626
|
-
rssTitle: identity.siteName,
|
|
627
|
-
rssDescription: identity.siteDescription,
|
|
628
|
-
ogImageUrl: `${identity.siteUrl}/og.png`,
|
|
629
|
-
fontSans,
|
|
630
|
-
fontMono
|
|
631
|
-
},
|
|
632
|
+
rubricaConfigInput(identity, fontSans, fontMono),
|
|
632
633
|
projectDir,
|
|
633
|
-
|
|
634
|
+
fs3
|
|
634
635
|
);
|
|
635
636
|
const pkgPath = `${projectDir}/package.json`;
|
|
636
|
-
const pkgRaw = await
|
|
637
|
+
const pkgRaw = await fs3.readFile(pkgPath, "utf-8");
|
|
637
638
|
const pkg = JSON.parse(pkgRaw);
|
|
638
639
|
pkg.name = projectName;
|
|
639
|
-
await
|
|
640
|
+
await fs3.writeFile(pkgPath, JSON.stringify(pkg, null, 2));
|
|
640
641
|
await writeStateFn(
|
|
641
642
|
projectDir,
|
|
642
643
|
{
|
|
643
|
-
|
|
644
|
+
// Versão realmente baixada: o update usa como base para preservar as personalizações.
|
|
645
|
+
version: version.replace(/^v/, ""),
|
|
644
646
|
layout,
|
|
645
647
|
theme: themeChoice,
|
|
646
648
|
fontSans,
|
|
@@ -656,7 +658,7 @@ async function runCreate(projectName, deps) {
|
|
|
656
658
|
lang: identity.lang
|
|
657
659
|
}
|
|
658
660
|
},
|
|
659
|
-
|
|
661
|
+
fs3
|
|
660
662
|
);
|
|
661
663
|
const doGitInit = await confirm({ message: "Inicializar reposit\xF3rio git?" });
|
|
662
664
|
const packageManager = await select2({
|
|
@@ -673,8 +675,8 @@ async function runCreate(projectName, deps) {
|
|
|
673
675
|
if (packageManager !== "none") {
|
|
674
676
|
await execFn(`${packageManager} install`, projectDir);
|
|
675
677
|
}
|
|
676
|
-
await removeDir(`${projectDir}/templates`,
|
|
677
|
-
await removeDir(`${projectDir}/cli`,
|
|
678
|
+
await removeDir(`${projectDir}/templates`, fs3);
|
|
679
|
+
await removeDir(`${projectDir}/cli`, fs3);
|
|
678
680
|
const installStep = packageManager === "none" ? "pnpm install\n " : "";
|
|
679
681
|
outro(
|
|
680
682
|
`Projeto criado com sucesso!
|
|
@@ -725,24 +727,18 @@ async function detectProject(startDir, fsModule = nodeFsPromises10) {
|
|
|
725
727
|
}
|
|
726
728
|
|
|
727
729
|
// src/commands/config.ts
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
"playground",
|
|
738
|
-
"testimonials",
|
|
739
|
-
"testimonials-intake",
|
|
740
|
-
"contact-wizard",
|
|
741
|
-
"audit-log"
|
|
742
|
-
];
|
|
730
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
731
|
+
async function existsIn(fs3, p) {
|
|
732
|
+
try {
|
|
733
|
+
await fs3.access(p);
|
|
734
|
+
return true;
|
|
735
|
+
} catch {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
743
739
|
async function runConfig(deps = {}) {
|
|
744
740
|
const cwd = deps.cwd ?? process.cwd();
|
|
745
|
-
const
|
|
741
|
+
const fs3 = deps.fs ?? nodeFsPromises11;
|
|
746
742
|
const detectProjectFn = deps.detectProject ?? detectProject;
|
|
747
743
|
const readStateFn = deps.readState ?? readState;
|
|
748
744
|
const writeStateFn = deps.writeState ?? writeState;
|
|
@@ -753,9 +749,11 @@ async function runConfig(deps = {}) {
|
|
|
753
749
|
const applyIndexHtmlFn = deps.applyIndexHtml ?? applyIndexHtml;
|
|
754
750
|
const applyLayoutFn = deps.applyLayout ?? applyLayout;
|
|
755
751
|
const applyPluginsFn = deps.applyPlugins ?? applyPlugins;
|
|
756
|
-
const
|
|
752
|
+
const downloadReleaseFn = deps.downloadRelease ?? downloadRelease;
|
|
753
|
+
const getLatestVersionFn = deps.getLatestVersion ?? getLatestVersion;
|
|
754
|
+
const rubricaJsonPath = await detectProjectFn(cwd, fs3);
|
|
757
755
|
const projectDir = path6.dirname(rubricaJsonPath);
|
|
758
|
-
const currentState = await readStateFn(projectDir,
|
|
756
|
+
const currentState = await readStateFn(projectDir, fs3);
|
|
759
757
|
const stateUpdate = {};
|
|
760
758
|
const sections = await multiselect2({
|
|
761
759
|
message: "O que deseja reconfigurar?",
|
|
@@ -775,25 +773,16 @@ async function runConfig(deps = {}) {
|
|
|
775
773
|
if (selected.includes("identity")) {
|
|
776
774
|
const identityData = await doIdentityPrompt();
|
|
777
775
|
await applyRubricalConfigFn(
|
|
778
|
-
|
|
779
|
-
siteName: identityData.siteName,
|
|
780
|
-
siteUrl: identityData.siteUrl,
|
|
781
|
-
siteDescription: identityData.siteDescription,
|
|
782
|
-
authorName: identityData.authorName,
|
|
783
|
-
authorEmail: identityData.authorEmail,
|
|
784
|
-
twitterHandle: identityData.twitterHandle,
|
|
785
|
-
lang: identityData.lang,
|
|
786
|
-
seoHomeTitle: "",
|
|
787
|
-
seoHomeDescription: "",
|
|
788
|
-
rssTitle: "",
|
|
789
|
-
rssDescription: "",
|
|
790
|
-
ogImageUrl: "",
|
|
791
|
-
fontSans: currentState.fontSans,
|
|
792
|
-
fontMono: currentState.fontMono
|
|
793
|
-
},
|
|
776
|
+
rubricaConfigInput(identityData, currentState.fontSans, currentState.fontMono),
|
|
794
777
|
projectDir,
|
|
795
|
-
|
|
778
|
+
fs3
|
|
779
|
+
);
|
|
780
|
+
await applyIndexHtmlFn(
|
|
781
|
+
indexHtmlInput(identityData, currentState.fontSans),
|
|
782
|
+
path6.join(projectDir, "index.html"),
|
|
783
|
+
fs3
|
|
796
784
|
);
|
|
785
|
+
stateUpdate.identity = identityData;
|
|
797
786
|
}
|
|
798
787
|
if (selected.includes("appearance")) {
|
|
799
788
|
const theme = await select3({
|
|
@@ -836,18 +825,21 @@ async function runConfig(deps = {}) {
|
|
|
836
825
|
await applyThemeFn(
|
|
837
826
|
{ preset: theme },
|
|
838
827
|
cssPath,
|
|
839
|
-
|
|
828
|
+
fs3
|
|
840
829
|
);
|
|
841
830
|
await applyFontFn(
|
|
842
831
|
{ fontSans, fontMono },
|
|
843
832
|
{ css: cssPath, html: htmlPath },
|
|
844
|
-
|
|
845
|
-
);
|
|
846
|
-
await applyIndexHtmlFn(
|
|
847
|
-
{ fontFamily: fontSans, themeColor: "", siteName: "", siteUrl: "", twitterHandle: "", authorName: "" },
|
|
848
|
-
htmlPath,
|
|
849
|
-
fs
|
|
833
|
+
fs3
|
|
850
834
|
);
|
|
835
|
+
const identity = stateUpdate.identity ?? currentState.identity;
|
|
836
|
+
if (identity) {
|
|
837
|
+
await applyIndexHtmlFn(
|
|
838
|
+
indexHtmlInput(identity, fontSans),
|
|
839
|
+
htmlPath,
|
|
840
|
+
fs3
|
|
841
|
+
);
|
|
842
|
+
}
|
|
851
843
|
stateUpdate.theme = theme;
|
|
852
844
|
stateUpdate.fontSans = fontSans;
|
|
853
845
|
stateUpdate.fontMono = fontMono;
|
|
@@ -860,18 +852,31 @@ async function runConfig(deps = {}) {
|
|
|
860
852
|
{ value: "cyberpunk", label: "Cyberpunk", hint: "sidebar lateral com foto de perfil \u2014 dev, designer, freelancer" },
|
|
861
853
|
{ value: "brutalist", label: "Brutalism Terminal", hint: "identidade hacker total \u2014 monospace, sem bordas arredondadas" },
|
|
862
854
|
{ value: "swiss", label: "Swiss Grid", hint: "grid de 12 colunas, tipografia forte, design su\xED\xE7o rigoroso" },
|
|
863
|
-
{ value: "bento", label: "Bento", hint: "grid assim\xE9trico com floating dock \u2014 moderno, orientado a produto" }
|
|
855
|
+
{ value: "bento", label: "Bento", hint: "grid assim\xE9trico com floating dock \u2014 moderno, orientado a produto" },
|
|
856
|
+
{ value: "magazine", label: "Magazine", hint: "editorial cl\xE1ssico \xB7 display serifado \xB7 grid assim\xE9trico \xB7 \xE1reas de respiro generosas" }
|
|
864
857
|
]
|
|
865
858
|
});
|
|
866
859
|
const confirmed = await confirm2({
|
|
867
860
|
message: "\u26A0 Isso sobrescreve Layout.tsx e arquivos de navega\xE7\xE3o. Customiza\xE7\xF5es manuais ser\xE3o perdidas. Continuar?"
|
|
868
861
|
});
|
|
869
862
|
if (!isCancel3(confirmed) && confirmed === true) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
863
|
+
let templatesDir = path6.join(projectDir, "templates");
|
|
864
|
+
let tmpDir;
|
|
865
|
+
if (!await existsIn(fs3, templatesDir)) {
|
|
866
|
+
tmpDir = await nodeFsPromises11.mkdtemp(path6.join(tmpdir2(), "rubrica-config-"));
|
|
867
|
+
const version = currentState.version === "0.1.0" ? await getLatestVersionFn() : currentState.version;
|
|
868
|
+
await downloadReleaseFn(tmpDir, version.startsWith("v") ? version : `v${version}`);
|
|
869
|
+
templatesDir = path6.join(tmpDir, "templates");
|
|
870
|
+
}
|
|
871
|
+
try {
|
|
872
|
+
await applyLayoutFn(
|
|
873
|
+
newLayout,
|
|
874
|
+
{ projectDir, templatesDir },
|
|
875
|
+
{ ...fs3, copyFile: nodeFsPromises11.copyFile, unlink: nodeFsPromises11.unlink, exists: (p) => existsIn(fs3, p) }
|
|
876
|
+
);
|
|
877
|
+
} finally {
|
|
878
|
+
if (tmpDir) await nodeFsPromises11.rm(tmpDir, { recursive: true, force: true });
|
|
879
|
+
}
|
|
875
880
|
stateUpdate.layout = newLayout;
|
|
876
881
|
}
|
|
877
882
|
}
|
|
@@ -880,32 +885,260 @@ async function runConfig(deps = {}) {
|
|
|
880
885
|
const selectedPlugins = await multiselect2({
|
|
881
886
|
message: "Plugins ativos",
|
|
882
887
|
initialValues: activePlugins,
|
|
883
|
-
options:
|
|
888
|
+
options: ALL_PLUGINS.map((p) => ({ value: p, label: p })),
|
|
884
889
|
required: false
|
|
885
890
|
});
|
|
886
891
|
if (!isCancel3(selectedPlugins)) {
|
|
887
892
|
const pluginsMap = {};
|
|
888
|
-
for (const p of
|
|
893
|
+
for (const p of ALL_PLUGINS) {
|
|
889
894
|
pluginsMap[p] = selectedPlugins.includes(p);
|
|
890
895
|
}
|
|
891
896
|
await applyPluginsFn(
|
|
892
897
|
pluginsMap,
|
|
893
898
|
path6.join(projectDir, "convex", "pluginRegistry.ts"),
|
|
894
|
-
|
|
899
|
+
fs3
|
|
895
900
|
);
|
|
896
901
|
stateUpdate.plugins = pluginsMap;
|
|
897
902
|
}
|
|
898
903
|
}
|
|
899
904
|
if (Object.keys(stateUpdate).length > 0) {
|
|
900
|
-
await writeStateFn(projectDir, stateUpdate,
|
|
905
|
+
await writeStateFn(projectDir, stateUpdate, fs3);
|
|
901
906
|
}
|
|
902
907
|
outro2("Configura\xE7\xE3o atualizada com sucesso!");
|
|
903
908
|
}
|
|
904
909
|
|
|
905
910
|
// src/commands/update.ts
|
|
906
|
-
import { intro as intro2, outro as outro3, confirm as confirm3, isCancel as isCancel4, cancel as cancel4, log as log2 } from "@clack/prompts";
|
|
911
|
+
import { intro as intro2, outro as outro3, confirm as confirm3, text as text2, isCancel as isCancel4, cancel as cancel4, log as log2, spinner } from "@clack/prompts";
|
|
912
|
+
import * as fs2 from "fs/promises";
|
|
913
|
+
import * as path9 from "path";
|
|
914
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
915
|
+
import { execFile as execFile3 } from "child_process";
|
|
916
|
+
import { promisify as promisify3 } from "util";
|
|
917
|
+
|
|
918
|
+
// src/utils/pristine.ts
|
|
907
919
|
import * as nodeFsPromises12 from "fs/promises";
|
|
908
920
|
import * as path7 from "path";
|
|
921
|
+
var fsForTransforms = {
|
|
922
|
+
...nodeFsPromises12,
|
|
923
|
+
exists: async (p) => {
|
|
924
|
+
try {
|
|
925
|
+
await nodeFsPromises12.access(p);
|
|
926
|
+
return true;
|
|
927
|
+
} catch {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
async function buildPristine(options) {
|
|
933
|
+
const { dir, state } = options;
|
|
934
|
+
const download = options.download ?? downloadRelease;
|
|
935
|
+
const tag = options.version.startsWith("v") ? options.version : `v${options.version}`;
|
|
936
|
+
const fs3 = fsForTransforms;
|
|
937
|
+
await download(dir, tag);
|
|
938
|
+
await applyLayout(state.layout, { projectDir: dir, templatesDir: path7.join(dir, "templates") }, fs3);
|
|
939
|
+
const cssPath = path7.join(dir, "src", "index.css");
|
|
940
|
+
const htmlPath = path7.join(dir, "index.html");
|
|
941
|
+
await applyTheme({ preset: state.theme }, cssPath, fs3);
|
|
942
|
+
await applyFont({ fontSans: state.fontSans, fontMono: state.fontMono }, { css: cssPath, html: htmlPath }, fs3);
|
|
943
|
+
const registryPath = path7.join(dir, "convex", "pluginRegistry.ts");
|
|
944
|
+
const knownPlugins = await knownPluginIds(registryPath);
|
|
945
|
+
const plugins = Object.fromEntries(
|
|
946
|
+
Object.entries(state.plugins ?? {}).filter(([id]) => knownPlugins.has(id))
|
|
947
|
+
);
|
|
948
|
+
await applyPlugins(plugins, registryPath, fs3);
|
|
949
|
+
const identity = state.identity;
|
|
950
|
+
if (identity) {
|
|
951
|
+
await applyIndexHtml(indexHtmlInput(identity, state.fontSans), htmlPath, fs3);
|
|
952
|
+
await applyRubricalConfig(rubricaConfigInput(identity, state.fontSans, state.fontMono), dir, fs3);
|
|
953
|
+
}
|
|
954
|
+
if (options.packageName) {
|
|
955
|
+
const pkgPath = path7.join(dir, "package.json");
|
|
956
|
+
const pkg = JSON.parse(await nodeFsPromises12.readFile(pkgPath, "utf-8"));
|
|
957
|
+
pkg.name = options.packageName;
|
|
958
|
+
await nodeFsPromises12.writeFile(pkgPath, JSON.stringify(pkg, null, 2));
|
|
959
|
+
}
|
|
960
|
+
await nodeFsPromises12.rm(path7.join(dir, "templates"), { recursive: true, force: true });
|
|
961
|
+
await nodeFsPromises12.rm(path7.join(dir, "cli"), { recursive: true, force: true });
|
|
962
|
+
}
|
|
963
|
+
async function knownPluginIds(registryPath) {
|
|
964
|
+
try {
|
|
965
|
+
const content = await nodeFsPromises12.readFile(registryPath, "utf-8");
|
|
966
|
+
return new Set([...content.matchAll(/id: '([^']+)'/g)].map((m) => m[1]));
|
|
967
|
+
} catch {
|
|
968
|
+
return /* @__PURE__ */ new Set();
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// src/utils/threeWayUpdate.ts
|
|
973
|
+
import * as fs from "fs/promises";
|
|
974
|
+
import * as path8 from "path";
|
|
975
|
+
import { execFile as execFile2 } from "child_process";
|
|
976
|
+
import { promisify as promisify2 } from "util";
|
|
977
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
978
|
+
var PROTECTED = [
|
|
979
|
+
/^\.git\//,
|
|
980
|
+
/(^|\/)node_modules\//,
|
|
981
|
+
/^dist\//,
|
|
982
|
+
/^\.env(\..*)?$/,
|
|
983
|
+
/^rubrica\.json$/,
|
|
984
|
+
// Conteúdo gerado a partir do banco do usuário no build.
|
|
985
|
+
/^public\/data\//,
|
|
986
|
+
/^public\/rss\.xml$/,
|
|
987
|
+
/^public\/sitemap\.xml$/
|
|
988
|
+
];
|
|
989
|
+
var LOCKFILES = /* @__PURE__ */ new Set(["package-lock.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb"]);
|
|
990
|
+
var NEW_SUFFIX = ".rubrica-new";
|
|
991
|
+
function isProtected(file) {
|
|
992
|
+
return PROTECTED.some((re) => re.test(file));
|
|
993
|
+
}
|
|
994
|
+
async function listFiles(root) {
|
|
995
|
+
const out = [];
|
|
996
|
+
async function walk(dir) {
|
|
997
|
+
let entries;
|
|
998
|
+
try {
|
|
999
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
1000
|
+
} catch {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
for (const entry of entries) {
|
|
1004
|
+
const abs = path8.join(dir, entry.name);
|
|
1005
|
+
const rel = path8.relative(root, abs).split(path8.sep).join("/");
|
|
1006
|
+
if (entry.isDirectory()) {
|
|
1007
|
+
if (!isProtected(`${rel}/`)) await walk(abs);
|
|
1008
|
+
} else if (entry.isFile() && !isProtected(rel)) {
|
|
1009
|
+
out.push(rel);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
await walk(root);
|
|
1014
|
+
return out;
|
|
1015
|
+
}
|
|
1016
|
+
async function readOrNull(file) {
|
|
1017
|
+
try {
|
|
1018
|
+
return await fs.readFile(file);
|
|
1019
|
+
} catch {
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
function same(a, b) {
|
|
1024
|
+
if (a === null || b === null) return a === b;
|
|
1025
|
+
return a.equals(b);
|
|
1026
|
+
}
|
|
1027
|
+
function isBinary(buf) {
|
|
1028
|
+
return buf.subarray(0, 8e3).includes(0);
|
|
1029
|
+
}
|
|
1030
|
+
async function mergeText(ours, base, theirs, tmpDir) {
|
|
1031
|
+
const o = path8.join(tmpDir, "ours");
|
|
1032
|
+
const b = path8.join(tmpDir, "base");
|
|
1033
|
+
const t = path8.join(tmpDir, "theirs");
|
|
1034
|
+
await fs.writeFile(o, ours);
|
|
1035
|
+
await fs.writeFile(b, base);
|
|
1036
|
+
await fs.writeFile(t, theirs);
|
|
1037
|
+
try {
|
|
1038
|
+
const { stdout } = await execFileAsync2("git", ["merge-file", "-p", o, b, t], {
|
|
1039
|
+
encoding: "buffer",
|
|
1040
|
+
maxBuffer: 64 * 1024 * 1024
|
|
1041
|
+
});
|
|
1042
|
+
return stdout;
|
|
1043
|
+
} catch (err) {
|
|
1044
|
+
const code = err.code;
|
|
1045
|
+
if (typeof code === "number" && code > 0) return null;
|
|
1046
|
+
throw err;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
async function planUpdate(dirs) {
|
|
1050
|
+
const files = /* @__PURE__ */ new Set([...await listFiles(dirs.base), ...await listFiles(dirs.next)]);
|
|
1051
|
+
const tmpDir = await fs.mkdtemp(path8.join(path8.dirname(dirs.base), "merge-"));
|
|
1052
|
+
const actions = [];
|
|
1053
|
+
try {
|
|
1054
|
+
for (const file of [...files].sort()) {
|
|
1055
|
+
const base = await readOrNull(path8.join(dirs.base, file));
|
|
1056
|
+
const next = await readOrNull(path8.join(dirs.next, file));
|
|
1057
|
+
const ours = await readOrNull(path8.join(dirs.project, file));
|
|
1058
|
+
if (same(base, next) || same(ours, next)) continue;
|
|
1059
|
+
if (same(ours, base)) {
|
|
1060
|
+
if (next === null) actions.push({ file, kind: "remove" });
|
|
1061
|
+
else actions.push({ file, kind: base === null ? "add" : "update", content: next });
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (ours === null) {
|
|
1065
|
+
actions.push({
|
|
1066
|
+
file,
|
|
1067
|
+
kind: "conflict",
|
|
1068
|
+
incoming: next ?? void 0,
|
|
1069
|
+
reason: "voc\xEA removeu este arquivo, mas o Rubrica o alterou"
|
|
1070
|
+
});
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
if (next === null) {
|
|
1074
|
+
actions.push({ file, kind: "keep", reason: "removido no Rubrica, mas voc\xEA o personalizou" });
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
if (LOCKFILES.has(path8.basename(file))) {
|
|
1078
|
+
actions.push({ file, kind: "lockfile", reason: "rode o install para atualizar as depend\xEAncias" });
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
if (base === null) {
|
|
1082
|
+
actions.push({ file, kind: "conflict", incoming: next, reason: "voc\xEA criou um arquivo com o mesmo nome de um arquivo novo do Rubrica" });
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (isBinary(ours) || isBinary(base) || isBinary(next)) {
|
|
1086
|
+
actions.push({ file, kind: "conflict", incoming: next, reason: "arquivo bin\xE1rio alterado dos dois lados" });
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
const merged = await mergeText(ours, base, next, tmpDir);
|
|
1090
|
+
if (merged) actions.push({ file, kind: "merge", content: merged });
|
|
1091
|
+
else actions.push({ file, kind: "conflict", incoming: next, reason: "voc\xEA e o Rubrica mudaram o mesmo trecho" });
|
|
1092
|
+
}
|
|
1093
|
+
} finally {
|
|
1094
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
1095
|
+
}
|
|
1096
|
+
return actions;
|
|
1097
|
+
}
|
|
1098
|
+
async function applyPlan(projectDir, actions) {
|
|
1099
|
+
for (const action of actions) {
|
|
1100
|
+
const target = path8.join(projectDir, action.file);
|
|
1101
|
+
switch (action.kind) {
|
|
1102
|
+
case "update":
|
|
1103
|
+
case "add":
|
|
1104
|
+
case "merge":
|
|
1105
|
+
await fs.mkdir(path8.dirname(target), { recursive: true });
|
|
1106
|
+
await fs.writeFile(target, action.content);
|
|
1107
|
+
break;
|
|
1108
|
+
case "remove":
|
|
1109
|
+
await fs.rm(target, { force: true });
|
|
1110
|
+
break;
|
|
1111
|
+
case "conflict":
|
|
1112
|
+
if (action.incoming) {
|
|
1113
|
+
await fs.mkdir(path8.dirname(target), { recursive: true });
|
|
1114
|
+
await fs.writeFile(`${target}${NEW_SUFFIX}`, action.incoming);
|
|
1115
|
+
}
|
|
1116
|
+
break;
|
|
1117
|
+
case "keep":
|
|
1118
|
+
case "lockfile":
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
function formatPlan(actions) {
|
|
1124
|
+
const groups = [
|
|
1125
|
+
["update", "Atualizados"],
|
|
1126
|
+
["add", "Novos"],
|
|
1127
|
+
["remove", "Removidos"],
|
|
1128
|
+
["merge", "Mesclados com suas mudan\xE7as"],
|
|
1129
|
+
["keep", "Mantidos como voc\xEA deixou"],
|
|
1130
|
+
["lockfile", "Lockfile mantido"],
|
|
1131
|
+
["conflict", `Precisam da sua revis\xE3o (vers\xE3o nova salva em <arquivo>${NEW_SUFFIX})`]
|
|
1132
|
+
];
|
|
1133
|
+
const lines = [];
|
|
1134
|
+
for (const [kind, title] of groups) {
|
|
1135
|
+
const items = actions.filter((a) => a.kind === kind);
|
|
1136
|
+
if (!items.length) continue;
|
|
1137
|
+
lines.push(`${title} (${items.length}):`);
|
|
1138
|
+
for (const a of items) lines.push(` \u2022 ${a.file}${a.reason ? ` \u2014 ${a.reason}` : ""}`);
|
|
1139
|
+
}
|
|
1140
|
+
return lines.length ? lines.join("\n") : "Nenhum arquivo muda.";
|
|
1141
|
+
}
|
|
909
1142
|
|
|
910
1143
|
// src/utils/checkRequiredEnv.ts
|
|
911
1144
|
function parseEnvKeys(content) {
|
|
@@ -920,173 +1153,172 @@ function parseEnvKeys(content) {
|
|
|
920
1153
|
}
|
|
921
1154
|
return keys;
|
|
922
1155
|
}
|
|
923
|
-
async function readEnvKeys(filePath,
|
|
1156
|
+
async function readEnvKeys(filePath, fs3) {
|
|
924
1157
|
try {
|
|
925
|
-
const content = await
|
|
1158
|
+
const content = await fs3.readFile(filePath, "utf-8");
|
|
926
1159
|
return parseEnvKeys(content);
|
|
927
1160
|
} catch {
|
|
928
1161
|
return /* @__PURE__ */ new Set();
|
|
929
1162
|
}
|
|
930
1163
|
}
|
|
931
|
-
async function checkRequiredEnv(projectDir,
|
|
1164
|
+
async function checkRequiredEnv(projectDir, fs3) {
|
|
932
1165
|
let required = [];
|
|
933
1166
|
try {
|
|
934
|
-
const raw = await
|
|
1167
|
+
const raw = await fs3.readFile(`${projectDir}/required-env.json`, "utf-8");
|
|
935
1168
|
required = JSON.parse(raw);
|
|
936
1169
|
} catch {
|
|
937
1170
|
return [];
|
|
938
1171
|
}
|
|
939
1172
|
if (!required.length) return [];
|
|
940
|
-
const envKeys = await readEnvKeys(`${projectDir}/.env`,
|
|
941
|
-
const envLocalKeys = await readEnvKeys(`${projectDir}/.env.local`,
|
|
1173
|
+
const envKeys = await readEnvKeys(`${projectDir}/.env`, fs3);
|
|
1174
|
+
const envLocalKeys = await readEnvKeys(`${projectDir}/.env.local`, fs3);
|
|
942
1175
|
const allKeys = /* @__PURE__ */ new Set([...envKeys, ...envLocalKeys]);
|
|
943
1176
|
return required.filter((v) => !allKeys.has(v.name));
|
|
944
1177
|
}
|
|
945
1178
|
|
|
946
1179
|
// src/commands/update.ts
|
|
1180
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
1181
|
+
var LEGACY_PLACEHOLDER_VERSION = "0.1.0";
|
|
1182
|
+
function normalizeVersion(version) {
|
|
1183
|
+
return version.trim().replace(/^v/, "");
|
|
1184
|
+
}
|
|
947
1185
|
function parseMajor(version) {
|
|
948
|
-
const
|
|
949
|
-
const major = parseInt(clean.split(".")[0] ?? "0", 10);
|
|
1186
|
+
const major = parseInt(normalizeVersion(version).split(".")[0] ?? "0", 10);
|
|
950
1187
|
return isNaN(major) ? 0 : major;
|
|
951
1188
|
}
|
|
952
|
-
function
|
|
953
|
-
|
|
1189
|
+
async function gitStatus(projectDir) {
|
|
1190
|
+
try {
|
|
1191
|
+
const { stdout } = await execFileAsync3("git", ["status", "--porcelain"], { cwd: projectDir });
|
|
1192
|
+
return stdout.trim();
|
|
1193
|
+
} catch {
|
|
1194
|
+
return null;
|
|
1195
|
+
}
|
|
954
1196
|
}
|
|
955
1197
|
async function runUpdate(deps = {}) {
|
|
956
1198
|
const cwd = deps.cwd ?? process.cwd();
|
|
957
|
-
const
|
|
958
|
-
...nodeFsPromises12,
|
|
959
|
-
exists: async (p) => {
|
|
960
|
-
try {
|
|
961
|
-
await nodeFsPromises12.access(p);
|
|
962
|
-
return true;
|
|
963
|
-
} catch {
|
|
964
|
-
return false;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
const detectProjectFn = deps.detectProject ?? detectProject;
|
|
969
|
-
const readStateFn = deps.readState ?? readState;
|
|
970
|
-
const writeStateFn = deps.writeState ?? writeState;
|
|
1199
|
+
const opts = deps.options ?? {};
|
|
971
1200
|
const getLatestVersionFn = deps.getLatestVersion ?? getLatestVersion;
|
|
972
|
-
const
|
|
973
|
-
const applyLayoutFn = deps.applyLayout ?? applyLayout;
|
|
974
|
-
const applyThemeFn = deps.applyTheme ?? applyTheme;
|
|
975
|
-
const applyFontFn = deps.applyFont ?? applyFont;
|
|
976
|
-
const applyPluginsFn = deps.applyPlugins ?? applyPlugins;
|
|
977
|
-
const applyIndexHtmlFn = deps.applyIndexHtml ?? applyIndexHtml;
|
|
978
|
-
const applyRubricalConfigFn = deps.applyRubricalConfig ?? applyRubricalConfig;
|
|
1201
|
+
const download = deps.downloadRelease ?? downloadRelease;
|
|
979
1202
|
const checkRequiredEnvFn = deps.checkRequiredEnv ?? checkRequiredEnv;
|
|
980
|
-
const
|
|
981
|
-
const { execSync } = await import("child_process");
|
|
982
|
-
execSync(cmd, { cwd: cwd2, stdio: "inherit" });
|
|
983
|
-
});
|
|
1203
|
+
const ask = !opts.yes;
|
|
984
1204
|
intro2("Rubrica Update");
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const remoteVersion = normalizeVersion(await getLatestVersionFn());
|
|
990
|
-
if (localVersion === remoteVersion) {
|
|
991
|
-
outro3(`J\xE1 est\xE1 na vers\xE3o mais recente (${localVersion}). Nenhuma atualiza\xE7\xE3o necess\xE1ria.`);
|
|
1205
|
+
try {
|
|
1206
|
+
await execFileAsync3("git", ["--version"]);
|
|
1207
|
+
} catch {
|
|
1208
|
+
cancel4("O update precisa do git instalado (ele \xE9 usado para mesclar suas mudan\xE7as com a vers\xE3o nova).");
|
|
992
1209
|
return;
|
|
993
1210
|
}
|
|
994
|
-
const
|
|
995
|
-
const
|
|
996
|
-
|
|
1211
|
+
const projectDir = path9.dirname(await detectProject(cwd));
|
|
1212
|
+
const state = await readState(projectDir);
|
|
1213
|
+
let fromVersion = normalizeVersion(opts.from ?? state.version);
|
|
1214
|
+
if (!opts.from && fromVersion === LEGACY_PLACEHOLDER_VERSION) {
|
|
997
1215
|
log2.warn(
|
|
998
|
-
`
|
|
999
|
-
|
|
1000
|
-
Consulte o guia de migra\xE7\xE3o antes de prosseguir.`
|
|
1216
|
+
`O rubrica.json diz ${LEGACY_PLACEHOLDER_VERSION}, mas vers\xF5es antigas do CLI sempre gravavam esse n\xFAmero.
|
|
1217
|
+
Para preservar suas personaliza\xE7\xF5es, o update precisa saber com qual vers\xE3o o projeto foi criado (veja a data de cria\xE7\xE3o e compare com https://github.com/MierzwaMatheus/rubrica/releases).`
|
|
1001
1218
|
);
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
});
|
|
1005
|
-
if (isCancel4(majorConfirmed) || !majorConfirmed) {
|
|
1006
|
-
cancel4("Atualiza\xE7\xE3o cancelada.");
|
|
1219
|
+
if (!ask) {
|
|
1220
|
+
cancel4("Informe a vers\xE3o de origem com --from <vers\xE3o>.");
|
|
1007
1221
|
return;
|
|
1008
1222
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1223
|
+
const answer = await text2({
|
|
1224
|
+
message: "Com qual vers\xE3o o projeto foi criado?",
|
|
1225
|
+
placeholder: "ex.: 0.3.12",
|
|
1226
|
+
validate: (v) => /^v?\d+\.\d+\.\d+$/.test(v.trim()) ? void 0 : "Use o formato 0.3.12"
|
|
1013
1227
|
});
|
|
1014
|
-
if (isCancel4(
|
|
1228
|
+
if (isCancel4(answer)) {
|
|
1015
1229
|
cancel4("Atualiza\xE7\xE3o cancelada.");
|
|
1016
1230
|
return;
|
|
1017
1231
|
}
|
|
1232
|
+
fromVersion = normalizeVersion(answer);
|
|
1018
1233
|
}
|
|
1019
|
-
await
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
)
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
);
|
|
1034
|
-
const registryPath = path7.join(projectDir, "convex", "pluginRegistry.ts");
|
|
1035
|
-
await applyPluginsFn(
|
|
1036
|
-
state.plugins,
|
|
1037
|
-
registryPath,
|
|
1038
|
-
fs
|
|
1039
|
-
);
|
|
1040
|
-
const identity = {
|
|
1041
|
-
siteName: "",
|
|
1042
|
-
siteUrl: "",
|
|
1043
|
-
siteDescription: "",
|
|
1044
|
-
authorName: "",
|
|
1045
|
-
authorEmail: "",
|
|
1046
|
-
twitterHandle: "",
|
|
1047
|
-
lang: "pt-BR",
|
|
1048
|
-
seoHomeTitle: "",
|
|
1049
|
-
seoHomeDescription: "",
|
|
1050
|
-
rssTitle: "",
|
|
1051
|
-
rssDescription: "",
|
|
1052
|
-
ogImageUrl: "",
|
|
1053
|
-
fontSans: state.fontSans,
|
|
1054
|
-
fontMono: state.fontMono
|
|
1055
|
-
};
|
|
1056
|
-
await applyIndexHtmlFn(
|
|
1057
|
-
{
|
|
1058
|
-
fontFamily: identity.fontSans,
|
|
1059
|
-
themeColor: "",
|
|
1060
|
-
siteName: identity.siteName,
|
|
1061
|
-
siteUrl: identity.siteUrl,
|
|
1062
|
-
twitterHandle: identity.twitterHandle,
|
|
1063
|
-
authorName: identity.authorName
|
|
1064
|
-
},
|
|
1065
|
-
htmlPath,
|
|
1066
|
-
fs
|
|
1067
|
-
);
|
|
1068
|
-
await applyRubricalConfigFn(
|
|
1069
|
-
identity,
|
|
1070
|
-
projectDir,
|
|
1071
|
-
fs
|
|
1072
|
-
);
|
|
1073
|
-
await writeStateFn(projectDir, { version: remoteVersion }, fs);
|
|
1074
|
-
const missingVars = await checkRequiredEnvFn(projectDir, fs);
|
|
1075
|
-
if (missingVars.length > 0) {
|
|
1076
|
-
const varList = missingVars.map((v) => ` \u2022 ${v.name} \u2014 ${v.description}`).join("\n");
|
|
1234
|
+
const toVersion = normalizeVersion(opts.to ?? await getLatestVersionFn());
|
|
1235
|
+
if (fromVersion === toVersion) {
|
|
1236
|
+
outro3(`J\xE1 est\xE1 na vers\xE3o mais recente (${toVersion}).`);
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
const status = await gitStatus(projectDir);
|
|
1240
|
+
if (!opts.dryRun) {
|
|
1241
|
+
if (status === null) {
|
|
1242
|
+
log2.warn("Este projeto n\xE3o est\xE1 num reposit\xF3rio git. Recomendado: fa\xE7a um backup antes, para poder desfazer.");
|
|
1243
|
+
} else if (status !== "") {
|
|
1244
|
+
log2.warn("H\xE1 mudan\xE7as n\xE3o commitadas. Recomendado: fa\xE7a commit antes, para poder desfazer o update com o git.");
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
if (parseMajor(toVersion) > parseMajor(fromVersion)) {
|
|
1077
1248
|
log2.warn(
|
|
1078
|
-
`
|
|
1079
|
-
|
|
1080
|
-
Configure-as em: https://dashboard.convex.dev`
|
|
1249
|
+
`Atualiza\xE7\xE3o de vers\xE3o major: ${fromVersion} \u2192 ${toVersion}.
|
|
1250
|
+
Leia o guia de atualiza\xE7\xE3o nas notas da release antes de publicar.`
|
|
1081
1251
|
);
|
|
1082
1252
|
}
|
|
1083
|
-
|
|
1253
|
+
const workDir = await fs2.mkdtemp(path9.join(tmpdir3(), "rubrica-update-"));
|
|
1254
|
+
const baseDir = path9.join(workDir, "base");
|
|
1255
|
+
const nextDir = path9.join(workDir, "next");
|
|
1256
|
+
let packageName;
|
|
1257
|
+
try {
|
|
1258
|
+
packageName = JSON.parse(await fs2.readFile(path9.join(projectDir, "package.json"), "utf-8")).name;
|
|
1259
|
+
} catch {
|
|
1260
|
+
packageName = void 0;
|
|
1261
|
+
}
|
|
1262
|
+
const s = spinner();
|
|
1263
|
+
try {
|
|
1264
|
+
s.start(`Baixando ${fromVersion} e ${toVersion}`);
|
|
1265
|
+
await buildPristine({ dir: baseDir, version: fromVersion, state, packageName, download });
|
|
1266
|
+
await buildPristine({ dir: nextDir, version: toVersion, state, packageName, download });
|
|
1267
|
+
s.stop("Vers\xF5es baixadas");
|
|
1268
|
+
s.start("Comparando com o seu projeto");
|
|
1269
|
+
const actions = await planUpdate({ base: baseDir, next: nextDir, project: projectDir });
|
|
1270
|
+
s.stop("Compara\xE7\xE3o conclu\xEDda");
|
|
1271
|
+
log2.info(`${fromVersion} \u2192 ${toVersion}
|
|
1272
|
+
|
|
1273
|
+
${formatPlan(actions)}`);
|
|
1274
|
+
if (opts.dryRun) {
|
|
1275
|
+
outro3("Simula\xE7\xE3o: nada foi gravado.");
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
if (ask) {
|
|
1279
|
+
const proceed = await confirm3({ message: `Aplicar a atualiza\xE7\xE3o para ${toVersion}?` });
|
|
1280
|
+
if (isCancel4(proceed) || !proceed) {
|
|
1281
|
+
cancel4("Atualiza\xE7\xE3o cancelada.");
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
await applyPlan(projectDir, actions);
|
|
1286
|
+
await writeState(projectDir, { version: toVersion });
|
|
1287
|
+
const changed = actions.filter((a) => ["update", "add", "remove", "merge"].includes(a.kind)).map((a) => a.file);
|
|
1288
|
+
const conflicts = actions.filter((a) => a.kind === "conflict");
|
|
1289
|
+
const steps = [];
|
|
1290
|
+
if (changed.includes("package.json") || actions.some((a) => a.kind === "lockfile")) {
|
|
1291
|
+
steps.push("Instale as depend\xEAncias: pnpm install (ou npm install)");
|
|
1292
|
+
}
|
|
1293
|
+
if (changed.some((f) => f.startsWith("convex/"))) {
|
|
1294
|
+
steps.push("Publique o backend: npx convex dev --once (dev) e, depois de testar, npx convex deploy (produ\xE7\xE3o)");
|
|
1295
|
+
}
|
|
1296
|
+
if (conflicts.length) {
|
|
1297
|
+
steps.push(
|
|
1298
|
+
`Revise ${conflicts.length} arquivo(s) com conflito: compare cada um com o ${NEW_SUFFIX} ao lado, leve o que quiser da vers\xE3o nova e apague o ${NEW_SUFFIX}`
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
steps.push("Rode o site (pnpm dev) e confira antes de publicar");
|
|
1302
|
+
const missingVars = await checkRequiredEnvFn(projectDir, fs2);
|
|
1303
|
+
if (missingVars.length > 0) {
|
|
1304
|
+
log2.warn(
|
|
1305
|
+
`Vari\xE1veis de ambiente faltando no Convex:
|
|
1306
|
+
` + missingVars.map((v) => ` \u2022 ${v.name} \u2014 ${v.description}`).join("\n")
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
outro3(`Atualizado para ${toVersion}.
|
|
1310
|
+
|
|
1311
|
+
Pr\xF3ximos passos:
|
|
1312
|
+
${steps.map((st, i) => ` ${i + 1}. ${st}`).join("\n")}`);
|
|
1313
|
+
} finally {
|
|
1314
|
+
await fs2.rm(workDir, { recursive: true, force: true });
|
|
1315
|
+
}
|
|
1084
1316
|
}
|
|
1085
1317
|
|
|
1086
1318
|
// src/commands/setup.ts
|
|
1087
|
-
import { outro as outro4, text as
|
|
1319
|
+
import { outro as outro4, text as text3, password, spinner as spinner2, isCancel as isCancel5, cancel as cancel5, log as log3 } from "@clack/prompts";
|
|
1088
1320
|
import * as nodeFsPromises13 from "fs/promises";
|
|
1089
|
-
import * as
|
|
1321
|
+
import * as path10 from "path";
|
|
1090
1322
|
import * as nodeCrypto from "crypto";
|
|
1091
1323
|
import { execFileSync as defaultExecFileSync } from "child_process";
|
|
1092
1324
|
|
|
@@ -1116,7 +1348,7 @@ function parseEnvFile(content) {
|
|
|
1116
1348
|
}
|
|
1117
1349
|
async function runSetup(deps = {}) {
|
|
1118
1350
|
const cwd = deps.cwd ?? process.cwd();
|
|
1119
|
-
const
|
|
1351
|
+
const fs3 = deps.fs ?? {
|
|
1120
1352
|
access: (p) => nodeFsPromises13.access(p).then(() => void 0),
|
|
1121
1353
|
readFile: (p, enc) => nodeFsPromises13.readFile(p, enc),
|
|
1122
1354
|
writeFile: (p, data) => nodeFsPromises13.writeFile(p, data).then(() => void 0),
|
|
@@ -1133,10 +1365,10 @@ async function runSetup(deps = {}) {
|
|
|
1133
1365
|
cancel5(err.message);
|
|
1134
1366
|
return;
|
|
1135
1367
|
}
|
|
1136
|
-
const envPath =
|
|
1368
|
+
const envPath = path10.join(cwd, ".env.local");
|
|
1137
1369
|
let envVars = {};
|
|
1138
1370
|
try {
|
|
1139
|
-
const envContent = await
|
|
1371
|
+
const envContent = await fs3.readFile(envPath, "utf-8");
|
|
1140
1372
|
envVars = parseEnvFile(envContent);
|
|
1141
1373
|
} catch {
|
|
1142
1374
|
cancel5(
|
|
@@ -1157,7 +1389,7 @@ async function runSetup(deps = {}) {
|
|
|
1157
1389
|
return;
|
|
1158
1390
|
}
|
|
1159
1391
|
const siteUrlDefault = envVars["VITE_CONVEX_SITE_URL"];
|
|
1160
|
-
const s =
|
|
1392
|
+
const s = spinner2();
|
|
1161
1393
|
s.start("Gerando chaves JWT (RS256)...");
|
|
1162
1394
|
const { JWT_PRIVATE_KEY, JWKS } = await generateJwtKeys2();
|
|
1163
1395
|
s.stop("Chaves JWT geradas.");
|
|
@@ -1167,7 +1399,7 @@ async function runSetup(deps = {}) {
|
|
|
1167
1399
|
execFileSync("npx", ["convex", "env", "set", "--", "JWKS", JWKS], {
|
|
1168
1400
|
stdio: "pipe"
|
|
1169
1401
|
});
|
|
1170
|
-
const siteUrl = await
|
|
1402
|
+
const siteUrl = await text3({
|
|
1171
1403
|
message: "URL p\xFAblica do site (SITE_URL no Convex):",
|
|
1172
1404
|
initialValue: siteUrlDefault,
|
|
1173
1405
|
validate: (v) => {
|
|
@@ -1182,17 +1414,17 @@ async function runSetup(deps = {}) {
|
|
|
1182
1414
|
execFileSync("npx", ["convex", "env", "set", "--", "SITE_URL", siteUrl], {
|
|
1183
1415
|
stdio: "pipe"
|
|
1184
1416
|
});
|
|
1185
|
-
const state = await readState2(cwd,
|
|
1417
|
+
const state = await readState2(cwd, fs3);
|
|
1186
1418
|
const plugins = state.plugins;
|
|
1187
1419
|
if (plugins["contact-wizard"] || plugins["testimonials-intake"]) {
|
|
1188
|
-
const telegramToken = await
|
|
1420
|
+
const telegramToken = await text3({
|
|
1189
1421
|
message: "TELEGRAM_BOT_TOKEN (Enter para pular):",
|
|
1190
1422
|
initialValue: ""
|
|
1191
1423
|
});
|
|
1192
1424
|
if (!isCancel5(telegramToken) && telegramToken && telegramToken.trim()) {
|
|
1193
1425
|
execFileSync("npx", ["convex", "env", "set", "--", "TELEGRAM_BOT_TOKEN", telegramToken], { stdio: "pipe" });
|
|
1194
1426
|
}
|
|
1195
|
-
const telegramChatId = await
|
|
1427
|
+
const telegramChatId = await text3({
|
|
1196
1428
|
message: "TELEGRAM_ADMIN_CHAT_ID (Enter para pular):",
|
|
1197
1429
|
initialValue: ""
|
|
1198
1430
|
});
|
|
@@ -1205,7 +1437,7 @@ async function runSetup(deps = {}) {
|
|
|
1205
1437
|
execFileSync("npx", ["convex", "env", "set", "--", "PLAYGROUND_KEY_PEPPER", pepper], { stdio: "pipe" });
|
|
1206
1438
|
}
|
|
1207
1439
|
if (plugins["ai-resumes"] || plugins["i18n"] || plugins["playground"]) {
|
|
1208
|
-
const openrouterKey = await
|
|
1440
|
+
const openrouterKey = await text3({
|
|
1209
1441
|
message: "OPENROUTER_API_KEY (Enter para pular):",
|
|
1210
1442
|
initialValue: ""
|
|
1211
1443
|
});
|
|
@@ -1214,22 +1446,28 @@ async function runSetup(deps = {}) {
|
|
|
1214
1446
|
}
|
|
1215
1447
|
}
|
|
1216
1448
|
if (plugins["payments"]) {
|
|
1217
|
-
const
|
|
1218
|
-
message: "
|
|
1219
|
-
initialValue: ""
|
|
1220
|
-
});
|
|
1221
|
-
if (!isCancel5(stripeSecret) && stripeSecret && stripeSecret.trim()) {
|
|
1222
|
-
execFileSync("npx", ["convex", "env", "set", "--", "STRIPE_WEBHOOK_SECRET", stripeSecret], { stdio: "pipe" });
|
|
1223
|
-
}
|
|
1224
|
-
const asaasToken = await text2({
|
|
1225
|
-
message: "ASAAS_WEBHOOK_TOKEN (Enter para pular):",
|
|
1449
|
+
const asaasKey = await text3({
|
|
1450
|
+
message: "ASAAS_API_KEY \u2014 chave da API do Asaas, sandbox ou produ\xE7\xE3o (Enter para pular):",
|
|
1226
1451
|
initialValue: ""
|
|
1227
1452
|
});
|
|
1228
|
-
if (!isCancel5(
|
|
1229
|
-
|
|
1453
|
+
if (!isCancel5(asaasKey) && asaasKey && asaasKey.trim()) {
|
|
1454
|
+
const key = asaasKey.trim();
|
|
1455
|
+
execFileSync("npx", ["convex", "env", "set", "--", "ASAAS_API_KEY", key], { stdio: "pipe" });
|
|
1456
|
+
const webhookToken = randomBytes2(32).toString("hex");
|
|
1457
|
+
execFileSync("npx", ["convex", "env", "set", "--", "ASAAS_WEBHOOK_TOKEN", webhookToken], { stdio: "pipe" });
|
|
1458
|
+
const env = key.startsWith("$aact_prod_") ? "produ\xE7\xE3o" : "sandbox (testes)";
|
|
1459
|
+
log3.info(
|
|
1460
|
+
`Asaas configurado em ${env}. Falta cadastrar o webhook no painel do Asaas
|
|
1461
|
+
(Integra\xE7\xF5es \u2192 Webhooks \u2192 Adicionar), com os eventos de cobran\xE7a ligados:
|
|
1462
|
+
|
|
1463
|
+
URL: ${siteUrlDefault.replace(/\/+$/, "")}/webhooks/asaas
|
|
1464
|
+
Token: ${webhookToken}
|
|
1465
|
+
|
|
1466
|
+
Sem o webhook, os pagamentos nunca aparecem como pagos.`
|
|
1467
|
+
);
|
|
1230
1468
|
}
|
|
1231
1469
|
}
|
|
1232
|
-
const adminEmail = await
|
|
1470
|
+
const adminEmail = await text3({
|
|
1233
1471
|
message: "Email do usu\xE1rio root:",
|
|
1234
1472
|
validate: (v) => {
|
|
1235
1473
|
if (!v.includes("@") || !v.includes("."))
|
|
@@ -1292,7 +1530,7 @@ async function runSetup(deps = {}) {
|
|
|
1292
1530
|
try {
|
|
1293
1531
|
execFileSync(
|
|
1294
1532
|
"npx",
|
|
1295
|
-
["convex", "run", "siteConfig:
|
|
1533
|
+
["convex", "run", "siteConfig:setBatchInternal", JSON.stringify({
|
|
1296
1534
|
items: [
|
|
1297
1535
|
{ key: "site_title", value: identity.siteName },
|
|
1298
1536
|
{ key: "site_name", value: identity.siteName },
|
|
@@ -1312,7 +1550,7 @@ async function runSetup(deps = {}) {
|
|
|
1312
1550
|
try {
|
|
1313
1551
|
execFileSync(
|
|
1314
1552
|
"npx",
|
|
1315
|
-
["convex", "run", "contactInfo:
|
|
1553
|
+
["convex", "run", "contactInfo:updateInternal", JSON.stringify({
|
|
1316
1554
|
name: identity.authorName,
|
|
1317
1555
|
email: identity.authorEmail || "",
|
|
1318
1556
|
showEmail: false
|
|
@@ -1323,26 +1561,26 @@ async function runSetup(deps = {}) {
|
|
|
1323
1561
|
}
|
|
1324
1562
|
}
|
|
1325
1563
|
}
|
|
1326
|
-
const vercelHookUrl = await
|
|
1564
|
+
const vercelHookUrl = await text3({
|
|
1327
1565
|
message: "VERCEL_DEPLOY_HOOK_URL (Enter para pular):",
|
|
1328
1566
|
initialValue: ""
|
|
1329
1567
|
});
|
|
1330
1568
|
if (!isCancel5(vercelHookUrl) && vercelHookUrl && vercelHookUrl.trim()) {
|
|
1331
1569
|
execFileSync("npx", ["convex", "env", "set", "--", "VERCEL_DEPLOY_HOOK_URL", vercelHookUrl], { stdio: "pipe" });
|
|
1332
1570
|
}
|
|
1333
|
-
const vercelWebhookSecret = await
|
|
1571
|
+
const vercelWebhookSecret = await text3({
|
|
1334
1572
|
message: "VERCEL_WEBHOOK_SECRET (Enter para pular):",
|
|
1335
1573
|
initialValue: ""
|
|
1336
1574
|
});
|
|
1337
1575
|
if (!isCancel5(vercelWebhookSecret) && vercelWebhookSecret && vercelWebhookSecret.trim()) {
|
|
1338
1576
|
execFileSync("npx", ["convex", "env", "set", "--", "VERCEL_WEBHOOK_SECRET", vercelWebhookSecret], { stdio: "pipe" });
|
|
1339
1577
|
}
|
|
1340
|
-
const profession = await
|
|
1578
|
+
const profession = await text3({
|
|
1341
1579
|
message: "Qual \xE9 a sua profiss\xE3o ou \xE1rea de atua\xE7\xE3o? (Enter para usar padr\xE3o tech)",
|
|
1342
1580
|
placeholder: "Ex: Designer UX, Fot\xF3grafa, Advogada, Engenheira Civil...",
|
|
1343
1581
|
initialValue: ""
|
|
1344
1582
|
});
|
|
1345
|
-
const specialties = await
|
|
1583
|
+
const specialties = await text3({
|
|
1346
1584
|
message: "Quais s\xE3o suas principais especialidades? (separadas por v\xEDrgula, Enter para pular)",
|
|
1347
1585
|
placeholder: "Ex: Branding, Motion Design, Fotografia de Produto",
|
|
1348
1586
|
initialValue: ""
|
|
@@ -1370,7 +1608,7 @@ async function runSetup(deps = {}) {
|
|
|
1370
1608
|
try {
|
|
1371
1609
|
execFileSync(
|
|
1372
1610
|
"npx",
|
|
1373
|
-
["convex", "run", "contactInfo:
|
|
1611
|
+
["convex", "run", "contactInfo:updateInternal", JSON.stringify({ proposalAiContext: aiContext })],
|
|
1374
1612
|
{ stdio: "pipe" }
|
|
1375
1613
|
);
|
|
1376
1614
|
} catch {
|
|
@@ -1400,14 +1638,30 @@ async function runCli(argv, cwd) {
|
|
|
1400
1638
|
} else if (command === "config") {
|
|
1401
1639
|
await runConfig({ cwd });
|
|
1402
1640
|
} else if (command === "update") {
|
|
1403
|
-
await runUpdate({ cwd });
|
|
1641
|
+
await runUpdate({ cwd, options: parseUpdateOptions(argv.slice(3)) });
|
|
1404
1642
|
} else if (command === "setup") {
|
|
1405
1643
|
await runSetup({ cwd });
|
|
1644
|
+
} else if (command && !command.startsWith("-")) {
|
|
1645
|
+
await runCreate(command, { projectsDir: cwd });
|
|
1406
1646
|
} else {
|
|
1407
|
-
console.log(
|
|
1647
|
+
console.log(
|
|
1648
|
+
"Comandos dispon\xEDveis: create <nome-do-projeto> | config | setup\n update [--dry-run] [--from <vers\xE3o>] [--to <vers\xE3o>] [--yes]"
|
|
1649
|
+
);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
function parseUpdateOptions(args) {
|
|
1653
|
+
const options = {};
|
|
1654
|
+
for (let i = 0; i < args.length; i++) {
|
|
1655
|
+
const arg = args[i];
|
|
1656
|
+
if (arg === "--dry-run") options.dryRun = true;
|
|
1657
|
+
else if (arg === "--yes" || arg === "-y") options.yes = true;
|
|
1658
|
+
else if (arg === "--from") options.from = args[++i];
|
|
1659
|
+
else if (arg === "--to") options.to = args[++i];
|
|
1408
1660
|
}
|
|
1661
|
+
return options;
|
|
1409
1662
|
}
|
|
1410
1663
|
await runCli(process.argv, process.cwd());
|
|
1411
1664
|
export {
|
|
1665
|
+
parseUpdateOptions,
|
|
1412
1666
|
runCli
|
|
1413
1667
|
};
|