storyblok 4.15.1 → 4.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +37 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import 'dotenv/config';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import { resolve, dirname,
|
|
4
|
+
import { resolve, dirname, join, parse, extname, relative, isAbsolute, basename } from 'pathe';
|
|
5
5
|
import { existsSync, mkdirSync, appendFileSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from 'node:fs';
|
|
6
6
|
import { homedir } from 'node:os';
|
|
7
7
|
import { loadConfig as loadConfig$1, SUPPORTED_EXTENSIONS } from 'c12';
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import { readPackageUp } from 'read-package-up';
|
|
10
10
|
import { Command } from 'commander';
|
|
11
|
-
import path, { join, resolve as resolve$1, parse, dirname as dirname$1, extname, relative, basename } from 'node:path';
|
|
12
11
|
import { MultiBar, Presets } from 'cli-progress';
|
|
13
12
|
import { Spinner } from '@topcli/spinner';
|
|
14
13
|
import fs, { mkdir, writeFile, readFile as readFile$1, appendFile, access, constants, readdir, unlink } from 'node:fs/promises';
|
|
@@ -1309,7 +1308,7 @@ const deduplicateManifest = async (manifestFile) => {
|
|
|
1309
1308
|
};
|
|
1310
1309
|
const resolvePath = (path, folder) => {
|
|
1311
1310
|
const basePath = path ?? DEFAULT_STORAGE_DIR;
|
|
1312
|
-
return resolve
|
|
1311
|
+
return resolve(process.cwd(), basePath, folder);
|
|
1313
1312
|
};
|
|
1314
1313
|
function resolveCommandPath(commandPath, space, baseDir) {
|
|
1315
1314
|
if (space) {
|
|
@@ -1421,7 +1420,7 @@ class Reporter {
|
|
|
1421
1420
|
if (this.maxFiles === void 0) {
|
|
1422
1421
|
return;
|
|
1423
1422
|
}
|
|
1424
|
-
const dir = dirname
|
|
1423
|
+
const dir = dirname(this.filePath);
|
|
1425
1424
|
const ext = extname(this.filePath);
|
|
1426
1425
|
Reporter.pruneReportFiles(dir, this.maxFiles, ext);
|
|
1427
1426
|
}
|
|
@@ -1479,7 +1478,7 @@ class FileTransport {
|
|
|
1479
1478
|
if (this.maxFiles === void 0) {
|
|
1480
1479
|
return;
|
|
1481
1480
|
}
|
|
1482
|
-
const dir = dirname
|
|
1481
|
+
const dir = dirname(this.filePath);
|
|
1483
1482
|
const ext = extname(this.filePath);
|
|
1484
1483
|
FileTransport.pruneLogFiles(dir, this.maxFiles, ext);
|
|
1485
1484
|
}
|
|
@@ -1878,7 +1877,7 @@ function getProgram() {
|
|
|
1878
1877
|
options.path
|
|
1879
1878
|
);
|
|
1880
1879
|
const logFilename = `${commandPieces.join("-")}-${runId}.jsonl`;
|
|
1881
|
-
logFilePath =
|
|
1880
|
+
logFilePath = join(logsPath, logFilename);
|
|
1882
1881
|
transports.push(
|
|
1883
1882
|
new FileTransport({
|
|
1884
1883
|
filePath: logFilePath,
|
|
@@ -1902,7 +1901,7 @@ function getProgram() {
|
|
|
1902
1901
|
options.path
|
|
1903
1902
|
);
|
|
1904
1903
|
const reportFilename = `${commandPieces.join("-")}-${runId}.json`;
|
|
1905
|
-
const reportFilePath =
|
|
1904
|
+
const reportFilePath = join(reportPath, reportFilename);
|
|
1906
1905
|
const reporter = getReporter({
|
|
1907
1906
|
enabled: true,
|
|
1908
1907
|
filePath: reportFilePath,
|
|
@@ -2339,7 +2338,7 @@ const fetchComponentInternalTags = async (spaceId) => {
|
|
|
2339
2338
|
const saveComponentsToFiles = async (space, spaceData, options) => {
|
|
2340
2339
|
const { components = [], groups = [], presets = [], internalTags = [] } = spaceData;
|
|
2341
2340
|
const { filename = DEFAULT_COMPONENTS_FILENAME, suffix, path, separateFiles } = options;
|
|
2342
|
-
const resolvedPath = path ? resolve
|
|
2341
|
+
const resolvedPath = path ? resolve(process.cwd(), path, "components", space) : resolvePath(path, `components/${space}`);
|
|
2343
2342
|
try {
|
|
2344
2343
|
if (separateFiles) {
|
|
2345
2344
|
for (const component of components) {
|
|
@@ -2713,17 +2712,17 @@ pullCmd$4.action(async (componentName, options, command) => {
|
|
|
2713
2712
|
konsola.warn(`The --filename option is ignored when using --separate-files`);
|
|
2714
2713
|
}
|
|
2715
2714
|
const filePath = `${componentsOutputDir}/`;
|
|
2716
|
-
const displayPath = path && isAbsolute(path) ? filePath : `${relative
|
|
2715
|
+
const displayPath = path && isAbsolute(path) ? filePath : `${relative(process.cwd(), componentsOutputDir)}/`;
|
|
2717
2716
|
konsola.ok(`Components downloaded successfully to ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
2718
2717
|
} else if (componentName) {
|
|
2719
2718
|
const fileName = suffix ? `${actualFilename}.${suffix}.json` : `${componentName}.json`;
|
|
2720
|
-
const filePath = join
|
|
2721
|
-
const displayPath = path && isAbsolute(path) ? filePath : relative
|
|
2719
|
+
const filePath = join(componentsOutputDir, fileName);
|
|
2720
|
+
const displayPath = path && isAbsolute(path) ? filePath : relative(process.cwd(), filePath);
|
|
2722
2721
|
konsola.ok(`Component ${chalk.hex(colorPalette.PRIMARY)(componentName)} downloaded successfully in ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
2723
2722
|
} else {
|
|
2724
2723
|
const fileName = suffix ? `${actualFilename}.${suffix}.json` : `${actualFilename}.json`;
|
|
2725
|
-
const filePath = join
|
|
2726
|
-
const displayPath = path && isAbsolute(path) ? filePath : relative
|
|
2724
|
+
const filePath = join(componentsOutputDir, fileName);
|
|
2725
|
+
const displayPath = path && isAbsolute(path) ? filePath : relative(process.cwd(), filePath);
|
|
2727
2726
|
konsola.ok(`Components downloaded successfully to ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
2728
2727
|
}
|
|
2729
2728
|
konsola.br();
|
|
@@ -3906,8 +3905,8 @@ pullCmd$3.action(async (options, command) => {
|
|
|
3906
3905
|
});
|
|
3907
3906
|
const languagesOutputDir = resolveCommandPath("languages", space, path);
|
|
3908
3907
|
const fileName = suffix ? `${filename}.${suffix}.json` : `${filename}.json`;
|
|
3909
|
-
const filePath = join
|
|
3910
|
-
const displayPath = path && isAbsolute(path) ? filePath : relative
|
|
3908
|
+
const filePath = join(languagesOutputDir, fileName);
|
|
3909
|
+
const displayPath = path && isAbsolute(path) ? filePath : relative(process.cwd(), filePath);
|
|
3911
3910
|
spinner.succeed();
|
|
3912
3911
|
konsola.ok(`Languages schema downloaded successfully at ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`, true);
|
|
3913
3912
|
} catch (error) {
|
|
@@ -3937,7 +3936,7 @@ const getMigrationTemplate = () => {
|
|
|
3937
3936
|
`;
|
|
3938
3937
|
};
|
|
3939
3938
|
const generateMigration = async (space, path, component, suffix) => {
|
|
3940
|
-
const resolvedPath = path ? resolve
|
|
3939
|
+
const resolvedPath = path ? resolve(process.cwd(), path, "migrations", space) : resolvePath(path, `migrations/${space}`);
|
|
3941
3940
|
const fileName = suffix ? `${component.name}.${suffix}.js` : `${component.name}.js`;
|
|
3942
3941
|
const migrationPath = join(resolvedPath, fileName);
|
|
3943
3942
|
try {
|
|
@@ -4545,8 +4544,8 @@ const findComponentSchemas = async (directoryPath) => {
|
|
|
4545
4544
|
}
|
|
4546
4545
|
throw error;
|
|
4547
4546
|
});
|
|
4548
|
-
const fileContents = files.filter((f) =>
|
|
4549
|
-
const filePath =
|
|
4547
|
+
const fileContents = files.filter((f) => extname(f) === ".json").map((f) => {
|
|
4548
|
+
const filePath = join(directoryPath, f);
|
|
4550
4549
|
const fileContent = readFileSync(filePath, "utf-8");
|
|
4551
4550
|
return JSON.parse(fileContent);
|
|
4552
4551
|
});
|
|
@@ -5611,7 +5610,7 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
5611
5610
|
};
|
|
5612
5611
|
const loadCustomFieldsParser = async (path) => {
|
|
5613
5612
|
try {
|
|
5614
|
-
const customFieldsParser = await import(resolve
|
|
5613
|
+
const customFieldsParser = await import(pathToFileURL(resolve(path)).href);
|
|
5615
5614
|
return customFieldsParser.default;
|
|
5616
5615
|
} catch (error) {
|
|
5617
5616
|
handleError(error);
|
|
@@ -5620,7 +5619,7 @@ const loadCustomFieldsParser = async (path) => {
|
|
|
5620
5619
|
};
|
|
5621
5620
|
async function loadCompilerOptions(path) {
|
|
5622
5621
|
if (path) {
|
|
5623
|
-
const compilerOptions = await import(resolve
|
|
5622
|
+
const compilerOptions = await import(pathToFileURL(resolve(path)).href);
|
|
5624
5623
|
return compilerOptions.default;
|
|
5625
5624
|
}
|
|
5626
5625
|
return {};
|
|
@@ -5770,7 +5769,7 @@ const generateTypes = async (spaceData, options = {
|
|
|
5770
5769
|
};
|
|
5771
5770
|
const saveTypesToComponentsFile = async (space, typedefData, options) => {
|
|
5772
5771
|
const { filename = DEFAULT_COMPONENT_FILENAME, path, separateFiles } = options;
|
|
5773
|
-
const resolvedPath = path ? resolve
|
|
5772
|
+
const resolvedPath = path ? resolve(process.cwd(), path, "types", space) : resolvePath(path, `types/${space}`);
|
|
5774
5773
|
try {
|
|
5775
5774
|
if (separateFiles && Array.isArray(typedefData)) {
|
|
5776
5775
|
for (const { name, content } of typedefData) {
|
|
@@ -5786,7 +5785,7 @@ const saveTypesToComponentsFile = async (space, typedefData, options) => {
|
|
|
5786
5785
|
const generateStoryblokTypes = async (options = {}) => {
|
|
5787
5786
|
const { path } = options;
|
|
5788
5787
|
try {
|
|
5789
|
-
const storyblokTypesPath = resolve
|
|
5788
|
+
const storyblokTypesPath = resolve(__dirname, "./index.d.ts");
|
|
5790
5789
|
const storyblokTypesContent = readFileSync(storyblokTypesPath, "utf-8");
|
|
5791
5790
|
const typeDefs = [
|
|
5792
5791
|
"// This file was generated by the Storyblok CLI.",
|
|
@@ -5794,7 +5793,7 @@ const generateStoryblokTypes = async (options = {}) => {
|
|
|
5794
5793
|
`import type { ${STORY_TYPE} } from '@storyblok/js';`,
|
|
5795
5794
|
storyblokTypesContent
|
|
5796
5795
|
].join("\n");
|
|
5797
|
-
const resolvedPath = path ? resolve
|
|
5796
|
+
const resolvedPath = path ? resolve(process.cwd(), path, "types") : resolvePath(path, "types");
|
|
5798
5797
|
await saveToFile(join(resolvedPath, `storyblok.d.ts`), typeDefs);
|
|
5799
5798
|
return true;
|
|
5800
5799
|
} catch (error) {
|
|
@@ -6113,7 +6112,7 @@ const fetchDatasource = async (spaceId, datasourceName) => {
|
|
|
6113
6112
|
};
|
|
6114
6113
|
const saveDatasourcesToFiles = async (space, datasources, options) => {
|
|
6115
6114
|
const { filename = DEFAULT_DATASOURCES_FILENAME, suffix, path, separateFiles } = options;
|
|
6116
|
-
const resolvedPath = path ? resolve
|
|
6115
|
+
const resolvedPath = path ? resolve(process.cwd(), path, "datasources", space) : resolvePath(path, `datasources/${space}`);
|
|
6117
6116
|
try {
|
|
6118
6117
|
if (separateFiles) {
|
|
6119
6118
|
for (const datasource of datasources) {
|
|
@@ -6181,17 +6180,17 @@ pullCmd$2.action(async (datasourceName, options, command) => {
|
|
|
6181
6180
|
konsola.warn(`The --filename option is ignored when using --separate-files`);
|
|
6182
6181
|
}
|
|
6183
6182
|
const filePath = `${datasourcesOutputDir}/`;
|
|
6184
|
-
const displayPath = path && isAbsolute(path) ? filePath : `${relative
|
|
6183
|
+
const displayPath = path && isAbsolute(path) ? filePath : `${relative(process.cwd(), datasourcesOutputDir)}/`;
|
|
6185
6184
|
konsola.ok(`Datasources downloaded successfully to ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
6186
6185
|
} else if (datasourceName) {
|
|
6187
6186
|
const fileName = suffix ? `${actualFilename}.${suffix}.json` : `${datasourceName}.json`;
|
|
6188
|
-
const filePath = join
|
|
6189
|
-
const displayPath = path && isAbsolute(path) ? filePath : relative
|
|
6187
|
+
const filePath = join(datasourcesOutputDir, fileName);
|
|
6188
|
+
const displayPath = path && isAbsolute(path) ? filePath : relative(process.cwd(), filePath);
|
|
6190
6189
|
konsola.ok(`Datasource ${chalk.hex(colorPalette.PRIMARY)(datasourceName)} downloaded successfully in ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
6191
6190
|
} else {
|
|
6192
6191
|
const fileName = suffix ? `${actualFilename}.${suffix}.json` : `${actualFilename}.json`;
|
|
6193
|
-
const filePath = join
|
|
6194
|
-
const displayPath = path && isAbsolute(path) ? filePath : relative
|
|
6192
|
+
const filePath = join(datasourcesOutputDir, fileName);
|
|
6193
|
+
const displayPath = path && isAbsolute(path) ? filePath : relative(process.cwd(), filePath);
|
|
6195
6194
|
konsola.ok(`Datasources downloaded successfully to ${chalk.hex(colorPalette.PRIMARY)(displayPath)}`);
|
|
6196
6195
|
}
|
|
6197
6196
|
konsola.br();
|
|
@@ -6400,7 +6399,7 @@ const createOctokit = (token) => {
|
|
|
6400
6399
|
|
|
6401
6400
|
const generateProject = async (blueprint, projectName, targetPath = process.cwd()) => {
|
|
6402
6401
|
try {
|
|
6403
|
-
const projectPath =
|
|
6402
|
+
const projectPath = join(targetPath, projectName);
|
|
6404
6403
|
const templateRepo = `storyblok/blueprint-core-${blueprint}`;
|
|
6405
6404
|
try {
|
|
6406
6405
|
await fs.access(projectPath);
|
|
@@ -6437,7 +6436,7 @@ const generateProject = async (blueprint, projectName, targetPath = process.cwd(
|
|
|
6437
6436
|
};
|
|
6438
6437
|
const createEnvFile = async (projectPath, storyblokVars, additionalVars) => {
|
|
6439
6438
|
try {
|
|
6440
|
-
const envPath =
|
|
6439
|
+
const envPath = join(projectPath, ".env");
|
|
6441
6440
|
let envContent = `# Storyblok Configuration
|
|
6442
6441
|
${Object.entries(storyblokVars).map(([key, value]) => `${key}=${value}`).join("\n")}
|
|
6443
6442
|
`;
|
|
@@ -6655,7 +6654,7 @@ program$5.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
6655
6654
|
if (!value.trim()) {
|
|
6656
6655
|
return "Project path is required";
|
|
6657
6656
|
}
|
|
6658
|
-
const projectName2 =
|
|
6657
|
+
const projectName2 = basename(value);
|
|
6659
6658
|
if (!/^[\w-]+$/.test(projectName2)) {
|
|
6660
6659
|
return "Project name (last part of the path) can only contain letters, numbers, hyphens, and underscores";
|
|
6661
6660
|
}
|
|
@@ -6663,9 +6662,9 @@ program$5.command(`${commands.CREATE} [project-path]`).alias("c").description(`S
|
|
|
6663
6662
|
}
|
|
6664
6663
|
});
|
|
6665
6664
|
}
|
|
6666
|
-
const resolvedPath =
|
|
6667
|
-
const targetDirectory =
|
|
6668
|
-
const projectName =
|
|
6665
|
+
const resolvedPath = resolve(finalProjectPath);
|
|
6666
|
+
const targetDirectory = dirname(resolvedPath);
|
|
6667
|
+
const projectName = basename(resolvedPath);
|
|
6669
6668
|
konsola.br();
|
|
6670
6669
|
konsola.info(`Scaffolding your project using the ${chalk.hex(colorPalette.CREATE)(technologyTemplate)} template...`);
|
|
6671
6670
|
await generateProject(technologyTemplate, projectName, targetDirectory);
|
|
@@ -7125,7 +7124,7 @@ const parseAssetData = (raw) => {
|
|
|
7125
7124
|
}
|
|
7126
7125
|
};
|
|
7127
7126
|
const getSidecarFilename = (assetBinaryPath) => {
|
|
7128
|
-
return join(dirname
|
|
7127
|
+
return join(dirname(assetBinaryPath), `${basename(assetBinaryPath, extname(assetBinaryPath))}.json`);
|
|
7129
7128
|
};
|
|
7130
7129
|
const loadSidecarAssetData = async (assetBinaryPath) => {
|
|
7131
7130
|
const sidecarPath = getSidecarFilename(assetBinaryPath);
|
|
@@ -8281,7 +8280,7 @@ const createStoryPlaceholderStream = ({
|
|
|
8281
8280
|
});
|
|
8282
8281
|
};
|
|
8283
8282
|
const makeWriteStoryFSTransport = ({ directoryPath }) => async (story) => {
|
|
8284
|
-
await saveToFile(resolve
|
|
8283
|
+
await saveToFile(resolve(directoryPath, getStoryFilename(story)), JSON.stringify(story, null, 2));
|
|
8285
8284
|
return story;
|
|
8286
8285
|
};
|
|
8287
8286
|
const makeWriteStoryAPITransport = ({ spaceId, publish }) => (mappedLocalStory) => updateStory(spaceId, mappedLocalStory.id, {
|
|
@@ -8295,7 +8294,7 @@ const makeCleanupStoryFSTransport = ({ directoryPath, maps }) => async (mappedSt
|
|
|
8295
8294
|
slug: mappedStory.slug,
|
|
8296
8295
|
uuid: originalUuid
|
|
8297
8296
|
});
|
|
8298
|
-
const storyFilePath = resolve
|
|
8297
|
+
const storyFilePath = resolve(directoryPath, storyFilename);
|
|
8299
8298
|
await unlink(storyFilePath);
|
|
8300
8299
|
};
|
|
8301
8300
|
const writeStoryStream = ({
|