storyblok 4.2.1 → 4.3.1
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/dist/index.mjs +85 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import fs, { mkdir, writeFile, readFile as readFile$1, access, readdir } from 'n
|
|
|
11
11
|
import path, { join, parse, resolve } from 'node:path';
|
|
12
12
|
import { exec, spawn } from 'node:child_process';
|
|
13
13
|
import { promisify } from 'node:util';
|
|
14
|
+
import { getRegion } from '@storyblok/region-helper';
|
|
14
15
|
import { minimatch } from 'minimatch';
|
|
15
16
|
import { hash } from 'ohash';
|
|
16
17
|
import { compile } from 'json-schema-to-typescript';
|
|
@@ -25,9 +26,9 @@ const commands = {
|
|
|
25
26
|
USER: "user",
|
|
26
27
|
COMPONENTS: "components",
|
|
27
28
|
LANGUAGES: "languages",
|
|
28
|
-
MIGRATIONS: "
|
|
29
|
-
TYPES: "
|
|
30
|
-
DATASOURCES: "
|
|
29
|
+
MIGRATIONS: "migrations",
|
|
30
|
+
TYPES: "types",
|
|
31
|
+
DATASOURCES: "datasources",
|
|
31
32
|
CREATE: "create"
|
|
32
33
|
};
|
|
33
34
|
const colorPalette = {
|
|
@@ -441,9 +442,9 @@ function formatHeader(title) {
|
|
|
441
442
|
const konsola = {
|
|
442
443
|
title: (message, color, subtitle) => {
|
|
443
444
|
if (subtitle) {
|
|
444
|
-
console.log(`${formatHeader(chalk.bgHex(color).bold(` ${message} `))} ${subtitle}`);
|
|
445
|
+
console.log(`${formatHeader(chalk.bgHex(color).bold(` ${capitalize(message)} `))} ${subtitle}`);
|
|
445
446
|
} else {
|
|
446
|
-
console.log(formatHeader(chalk.bgHex(color).bold(` ${message} `)));
|
|
447
|
+
console.log(formatHeader(chalk.bgHex(color).bold(` ${capitalize(message)} `)));
|
|
447
448
|
}
|
|
448
449
|
console.log("");
|
|
449
450
|
console.log("");
|
|
@@ -773,7 +774,7 @@ program$i.command(commands.LOGIN).description("Login to the Storyblok CLI").opti
|
|
|
773
774
|
"-r, --region <region>",
|
|
774
775
|
`The region you would like to work in. Please keep in mind that the region must match the region of your space. This region flag will be used for the other cli's commands. You can use the values: ${allRegionsText}.`
|
|
775
776
|
).action(async (options) => {
|
|
776
|
-
konsola.title(
|
|
777
|
+
konsola.title(`${commands.LOGIN}`, colorPalette.LOGIN);
|
|
777
778
|
const verbose = program$i.opts().verbose;
|
|
778
779
|
const { token, region } = options;
|
|
779
780
|
const { state, updateSession, persistCredentials, initializeSession } = session();
|
|
@@ -895,7 +896,7 @@ program$i.command(commands.LOGIN).description("Login to the Storyblok CLI").opti
|
|
|
895
896
|
|
|
896
897
|
const program$h = getProgram();
|
|
897
898
|
program$h.command(commands.LOGOUT).description("Logout from the Storyblok CLI").action(async () => {
|
|
898
|
-
konsola.title(
|
|
899
|
+
konsola.title(`${commands.LOGOUT}`, colorPalette.LOGOUT);
|
|
899
900
|
const verbose = program$h.opts().verbose;
|
|
900
901
|
try {
|
|
901
902
|
const { state, initializeSession } = session();
|
|
@@ -946,7 +947,7 @@ async function openSignupInBrowser(url) {
|
|
|
946
947
|
|
|
947
948
|
const program$g = getProgram();
|
|
948
949
|
program$g.command(commands.SIGNUP).description("Sign up for Storyblok").action(async () => {
|
|
949
|
-
konsola.title(
|
|
950
|
+
konsola.title(`${commands.SIGNUP}`, colorPalette.SIGNUP);
|
|
950
951
|
const verbose = program$g.opts().verbose;
|
|
951
952
|
const { state, initializeSession } = session();
|
|
952
953
|
await initializeSession();
|
|
@@ -995,7 +996,7 @@ const getUser = async (token, region) => {
|
|
|
995
996
|
|
|
996
997
|
const program$f = getProgram();
|
|
997
998
|
program$f.command(commands.USER).description("Get the current user").action(async () => {
|
|
998
|
-
konsola.title(
|
|
999
|
+
konsola.title(`${commands.USER}`, colorPalette.USER);
|
|
999
1000
|
const { state, initializeSession } = session();
|
|
1000
1001
|
await initializeSession();
|
|
1001
1002
|
if (!requireAuthentication(state)) {
|
|
@@ -1019,8 +1020,30 @@ program$f.command(commands.USER).description("Get the current user").action(asyn
|
|
|
1019
1020
|
konsola.br();
|
|
1020
1021
|
});
|
|
1021
1022
|
|
|
1023
|
+
function getRegionFromSpaceId(spaceId) {
|
|
1024
|
+
try {
|
|
1025
|
+
const region = getRegion(spaceId);
|
|
1026
|
+
return region;
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
console.warn(`Failed to determine region from space ID: ${error}`);
|
|
1029
|
+
return void 0;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const resolveRegion = async (thisCommand) => {
|
|
1033
|
+
const options = thisCommand.opts();
|
|
1034
|
+
const spaceId = options.space;
|
|
1035
|
+
if (spaceId) {
|
|
1036
|
+
const { state, initializeSession } = session();
|
|
1037
|
+
await initializeSession();
|
|
1038
|
+
const detectedRegion = getRegionFromSpaceId(spaceId);
|
|
1039
|
+
if (detectedRegion) {
|
|
1040
|
+
state.region = detectedRegion;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1022
1045
|
const program$e = getProgram();
|
|
1023
|
-
const componentsCommand = program$e.command(
|
|
1046
|
+
const componentsCommand = program$e.command(commands.COMPONENTS).alias("comp").description(`Manage your space's block schema`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/components").hook("preAction", resolveRegion);
|
|
1024
1047
|
|
|
1025
1048
|
let instance = null;
|
|
1026
1049
|
const createMapiClient = (options) => {
|
|
@@ -1480,7 +1503,7 @@ async function readConsolidatedFiles$1(resolvedPath, suffix) {
|
|
|
1480
1503
|
|
|
1481
1504
|
const program$d = getProgram();
|
|
1482
1505
|
componentsCommand.command("pull [componentName]").option("-f, --filename <filename>", "custom name to be used in file(s) name instead of space id").option("--sf, --separate-files", "Argument to create a single file for each component").option("--su, --suffix <suffix>", "suffix to add to the file name (e.g. components.<suffix>.json)").description(`Download your space's components schema as json. Optionally specify a component name to pull a single component.`).action(async (componentName, options) => {
|
|
1483
|
-
konsola.title(
|
|
1506
|
+
konsola.title(`${commands.COMPONENTS}`, colorPalette.COMPONENTS, componentName ? `Pulling component ${componentName}...` : "Pulling components...");
|
|
1484
1507
|
const verbose = program$d.opts().verbose;
|
|
1485
1508
|
const { space, path } = componentsCommand.opts();
|
|
1486
1509
|
const { separateFiles, suffix, filename = "components" } = options;
|
|
@@ -2760,7 +2783,7 @@ const saveDatasourcesToFiles = async (space, datasources, options) => {
|
|
|
2760
2783
|
|
|
2761
2784
|
const program$c = getProgram();
|
|
2762
2785
|
componentsCommand.command("push [componentName]").description(`Push your space's components schema as json`).option("-f, --from <from>", "source space id").option("--fi, --filter <filter>", "glob filter to apply to the components before pushing").option("--sf, --separate-files", "Read from separate files instead of consolidated files").option("--su, --suffix <suffix>", "Suffix to add to the component name").action(async (componentName, options) => {
|
|
2763
|
-
konsola.title(
|
|
2786
|
+
konsola.title(`${commands.COMPONENTS}`, colorPalette.COMPONENTS, componentName ? `Pushing component ${componentName}...` : "Pushing components...");
|
|
2764
2787
|
const verbose = program$c.opts().verbose;
|
|
2765
2788
|
const { space, path } = componentsCommand.opts();
|
|
2766
2789
|
const { from, filter } = options;
|
|
@@ -2916,9 +2939,9 @@ const saveLanguagesToFile = async (space, internationalizationOptions, options)
|
|
|
2916
2939
|
};
|
|
2917
2940
|
|
|
2918
2941
|
const program$b = getProgram();
|
|
2919
|
-
const languagesCommand = program$b.command(
|
|
2942
|
+
const languagesCommand = program$b.command(commands.LANGUAGES).alias("lang").description(`Manage your space's languages`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/languages").hook("preAction", resolveRegion);
|
|
2920
2943
|
languagesCommand.command("pull").description(`Download your space's languages schema as json`).option("-f, --filename <filename>", "filename to save the file as <filename>.<suffix>.json").option("--su, --suffix <suffix>", "suffix to add to the file name (e.g. languages.<suffix>.json). By default, the space ID is used.").action(async (options) => {
|
|
2921
|
-
konsola.title(
|
|
2944
|
+
konsola.title(`${commands.LANGUAGES}`, colorPalette.LANGUAGES);
|
|
2922
2945
|
const verbose = program$b.opts().verbose;
|
|
2923
2946
|
const { space, path } = languagesCommand.opts();
|
|
2924
2947
|
const { filename = "languages", suffix = options.space } = options;
|
|
@@ -2961,7 +2984,7 @@ languagesCommand.command("pull").description(`Download your space's languages sc
|
|
|
2961
2984
|
});
|
|
2962
2985
|
|
|
2963
2986
|
const program$a = getProgram();
|
|
2964
|
-
const migrationsCommand = program$a.command(
|
|
2987
|
+
const migrationsCommand = program$a.command(commands.MIGRATIONS).alias("mig").description(`Manage your space's migrations`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/migrations").hook("preAction", resolveRegion);
|
|
2965
2988
|
|
|
2966
2989
|
const getMigrationTemplate = () => {
|
|
2967
2990
|
return `export default function (block) {
|
|
@@ -2991,7 +3014,7 @@ const generateMigration = async (space, path, component, suffix) => {
|
|
|
2991
3014
|
|
|
2992
3015
|
const program$9 = getProgram();
|
|
2993
3016
|
migrationsCommand.command("generate [componentName]").description("Generate a migration file").option("--su, --suffix <suffix>", "suffix to add to the file name (e.g. {component-name}.<suffix>.js)").action(async (componentName, options) => {
|
|
2994
|
-
konsola.title(
|
|
3017
|
+
konsola.title(`${commands.MIGRATIONS}`, colorPalette.MIGRATIONS, componentName ? `Generating migration for component ${componentName}...` : "Generating migrations...");
|
|
2995
3018
|
const verbose = program$9.opts().verbose;
|
|
2996
3019
|
const { space, path } = migrationsCommand.opts();
|
|
2997
3020
|
const { suffix } = options;
|
|
@@ -3034,9 +3057,9 @@ migrationsCommand.command("generate [componentName]").description("Generate a mi
|
|
|
3034
3057
|
}
|
|
3035
3058
|
});
|
|
3036
3059
|
|
|
3037
|
-
const fetchStories = async (space,
|
|
3060
|
+
const fetchStories = async (space, params) => {
|
|
3038
3061
|
try {
|
|
3039
|
-
const
|
|
3062
|
+
const client = mapiClient();
|
|
3040
3063
|
const allStories = [];
|
|
3041
3064
|
let currentPage = 1;
|
|
3042
3065
|
let hasMorePages = true;
|
|
@@ -3047,14 +3070,10 @@ const fetchStories = async (space, token, region, params) => {
|
|
|
3047
3070
|
...currentPage > 1 && { page: currentPage.toString() }
|
|
3048
3071
|
}).toString();
|
|
3049
3072
|
const queryString = filter_query ? `${regularParams ? `${regularParams}&` : ""}${filter_query}` : regularParams;
|
|
3050
|
-
const endpoint =
|
|
3051
|
-
const
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
}
|
|
3055
|
-
});
|
|
3056
|
-
allStories.push(...response.stories);
|
|
3057
|
-
const totalPages = Math.ceil(response.total / response.perPage);
|
|
3073
|
+
const endpoint = `spaces/${space}/stories${queryString ? `?${queryString}` : ""}`;
|
|
3074
|
+
const { data } = await client.get(endpoint, {});
|
|
3075
|
+
allStories.push(...data.stories);
|
|
3076
|
+
const totalPages = Math.ceil(data.total / data.per_page);
|
|
3058
3077
|
hasMorePages = currentPage < totalPages;
|
|
3059
3078
|
currentPage++;
|
|
3060
3079
|
}
|
|
@@ -3064,7 +3083,7 @@ const fetchStories = async (space, token, region, params) => {
|
|
|
3064
3083
|
}
|
|
3065
3084
|
};
|
|
3066
3085
|
async function fetchStoriesByComponent(spaceOptions, filterOptions) {
|
|
3067
|
-
const { spaceId
|
|
3086
|
+
const { spaceId } = spaceOptions;
|
|
3068
3087
|
const { componentName = "", query, starts_with } = filterOptions || {};
|
|
3069
3088
|
const params = {
|
|
3070
3089
|
...starts_with && { starts_with }
|
|
@@ -3076,39 +3095,30 @@ async function fetchStoriesByComponent(spaceOptions, filterOptions) {
|
|
|
3076
3095
|
params.filter_query = query.startsWith("filter_query") ? query : `filter_query${query}`;
|
|
3077
3096
|
}
|
|
3078
3097
|
try {
|
|
3079
|
-
const stories = await fetchStories(spaceId,
|
|
3098
|
+
const stories = await fetchStories(spaceId, params);
|
|
3080
3099
|
return stories ?? [];
|
|
3081
3100
|
} catch (error) {
|
|
3082
3101
|
handleAPIError("pull_stories", error);
|
|
3083
3102
|
}
|
|
3084
3103
|
}
|
|
3085
|
-
const fetchStory = async (space,
|
|
3104
|
+
const fetchStory = async (space, storyId) => {
|
|
3086
3105
|
try {
|
|
3087
|
-
const
|
|
3088
|
-
const endpoint =
|
|
3089
|
-
const
|
|
3090
|
-
|
|
3091
|
-
Authorization: token
|
|
3092
|
-
}
|
|
3093
|
-
});
|
|
3094
|
-
return response.story;
|
|
3106
|
+
const client = mapiClient();
|
|
3107
|
+
const endpoint = `spaces/${space}/stories/${storyId}`;
|
|
3108
|
+
const { data } = await client.get(endpoint, {});
|
|
3109
|
+
return data.story;
|
|
3095
3110
|
} catch (error) {
|
|
3096
3111
|
handleAPIError("pull_story", error);
|
|
3097
3112
|
}
|
|
3098
3113
|
};
|
|
3099
|
-
const updateStory = async (space,
|
|
3114
|
+
const updateStory = async (space, storyId, payload) => {
|
|
3100
3115
|
try {
|
|
3101
|
-
const
|
|
3102
|
-
const endpoint =
|
|
3103
|
-
const
|
|
3104
|
-
method: "PUT",
|
|
3105
|
-
headers: {
|
|
3106
|
-
"Authorization": token,
|
|
3107
|
-
"Content-Type": "application/json"
|
|
3108
|
-
},
|
|
3116
|
+
const client = mapiClient();
|
|
3117
|
+
const endpoint = `spaces/${space}/stories/${storyId}`;
|
|
3118
|
+
const { data } = await client.put(endpoint, {
|
|
3109
3119
|
body: JSON.stringify(payload)
|
|
3110
3120
|
});
|
|
3111
|
-
return
|
|
3121
|
+
return data.story;
|
|
3112
3122
|
} catch (error) {
|
|
3113
3123
|
handleAPIError("update_story", error);
|
|
3114
3124
|
}
|
|
@@ -3410,7 +3420,7 @@ const isStoryWithUnpublishedChanges = (story) => {
|
|
|
3410
3420
|
|
|
3411
3421
|
const program$8 = getProgram();
|
|
3412
3422
|
migrationsCommand.command("run [componentName]").description("Run migrations").option("--fi, --filter <filter>", "glob filter to apply to the components before pushing").option("-d, --dry-run", "Preview changes without applying them to Storyblok").option("-q, --query <query>", 'Filter stories by content attributes using Storyblok filter query syntax. Example: --query="[highlighted][in]=true"').option("--starts-with <path>", 'Filter stories by path. Example: --starts-with="/en/blog/"').option("--publish <publish>", "Options for publication mode: all | published | published-with-changes").action(async (componentName, options) => {
|
|
3413
|
-
konsola.title(
|
|
3423
|
+
konsola.title(`${commands.MIGRATIONS}`, colorPalette.MIGRATIONS, componentName ? `Running migrations for component ${componentName}...` : "Running migrations...");
|
|
3414
3424
|
const verbose = program$8.opts().verbose;
|
|
3415
3425
|
const { filter, dryRun = false, query, startsWith, publish } = options;
|
|
3416
3426
|
const { space, path } = migrationsCommand.opts();
|
|
@@ -3424,6 +3434,10 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
3424
3434
|
return;
|
|
3425
3435
|
}
|
|
3426
3436
|
const { password, region } = state;
|
|
3437
|
+
mapiClient({
|
|
3438
|
+
token: password,
|
|
3439
|
+
region
|
|
3440
|
+
});
|
|
3427
3441
|
try {
|
|
3428
3442
|
const spinner = new Spinner({
|
|
3429
3443
|
verbose: !isVitest
|
|
@@ -3448,9 +3462,7 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
3448
3462
|
const storiesSpinner = new Spinner({ verbose: !isVitest }).start(`Fetching stories...`);
|
|
3449
3463
|
const stories = await fetchStoriesByComponent(
|
|
3450
3464
|
{
|
|
3451
|
-
spaceId: space
|
|
3452
|
-
token: password,
|
|
3453
|
-
region
|
|
3465
|
+
spaceId: space
|
|
3454
3466
|
},
|
|
3455
3467
|
// Filter options
|
|
3456
3468
|
{
|
|
@@ -3464,7 +3476,7 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
3464
3476
|
return;
|
|
3465
3477
|
}
|
|
3466
3478
|
const storiesWithContent = await Promise.all(stories.map(async (story) => {
|
|
3467
|
-
const fullStory = await fetchStory(space,
|
|
3479
|
+
const fullStory = await fetchStory(space, story.id.toString());
|
|
3468
3480
|
return {
|
|
3469
3481
|
...story,
|
|
3470
3482
|
content: fullStory?.content
|
|
@@ -3536,7 +3548,7 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
3536
3548
|
payload.publish = 1;
|
|
3537
3549
|
}
|
|
3538
3550
|
try {
|
|
3539
|
-
const updatedStory = await updateStory(space,
|
|
3551
|
+
const updatedStory = await updateStory(space, story.id, payload);
|
|
3540
3552
|
if (updatedStory) {
|
|
3541
3553
|
successCount++;
|
|
3542
3554
|
storySpinner.succeed(`Updated story ${chalk.hex(colorPalette.PRIMARY)(story.name || story.id.toString())} - Completed in ${storySpinner.elapsedTime.toFixed(2)}ms`);
|
|
@@ -3567,7 +3579,7 @@ migrationsCommand.command("run [componentName]").description("Run migrations").o
|
|
|
3567
3579
|
|
|
3568
3580
|
const program$7 = getProgram();
|
|
3569
3581
|
migrationsCommand.command("rollback [migrationFile]").description("Rollback a migration").action(async (migrationFile) => {
|
|
3570
|
-
konsola.title(
|
|
3582
|
+
konsola.title(`${commands.MIGRATIONS}`, colorPalette.MIGRATIONS, `Rolling back migration ${chalk.hex(colorPalette.MIGRATIONS)(migrationFile)}...`);
|
|
3571
3583
|
const verbose = program$7.opts().verbose;
|
|
3572
3584
|
const { space, path } = migrationsCommand.opts();
|
|
3573
3585
|
const { state, initializeSession } = session();
|
|
@@ -3608,7 +3620,7 @@ migrationsCommand.command("rollback [migrationFile]").description("Rollback a mi
|
|
|
3608
3620
|
});
|
|
3609
3621
|
|
|
3610
3622
|
const program$6 = getProgram();
|
|
3611
|
-
const typesCommand = program$6.command(commands.TYPES).alias("ts").description(`Generate types d.ts for your component schemas`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/types");
|
|
3623
|
+
const typesCommand = program$6.command(commands.TYPES).alias("ts").description(`Generate types d.ts for your component schemas`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/types").hook("preAction", resolveRegion);
|
|
3612
3624
|
|
|
3613
3625
|
const getAssetJSONSchema = (title) => ({
|
|
3614
3626
|
$id: "#/asset",
|
|
@@ -4034,7 +4046,7 @@ const DEFAULT_TYPEDEFS_HEADER = [
|
|
|
4034
4046
|
"// This file was generated by the storyblok CLI.",
|
|
4035
4047
|
"// DO NOT MODIFY THIS FILE BY HAND."
|
|
4036
4048
|
];
|
|
4037
|
-
const getPropertyTypeAnnotation = (property, prefix) => {
|
|
4049
|
+
const getPropertyTypeAnnotation = (property, prefix, suffix) => {
|
|
4038
4050
|
if (Array.from(storyblokSchemas.keys()).includes(property.type)) {
|
|
4039
4051
|
return { type: property.type };
|
|
4040
4052
|
}
|
|
@@ -4047,11 +4059,11 @@ const getPropertyTypeAnnotation = (property, prefix) => {
|
|
|
4047
4059
|
if (property.filter_content_type) {
|
|
4048
4060
|
if (typeof property.filter_content_type === "string") {
|
|
4049
4061
|
return {
|
|
4050
|
-
tsType: `(${getStoryType(property.filter_content_type, prefix)} | string )${property.type === "options" ? "[]" : ""}`
|
|
4062
|
+
tsType: `(${getStoryType(property.filter_content_type, prefix, suffix)} | string )${property.type === "options" ? "[]" : ""}`
|
|
4051
4063
|
};
|
|
4052
4064
|
}
|
|
4053
4065
|
return {
|
|
4054
|
-
tsType: `(${property.filter_content_type.map((type2) => getStoryType(type2, prefix)).join(" | ")} | string )${property.type === "options" ? "[]" : ""}`
|
|
4066
|
+
tsType: `(${property.filter_content_type.map((type2) => getStoryType(type2, prefix, suffix)).join(" | ")} | string )${property.type === "options" ? "[]" : ""}`
|
|
4055
4067
|
};
|
|
4056
4068
|
}
|
|
4057
4069
|
}
|
|
@@ -4106,13 +4118,14 @@ const getPropertyTypeAnnotation = (property, prefix) => {
|
|
|
4106
4118
|
return { type: "any" };
|
|
4107
4119
|
}
|
|
4108
4120
|
};
|
|
4109
|
-
function getStoryType(property, prefix) {
|
|
4110
|
-
return `${STORY_TYPE}<${prefix ?? ""}${capitalize(toCamelCase(property))}>`;
|
|
4121
|
+
function getStoryType(property, prefix, suffix) {
|
|
4122
|
+
return `${STORY_TYPE}<${prefix ?? ""}${capitalize(toCamelCase(property))}${suffix ?? ""}>`;
|
|
4111
4123
|
}
|
|
4112
4124
|
const getComponentType = (componentName, options) => {
|
|
4113
4125
|
const prefix = options.typePrefix ?? "";
|
|
4126
|
+
const suffix = options.typeSuffix ?? "";
|
|
4114
4127
|
const sanitizedName = componentName.replace(/[^a-z0-9]/gi, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
4115
|
-
const componentType = toPascalCase(toCamelCase(`${prefix}_${sanitizedName}`));
|
|
4128
|
+
const componentType = toPascalCase(toCamelCase(`${prefix}_${sanitizedName}_${suffix}`));
|
|
4116
4129
|
const isFirstCharacterNumber = !Number.isNaN(Number.parseInt(componentType.charAt(0)));
|
|
4117
4130
|
return isFirstCharacterNumber ? `_${componentType}` : componentType;
|
|
4118
4131
|
};
|
|
@@ -4124,7 +4137,7 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
4124
4137
|
}
|
|
4125
4138
|
const propertyType = value.type;
|
|
4126
4139
|
const propertyTypeAnnotation = {
|
|
4127
|
-
[key]: getPropertyTypeAnnotation(value, options.typePrefix)
|
|
4140
|
+
[key]: getPropertyTypeAnnotation(value, options.typePrefix, options.typeSuffix)
|
|
4128
4141
|
};
|
|
4129
4142
|
if (propertyType === "custom" && customFieldsParser) {
|
|
4130
4143
|
const customField = typeof customFieldsParser === "function" ? customFieldsParser(key, value) : {};
|
|
@@ -4308,8 +4321,8 @@ const generateStoryblokTypes = async (options = {}) => {
|
|
|
4308
4321
|
};
|
|
4309
4322
|
|
|
4310
4323
|
const program$5 = getProgram();
|
|
4311
|
-
typesCommand.command("generate").description("Generate types d.ts for your component schemas").option("--sf, --separate-files", "").option("--strict", "strict mode, no loose typing").option("--type-prefix <prefix>", "prefix to be prepended to all generated component type names").option("--suffix <suffix>", "Components suffix").option("--custom-fields-parser <path>", "Path to the parser file for Custom Field Types").option("--compiler-options <options>", "path to the compiler options from json-schema-to-typescript").action(async (options) => {
|
|
4312
|
-
konsola.title(
|
|
4324
|
+
typesCommand.command("generate").description("Generate types d.ts for your component schemas").option("--sf, --separate-files", "").option("--strict", "strict mode, no loose typing").option("--type-prefix <prefix>", "prefix to be prepended to all generated component type names").option("--type-suffix <suffix>", "suffix to be appended to all generated component type names").option("--suffix <suffix>", "Components suffix").option("--custom-fields-parser <path>", "Path to the parser file for Custom Field Types").option("--compiler-options <options>", "path to the compiler options from json-schema-to-typescript").action(async (options) => {
|
|
4325
|
+
konsola.title(`${commands.TYPES}`, colorPalette.TYPES, "Generating types...");
|
|
4313
4326
|
const verbose = program$5.opts().verbose;
|
|
4314
4327
|
const { space, path } = typesCommand.opts();
|
|
4315
4328
|
const spinner = new Spinner({
|
|
@@ -4351,11 +4364,11 @@ typesCommand.command("generate").description("Generate types d.ts for your compo
|
|
|
4351
4364
|
});
|
|
4352
4365
|
|
|
4353
4366
|
const program$4 = getProgram();
|
|
4354
|
-
const datasourcesCommand = program$4.command(
|
|
4367
|
+
const datasourcesCommand = program$4.command(commands.DATASOURCES).alias("ds").description(`Manage your space's datasources`).option("-s, --space <space>", "space ID").option("-p, --path <path>", "path to save the file. Default is .storyblok/datasources").hook("preAction", resolveRegion);
|
|
4355
4368
|
|
|
4356
4369
|
const program$3 = getProgram();
|
|
4357
4370
|
datasourcesCommand.command("pull [datasourceName]").option("-f, --filename <filename>", "custom name to be used in file(s) name instead of space id").option("--sf, --separate-files", "Argument to create a single file for each datasource").option("--su, --suffix <suffix>", "suffix to add to the file name (e.g. datasources.<suffix>.json)").description("Pull datasources from your space").action(async (datasourceName, options) => {
|
|
4358
|
-
konsola.title(
|
|
4371
|
+
konsola.title(`${commands.DATASOURCES}`, colorPalette.DATASOURCES, datasourceName ? `Pulling datasource ${datasourceName}...` : "Pulling datasources...");
|
|
4359
4372
|
const verbose = program$3.opts().verbose;
|
|
4360
4373
|
const { space, path } = datasourcesCommand.opts();
|
|
4361
4374
|
const { separateFiles, suffix, filename = "datasources" } = options;
|
|
@@ -4425,7 +4438,7 @@ datasourcesCommand.command("pull [datasourceName]").option("-f, --filename <file
|
|
|
4425
4438
|
|
|
4426
4439
|
const program$2 = getProgram();
|
|
4427
4440
|
datasourcesCommand.command("push [datasourceName]").description(`Push your space's datasources schema as json`).option("-f, --from <from>", "source space id").option("--fi, --filter <filter>", "glob filter to apply to the datasources before pushing").option("--sf, --separate-files", "Read from separate files instead of consolidated files").option("--su, --suffix <suffix>", "Suffix to add to the datasource name").action(async (datasourceName, options) => {
|
|
4428
|
-
konsola.title(
|
|
4441
|
+
konsola.title(`${commands.DATASOURCES}`, colorPalette.DATASOURCES, datasourceName ? `Pushing datasource ${datasourceName}...` : "Pushing datasources...");
|
|
4429
4442
|
const verbose = program$2.opts().verbose;
|
|
4430
4443
|
const { space, path } = datasourcesCommand.opts();
|
|
4431
4444
|
const { from, filter } = options;
|
|
@@ -4544,7 +4557,7 @@ async function deleteDatasource(space, id) {
|
|
|
4544
4557
|
|
|
4545
4558
|
datasourcesCommand.command("delete [name]").description("Delete a datasource from your space by name or id").option("--id <id>", "Delete by datasource id instead of name").option("--force", "Skip confirmation prompt for deletion (useful for CI)").action(async (name, options) => {
|
|
4546
4559
|
konsola.title(
|
|
4547
|
-
|
|
4560
|
+
`${commands.DATASOURCES}`,
|
|
4548
4561
|
colorPalette.DATASOURCES,
|
|
4549
4562
|
options.id ? `Deleting datasource with id ${options.id}...` : `Deleting datasource with name ${name}...`
|
|
4550
4563
|
);
|
|
@@ -4742,7 +4755,7 @@ const createSpace = async (space) => {
|
|
|
4742
4755
|
|
|
4743
4756
|
const program$1 = getProgram();
|
|
4744
4757
|
program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`Scaffold a new project using Storyblok`).option("-b, --blueprint <blueprint>", "technology starter blueprint").option("--skip-space", "skip space creation").action(async (projectPath, options) => {
|
|
4745
|
-
konsola.title(
|
|
4758
|
+
konsola.title(`${commands.CREATE}`, colorPalette.CREATE);
|
|
4746
4759
|
const verbose = program$1.opts().verbose;
|
|
4747
4760
|
const { blueprint } = options;
|
|
4748
4761
|
const { state, initializeSession } = session();
|
|
@@ -4872,7 +4885,7 @@ program$1.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
4872
4885
|
konsola.br();
|
|
4873
4886
|
});
|
|
4874
4887
|
|
|
4875
|
-
const version = "4.
|
|
4888
|
+
const version = "4.3.1";
|
|
4876
4889
|
const pkg = {
|
|
4877
4890
|
version: version};
|
|
4878
4891
|
|
|
@@ -4887,7 +4900,8 @@ program.helpOption("-h, --help", "Display help for command");
|
|
|
4887
4900
|
program.on("command:*", () => {
|
|
4888
4901
|
console.error(`Invalid command: ${program.args.join(" ")}`);
|
|
4889
4902
|
konsola.br();
|
|
4890
|
-
program.
|
|
4903
|
+
program.outputHelp();
|
|
4904
|
+
process.exit(1);
|
|
4891
4905
|
});
|
|
4892
4906
|
try {
|
|
4893
4907
|
program.parse(process.argv);
|