create-portfoliable 1.2.17 → 1.3.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/bin/create-portfoliable.mjs +19 -0
- package/cli/portfoliable.mjs +37 -27
- package/package.json +1 -1
- package/scripts/package-updates.mjs +41 -0
- package/vite.config.js +2 -2
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
readProjectUiPreferences,
|
|
17
17
|
writeProjectUiPreferences
|
|
18
18
|
} from '../scripts/terminal-ui.mjs';
|
|
19
|
+
import { findPackageUpdates } from '../scripts/package-updates.mjs';
|
|
19
20
|
|
|
20
21
|
// MARK: DEFAULTS
|
|
21
22
|
// Defines default target folder when no project name is provided.
|
|
@@ -385,6 +386,24 @@ async function run() {
|
|
|
385
386
|
printRailSegment({ dot: true, label: `${color('32', 'Dependencies installed.')}` });
|
|
386
387
|
console.log(color('36', 'Command guide is available after launch via interactive prompt.'));
|
|
387
388
|
|
|
389
|
+
const installedPackages = [
|
|
390
|
+
['create-portfoliable', path.resolve(targetDir, 'node_modules', 'create-portfoliable', 'package.json')],
|
|
391
|
+
['@portfoliablejs/valence', path.resolve(targetDir, 'node_modules', '@portfoliablejs', 'valence', 'package.json')]
|
|
392
|
+
].flatMap(([name, packagePath]) => {
|
|
393
|
+
try {
|
|
394
|
+
return [{ name, currentVersion: JSON.parse(fs.readFileSync(packagePath, 'utf8')).version }];
|
|
395
|
+
} catch {
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
const updates = await findPackageUpdates(installedPackages);
|
|
400
|
+
for (const update of updates) {
|
|
401
|
+
const isValence = update.name === '@portfoliablejs/valence';
|
|
402
|
+
const label = isValence ? 'design system' : 'Portfoliable';
|
|
403
|
+
console.log(color('33', `A new ${label} update (${update.latestVersion}) is available.`));
|
|
404
|
+
console.log(`Run: ${color('32', `npm update ${update.name}`)}`);
|
|
405
|
+
}
|
|
406
|
+
|
|
388
407
|
if (options.launch) {
|
|
389
408
|
printRailSegment();
|
|
390
409
|
printRailSegment({ dot: true, label: `${color('36', 'Preparing first build...')}` });
|
package/cli/portfoliable.mjs
CHANGED
|
@@ -27,6 +27,15 @@ import {
|
|
|
27
27
|
readProjectUiPreferences
|
|
28
28
|
} from '../scripts/terminal-ui.mjs';
|
|
29
29
|
import { resolveConsumerRuntimeAliases } from '../scripts/consumer-runtime-aliases.mjs';
|
|
30
|
+
import { findPackageUpdates } from '../scripts/package-updates.mjs';
|
|
31
|
+
|
|
32
|
+
function resolveMermaidDevAliases(runtimeAliases) {
|
|
33
|
+
return [
|
|
34
|
+
...runtimeAliases,
|
|
35
|
+
{ find: /^dayjs$/, replacement: path.resolve(process.cwd(), 'node_modules/dayjs/esm/index.js') },
|
|
36
|
+
{ find: 'dayjs/dayjs.min.js', replacement: path.resolve(process.cwd(), 'node_modules/dayjs/esm/index.js') }
|
|
37
|
+
];
|
|
38
|
+
}
|
|
30
39
|
|
|
31
40
|
// MARK: TERMINAL STYLES
|
|
32
41
|
// ANSI color code used for success-status text.
|
|
@@ -75,21 +84,6 @@ function firstNetworkAddress() {
|
|
|
75
84
|
return null;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
// Fetches latest published create-portfoliable version from npm registry.
|
|
79
|
-
async function fetchLatestVersion() {
|
|
80
|
-
try {
|
|
81
|
-
// Calls npm metadata endpoint for latest dist-tag payload.
|
|
82
|
-
const response = await fetch('https://registry.npmjs.org/create-portfoliable/latest');
|
|
83
|
-
if (!response.ok) return null;
|
|
84
|
-
|
|
85
|
-
// Parses registry response payload.
|
|
86
|
-
const data = await response.json();
|
|
87
|
-
return data.version || null;
|
|
88
|
-
} catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
87
|
// MARK: CLI ARGUMENT PARSING
|
|
94
88
|
// Parses command and flags from argv into normalized runtime options.
|
|
95
89
|
function parseCliArgs(argv) {
|
|
@@ -488,7 +482,7 @@ function createCaseContentAssetPlugin() {
|
|
|
488
482
|
}
|
|
489
483
|
|
|
490
484
|
// Prints startup summary box for dev server sessions.
|
|
491
|
-
function printStartupBox({ localUrl, networkUrl,
|
|
485
|
+
function printStartupBox({ localUrl, networkUrl, updates }) {
|
|
492
486
|
const lines = [
|
|
493
487
|
`${green}${bold}Portfoliable ready!${reset}`,
|
|
494
488
|
`${dim}Dev server is live and ready for editing.${reset}`,
|
|
@@ -499,13 +493,20 @@ function printStartupBox({ localUrl, networkUrl, localVersion, latestVersion })
|
|
|
499
493
|
`${bold}Next:${reset} open the local URL in your browser.`
|
|
500
494
|
];
|
|
501
495
|
|
|
502
|
-
|
|
496
|
+
for (const update of updates) {
|
|
503
497
|
lines.push('');
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
lines.push(
|
|
498
|
+
const isValence = update.name === '@portfoliablejs/valence';
|
|
499
|
+
const packageLabel = isValence ? 'design system' : 'Portfoliable';
|
|
500
|
+
lines.push(`${yellow}A new ${packageLabel} update (${update.latestVersion}) is available!${reset}`);
|
|
501
|
+
lines.push(`Upgrade now: ${green}npm update ${update.name}${reset}`);
|
|
502
|
+
if (!isValence) {
|
|
503
|
+
lines.push(`If it still persists, run: ${green}npm install ${update.name}@latest${reset}`);
|
|
504
|
+
}
|
|
507
505
|
lines.push('Read changelog:');
|
|
508
|
-
|
|
506
|
+
const changelogUrl = isValence
|
|
507
|
+
? 'https://github.com/portfoliablejs/valence/blob/main/CHANGELOG.md'
|
|
508
|
+
: 'https://github.com/portfoliablejs/portfoliable/blob/main/CHANGELOG.md';
|
|
509
|
+
lines.push(`${dim}${changelogUrl}${reset}`);
|
|
509
510
|
}
|
|
510
511
|
|
|
511
512
|
printRailAttachedBox({ width: 96, lines });
|
|
@@ -595,13 +596,13 @@ async function runDevServer(flags, options = {}) {
|
|
|
595
596
|
}
|
|
596
597
|
|
|
597
598
|
const runtimeAliases = resolveConsumerRuntimeAliases(process.cwd());
|
|
599
|
+
const mermaidDevAliases = resolveMermaidDevAliases(runtimeAliases);
|
|
598
600
|
|
|
599
601
|
// Creates Vite development server instance.
|
|
600
602
|
const server = await createServer({
|
|
601
|
-
resolve:
|
|
602
|
-
? { alias: runtimeAliases }
|
|
603
|
-
: undefined,
|
|
603
|
+
resolve: { alias: mermaidDevAliases },
|
|
604
604
|
optimizeDeps: {
|
|
605
|
+
include: ['mermaid', 'mermaid > dayjs'],
|
|
605
606
|
exclude: ['create-portfoliable']
|
|
606
607
|
},
|
|
607
608
|
server: {
|
|
@@ -626,15 +627,24 @@ async function runDevServer(flags, options = {}) {
|
|
|
626
627
|
|
|
627
628
|
// Resolves currently running CLI package version.
|
|
628
629
|
const localVersion = resolvePackageVersion();
|
|
629
|
-
|
|
630
|
-
|
|
630
|
+
const valencePackagePath = path.resolve(process.cwd(), 'node_modules', '@portfoliablejs', 'valence', 'package.json');
|
|
631
|
+
let valenceVersion = null;
|
|
632
|
+
try {
|
|
633
|
+
valenceVersion = JSON.parse(fs.readFileSync(valencePackagePath, 'utf8')).version || null;
|
|
634
|
+
} catch {
|
|
635
|
+
valenceVersion = null;
|
|
636
|
+
}
|
|
637
|
+
const updates = await findPackageUpdates([
|
|
638
|
+
{ name: 'create-portfoliable', currentVersion: localVersion },
|
|
639
|
+
...(valenceVersion ? [{ name: '@portfoliablejs/valence', currentVersion: valenceVersion }] : [])
|
|
640
|
+
]);
|
|
631
641
|
|
|
632
642
|
if (fancyDots) {
|
|
633
643
|
printRailSegment({ dot: true, label: `${cyan}${bold}Starting...${reset}` });
|
|
634
644
|
printRailSpacer();
|
|
635
645
|
}
|
|
636
646
|
|
|
637
|
-
printStartupBox({ localUrl, networkUrl,
|
|
647
|
+
printStartupBox({ localUrl, networkUrl, updates });
|
|
638
648
|
|
|
639
649
|
if (isInteractiveTerminal() && flags.open !== false) {
|
|
640
650
|
let showCommands = false;
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const PACKAGE_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
2
|
+
|
|
3
|
+
function parseVersion(version) {
|
|
4
|
+
const match = String(version || '').trim().match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
5
|
+
return match ? match.slice(1).map(Number) : null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function isNewerVersion(latestVersion, currentVersion) {
|
|
9
|
+
const latest = parseVersion(latestVersion);
|
|
10
|
+
const current = parseVersion(currentVersion);
|
|
11
|
+
if (!latest || !current) return false;
|
|
12
|
+
|
|
13
|
+
for (let index = 0; index < latest.length; index += 1) {
|
|
14
|
+
if (latest[index] !== current[index]) return latest[index] > current[index];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function fetchLatestPackageVersion(packageName) {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(`${PACKAGE_REGISTRY_URL}/${encodeURIComponent(packageName)}/latest`);
|
|
23
|
+
if (!response.ok) return null;
|
|
24
|
+
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
return data.version || null;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function findPackageUpdates(packages) {
|
|
33
|
+
const updates = await Promise.all(packages.map(async ({ name, currentVersion }) => {
|
|
34
|
+
const latestVersion = await fetchLatestPackageVersion(name);
|
|
35
|
+
if (!latestVersion || !isNewerVersion(latestVersion, currentVersion)) return null;
|
|
36
|
+
|
|
37
|
+
return { name, currentVersion, latestVersion };
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
return updates.filter(Boolean);
|
|
41
|
+
}
|
package/vite.config.js
CHANGED
|
@@ -94,8 +94,8 @@ export default defineConfig(({ command }) => {
|
|
|
94
94
|
? { alias: runtimeAliases }
|
|
95
95
|
: undefined,
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
//
|
|
97
|
+
// Keep Mermaid's CommonJS dependencies in Vite's normalized dev graph while
|
|
98
|
+
// avoiding prebundling Valence so linked-package edits remain observable.
|
|
99
99
|
optimizeDeps: (command === 'serve' && usingLocalValence)
|
|
100
100
|
? { exclude: ['@portfoliablejs/valence'] }
|
|
101
101
|
: undefined,
|