@contentful/app-scripts 2.1.3 → 2.2.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/lib/build-functions/build-functions.js +80 -20
- package/lib/cache-credential/index.js +3 -3
- package/lib/create-app-definition/build-app-definition-settings.js +2 -2
- package/lib/create-app-definition/create-app-definition.js +2 -2
- package/lib/generate-function/build-generate-function-settings.js +2 -2
- package/lib/generate-function/clone.js +16 -14
- package/lib/generate-function/utils/file.js +4 -4
- package/lib/upload/build-upload-settings.js +5 -1
- package/lib/upload/create-app-upload.js +1 -1
- package/lib/upload/create-zip-from-directory.js +2 -1
- package/lib/upload/validate-bundle.js +8 -7
- package/lib/utils.js +7 -6
- package/package.json +4 -3
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -7,7 +40,7 @@ exports.resolveEsBuildConfig = exports.validateFunctions = void 0;
|
|
|
7
40
|
exports.buildFunctions = buildFunctions;
|
|
8
41
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
9
42
|
const esbuild_1 = __importDefault(require("esbuild"));
|
|
10
|
-
const
|
|
43
|
+
const node_path_1 = __importStar(require("node:path"));
|
|
11
44
|
const node_modules_polyfill_1 = require("@esbuild-plugins/node-modules-polyfill");
|
|
12
45
|
const node_globals_polyfill_1 = require("@esbuild-plugins/node-globals-polyfill");
|
|
13
46
|
const zod_1 = require("zod");
|
|
@@ -50,33 +83,60 @@ const validateFunctions = (manifest) => {
|
|
|
50
83
|
if (acceptsSet.size !== accepts.length) {
|
|
51
84
|
throw new Error(`Duplicate values found in 'accepts' for function with id '${id}'.`);
|
|
52
85
|
}
|
|
86
|
+
// Validate POSIX style paths
|
|
87
|
+
if (path.includes('\\')) {
|
|
88
|
+
throw new Error(`Function path must use POSIX style forward slashes, got: '${path}'`);
|
|
89
|
+
}
|
|
90
|
+
if (entryFile.includes('\\')) {
|
|
91
|
+
throw new Error(`Function entryFile must use POSIX style forward slashes, got: '${entryFile}'`);
|
|
92
|
+
}
|
|
53
93
|
});
|
|
54
94
|
};
|
|
55
95
|
exports.validateFunctions = validateFunctions;
|
|
56
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Build the esbuild config `entryPoints` object from the functions manifest.
|
|
98
|
+
* Uses posix style paths for consistency with the app manifest.
|
|
99
|
+
*/
|
|
100
|
+
const getEntryPoints = (manifest) => {
|
|
57
101
|
return manifest.functions.reduce((result, contentfulFunction) => {
|
|
58
|
-
const fileProperties =
|
|
59
|
-
const
|
|
60
|
-
|
|
102
|
+
const fileProperties = node_path_1.default.posix.parse(contentfulFunction.entryFile);
|
|
103
|
+
const buildAlias = node_path_1.default.posix.join(fileProperties.dir, fileProperties.name);
|
|
104
|
+
const resolvedPath = node_path_1.default.posix.resolve('.', contentfulFunction.entryFile);
|
|
105
|
+
let relativePath = node_path_1.default.posix.relative('.', resolvedPath);
|
|
106
|
+
if (!relativePath.startsWith('.')) {
|
|
107
|
+
relativePath = `./${relativePath}`;
|
|
108
|
+
}
|
|
109
|
+
result[buildAlias] = relativePath;
|
|
61
110
|
return result;
|
|
62
111
|
}, {});
|
|
63
112
|
};
|
|
64
113
|
const resolveEsBuildConfig = (options, manifest, cwd = process.cwd()) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
114
|
+
if (options.esbuildConfig) {
|
|
115
|
+
const esbuildConfigFileProperties = (0, node_path_1.parse)(options.esbuildConfig);
|
|
116
|
+
const dir = esbuildConfigFileProperties.dir === '' ? cwd : esbuildConfigFileProperties.dir;
|
|
117
|
+
const absolutePath = (0, node_path_1.resolve)(dir, esbuildConfigFileProperties.base);
|
|
118
|
+
const relativePath = (0, node_path_1.relative)(__dirname, absolutePath);
|
|
119
|
+
// Convert the relative path to a module path that require() can use
|
|
120
|
+
// On Windows, this means convert ..\path\to\file.js to ../path/to/file.js
|
|
121
|
+
let modulePath = relativePath.replaceAll("\\", '/');
|
|
122
|
+
if (!modulePath.startsWith('./')) {
|
|
123
|
+
modulePath = `./${modulePath}`;
|
|
124
|
+
}
|
|
125
|
+
return require(modulePath);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
entryPoints: getEntryPoints(manifest),
|
|
129
|
+
bundle: true,
|
|
130
|
+
outdir: 'build',
|
|
131
|
+
format: 'esm',
|
|
132
|
+
target: 'es2022',
|
|
133
|
+
minify: true,
|
|
134
|
+
define: {
|
|
135
|
+
global: 'globalThis',
|
|
136
|
+
},
|
|
137
|
+
plugins: [(0, node_modules_polyfill_1.NodeModulesPolyfillPlugin)(), (0, node_globals_polyfill_1.NodeGlobalsPolyfillPlugin)()],
|
|
138
|
+
logLevel: 'info',
|
|
139
|
+
};
|
|
80
140
|
};
|
|
81
141
|
exports.resolveEsBuildConfig = resolveEsBuildConfig;
|
|
82
142
|
async function buildFunctions(options) {
|
|
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.cacheEnvVars = cacheEnvVars;
|
|
7
7
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
const
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const os_1 = require("os");
|
|
10
10
|
const ignore_1 = __importDefault(require("ignore"));
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
12
|
const constants_1 = require("../constants");
|
|
13
13
|
const ig = (0, ignore_1.default)();
|
|
14
|
-
const fsPromises =
|
|
15
|
-
const fsConstants =
|
|
14
|
+
const fsPromises = node_fs_1.default.promises;
|
|
15
|
+
const fsConstants = node_fs_1.default.constants;
|
|
16
16
|
// Always export set env vars by default
|
|
17
17
|
dotenv_1.default.config();
|
|
18
18
|
async function removeOldEnv(envKey) {
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.buildAppDefinitionSettings = buildAppDefinitionSettings;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
-
const
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const constants_1 = require("../constants");
|
|
11
11
|
const build_app_parameter_settings_1 = require("./build-app-parameter-settings");
|
|
12
12
|
async function buildAppDefinitionSettings() {
|
|
@@ -18,7 +18,7 @@ NOTE: This will create an app definition in your Contentful organization.
|
|
|
18
18
|
const appDefinitionSettings = await inquirer_1.default.prompt([
|
|
19
19
|
{
|
|
20
20
|
name: 'name',
|
|
21
|
-
message: `App name (${
|
|
21
|
+
message: `App name (${node_path_1.default.basename(process.cwd())}):`,
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
name: 'locations',
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAppDefinition = createAppDefinition;
|
|
7
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const contentful_management_1 = require("contentful-management");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
@@ -47,7 +47,7 @@ async function createAppDefinition(accessToken, appDefinitionSettings) {
|
|
|
47
47
|
const organizations = await fetchOrganizations(client);
|
|
48
48
|
const selectedOrg = await (0, utils_1.selectFromList)(organizations, 'Select an organization for your app:', constants_1.ORG_ID_ENV_KEY);
|
|
49
49
|
const organizationId = selectedOrg.value;
|
|
50
|
-
const appName = appDefinitionSettings.name ||
|
|
50
|
+
const appName = appDefinitionSettings.name || node_path_1.default.basename(process.cwd());
|
|
51
51
|
const locations = appDefinitionSettings.locations.map((location) => {
|
|
52
52
|
if (location === 'entry-field') {
|
|
53
53
|
return {
|
|
@@ -7,7 +7,7 @@ exports.buildGenerateFunctionSettingsInteractive = buildGenerateFunctionSettings
|
|
|
7
7
|
exports.validateArguments = validateArguments;
|
|
8
8
|
exports.buildGenerateFunctionSettingsCLI = buildGenerateFunctionSettingsCLI;
|
|
9
9
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
-
const
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const get_github_folder_names_1 = require("./get-github-folder-names");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
13
|
const ora_1 = __importDefault(require("ora"));
|
|
@@ -18,7 +18,7 @@ async function buildGenerateFunctionSettingsInteractive() {
|
|
|
18
18
|
const baseSettings = await inquirer_1.default.prompt([
|
|
19
19
|
{
|
|
20
20
|
name: 'name',
|
|
21
|
-
message: `Function name (${
|
|
21
|
+
message: `Function name (${node_path_1.default.basename(process.cwd())}):`,
|
|
22
22
|
},
|
|
23
23
|
]);
|
|
24
24
|
validateFunctionName(baseSettings);
|
|
@@ -17,7 +17,7 @@ exports.updatePackageJsonWithBuild = updatePackageJsonWithBuild;
|
|
|
17
17
|
const tiged = require('tiged');
|
|
18
18
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
19
19
|
const chalk_1 = __importDefault(require("chalk"));
|
|
20
|
-
const
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
21
21
|
const constants_1 = require("./constants");
|
|
22
22
|
const logger_1 = require("./logger");
|
|
23
23
|
const file_1 = require("./utils/file");
|
|
@@ -48,13 +48,15 @@ function getCloneURL(settings) {
|
|
|
48
48
|
return `${constants_1.REPO_URL}/${settings.example}/${settings.language}`;
|
|
49
49
|
}
|
|
50
50
|
async function touchupAppManifest(localPath, settings, renameFunctionFile) {
|
|
51
|
-
const
|
|
51
|
+
const appManifestPath = (0, node_path_1.resolve)(localPath, constants_1.CONTENTFUL_APP_MANIFEST);
|
|
52
|
+
const appManifest = JSON.parse(node_fs_1.default.readFileSync(appManifestPath, 'utf-8'));
|
|
52
53
|
const entry = appManifest["functions"][appManifest["functions"].length - 1];
|
|
53
54
|
entry.id = settings.name;
|
|
54
55
|
// the path always has a .js extension
|
|
56
|
+
// and path and entryFile are always POSIX style paths
|
|
55
57
|
entry.path = `functions/${renameFunctionFile.replace('.ts', '.js')}`;
|
|
56
58
|
entry.entryFile = `functions/${renameFunctionFile}`;
|
|
57
|
-
await node_fs_1.default.writeFileSync(
|
|
59
|
+
await node_fs_1.default.writeFileSync(appManifestPath, JSON.stringify(appManifest, null, 2));
|
|
58
60
|
}
|
|
59
61
|
function moveFilesToFinalDirectory(localTmpPath, localFunctionsPath) {
|
|
60
62
|
node_fs_1.default.cpSync(localTmpPath, localFunctionsPath, { recursive: true });
|
|
@@ -67,12 +69,12 @@ function renameClonedFiles(localTmpPath, settings) {
|
|
|
67
69
|
throw new Error(`No function file found in ${localTmpPath}`);
|
|
68
70
|
}
|
|
69
71
|
const newFunctionFile = `${settings.name}.${settings.language === 'typescript' ? 'ts' : 'js'}`;
|
|
70
|
-
node_fs_1.default.renameSync(
|
|
72
|
+
node_fs_1.default.renameSync((0, node_path_1.resolve)(localTmpPath, functionFile), (0, node_path_1.resolve)(localTmpPath, newFunctionFile));
|
|
71
73
|
return newFunctionFile;
|
|
72
74
|
}
|
|
73
75
|
function resolvePaths(localPath) {
|
|
74
|
-
const localTmpPath = (0,
|
|
75
|
-
const localFunctionsPath = (0,
|
|
76
|
+
const localTmpPath = (0, node_path_1.resolve)(localPath, 'tmp'); // we require a tmp directory because tiged overwrites all files in the target directory
|
|
77
|
+
const localFunctionsPath = (0, node_path_1.resolve)(localPath, 'functions');
|
|
76
78
|
return { localTmpPath, localFunctionsPath };
|
|
77
79
|
}
|
|
78
80
|
async function cloneAndResolveManifests(cloneURL, localTmpPath, localPath, localFunctionsPath) {
|
|
@@ -83,7 +85,7 @@ async function cloneAndResolveManifests(cloneURL, localTmpPath, localPath, local
|
|
|
83
85
|
await updatePackageJsonWithBuild(localPath, localTmpPath);
|
|
84
86
|
// check if a tsconfig.json file exists already
|
|
85
87
|
const ignoredFiles = constants_1.IGNORED_CLONED_FILES;
|
|
86
|
-
const tsconfigExists = await (0, file_1.exists)(
|
|
88
|
+
const tsconfigExists = await (0, file_1.exists)((0, node_path_1.resolve)(localFunctionsPath, 'tsconfig.json'));
|
|
87
89
|
if (tsconfigExists) {
|
|
88
90
|
ignoredFiles.push('tsconfig.json');
|
|
89
91
|
}
|
|
@@ -99,19 +101,19 @@ async function clone(cloneURL, localFunctionsPath) {
|
|
|
99
101
|
return tigedInstance;
|
|
100
102
|
}
|
|
101
103
|
async function mergeAppManifest(localPath, localTmpPath) {
|
|
102
|
-
const finalAppManifestType = await (0, file_1.exists)(
|
|
104
|
+
const finalAppManifestType = await (0, file_1.exists)((0, node_path_1.resolve)(localPath, constants_1.CONTENTFUL_APP_MANIFEST));
|
|
103
105
|
const tmpAppManifestType = await (0, file_1.whichExists)(localTmpPath, [constants_1.CONTENTFUL_APP_MANIFEST, constants_1.APP_MANIFEST]); // find the app manifest in the cloned files
|
|
104
106
|
if (!finalAppManifestType) {
|
|
105
107
|
await (0, file_1.mergeJsonIntoFile)({
|
|
106
|
-
source:
|
|
107
|
-
destination:
|
|
108
|
+
source: (0, node_path_1.resolve)(localTmpPath, tmpAppManifestType),
|
|
109
|
+
destination: (0, node_path_1.resolve)(localPath, constants_1.CONTENTFUL_APP_MANIFEST), // always save as contentful-app-manifest.json
|
|
108
110
|
});
|
|
109
111
|
}
|
|
110
112
|
else {
|
|
111
113
|
// add the function to the json's "functions" array
|
|
112
114
|
await (0, file_1.mergeJsonIntoFile)({
|
|
113
|
-
source:
|
|
114
|
-
destination:
|
|
115
|
+
source: (0, node_path_1.resolve)(localTmpPath, tmpAppManifestType),
|
|
116
|
+
destination: (0, node_path_1.resolve)(localPath, constants_1.CONTENTFUL_APP_MANIFEST),
|
|
115
117
|
mergeFn: (destinationJson = {}, sourceJson = {}) => {
|
|
116
118
|
if (!destinationJson.functions) {
|
|
117
119
|
destinationJson.functions = [];
|
|
@@ -125,11 +127,11 @@ async function mergeAppManifest(localPath, localTmpPath) {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
async function updatePackageJsonWithBuild(localPath, localTmpPath) {
|
|
128
|
-
const packageJsonLocation = (0,
|
|
130
|
+
const packageJsonLocation = (0, node_path_1.resolve)(localPath, 'package.json');
|
|
129
131
|
const packageJsonExists = await (0, file_1.exists)(packageJsonLocation);
|
|
130
132
|
if (packageJsonExists) {
|
|
131
133
|
await (0, file_1.mergeJsonIntoFile)({
|
|
132
|
-
source:
|
|
134
|
+
source: (0, node_path_1.resolve)(localTmpPath, 'package.json'),
|
|
133
135
|
destination: packageJsonLocation,
|
|
134
136
|
mergeFn: addBuildCommand,
|
|
135
137
|
});
|
|
@@ -9,12 +9,12 @@ exports.exists = exists;
|
|
|
9
9
|
exports.whichExists = whichExists;
|
|
10
10
|
const merge_options_1 = __importDefault(require("merge-options"));
|
|
11
11
|
const promises_1 = require("fs/promises");
|
|
12
|
-
const
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
13
|
async function getJsonData(path) {
|
|
14
14
|
if (!path) {
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
|
-
const normalizedPath = (0,
|
|
17
|
+
const normalizedPath = (0, node_path_1.resolve)(path);
|
|
18
18
|
if (!(await exists(normalizedPath))) {
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
@@ -24,7 +24,7 @@ async function mergeJsonIntoFile({ source, destination, mergeFn = merge_options_
|
|
|
24
24
|
const sourceJson = await getJsonData(source);
|
|
25
25
|
const destinationJson = await getJsonData(destination);
|
|
26
26
|
const mergedJson = mergeFn(destinationJson, sourceJson);
|
|
27
|
-
await (0, promises_1.writeFile)((0,
|
|
27
|
+
await (0, promises_1.writeFile)((0, node_path_1.resolve)(destination), JSON.stringify(mergedJson, null, ' '));
|
|
28
28
|
}
|
|
29
29
|
function exists(path) {
|
|
30
30
|
return (0, promises_1.access)(path)
|
|
@@ -40,7 +40,7 @@ function exists(path) {
|
|
|
40
40
|
async function whichExists(basePath, paths) {
|
|
41
41
|
for (const path of paths) {
|
|
42
42
|
try {
|
|
43
|
-
await (0, promises_1.access)((0,
|
|
43
|
+
await (0, promises_1.access)((0, node_path_1.join)(basePath, path));
|
|
44
44
|
return path;
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.buildAppUploadSettings = buildAppUploadSettings;
|
|
4
7
|
exports.hostProtocolFilter = hostProtocolFilter;
|
|
@@ -6,6 +9,7 @@ const inquirer_1 = require("inquirer");
|
|
|
6
9
|
const get_app_info_1 = require("../get-app-info");
|
|
7
10
|
const utils_1 = require("../utils");
|
|
8
11
|
const constants_1 = require("../constants");
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
13
|
async function buildAppUploadSettings(options) {
|
|
10
14
|
const functionManifest = (0, utils_1.getFunctionsFromManifest)();
|
|
11
15
|
const prompts = [];
|
|
@@ -14,7 +18,7 @@ async function buildAppUploadSettings(options) {
|
|
|
14
18
|
prompts.push({
|
|
15
19
|
name: 'bundleDirectory',
|
|
16
20
|
message: `Bundle directory, if not default:`,
|
|
17
|
-
default: '
|
|
21
|
+
default: node_path_1.default.resolve('.', 'build'),
|
|
18
22
|
});
|
|
19
23
|
}
|
|
20
24
|
if (!comment) {
|
|
@@ -22,7 +22,7 @@ async function createAppUpload(settings) {
|
|
|
22
22
|
(0, validate_bundle_1.validateBundle)(settings.bundleDirectory || '.', settings);
|
|
23
23
|
let appUpload = null;
|
|
24
24
|
const zipFileSpinner = (0, ora_1.default)('Preparing your files for upload...').start();
|
|
25
|
-
const zipFile = await (0, create_zip_from_directory_1.createZipFileFromDirectory)(settings.bundleDirectory || '
|
|
25
|
+
const zipFile = await (0, create_zip_from_directory_1.createZipFileFromDirectory)(settings.bundleDirectory || '.');
|
|
26
26
|
zipFileSpinner.stop();
|
|
27
27
|
if (!zipFile)
|
|
28
28
|
return;
|
|
@@ -7,10 +7,11 @@ exports.createZipFileFromDirectory = createZipFileFromDirectory;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
9
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
10
11
|
async function createZipFileFromDirectory(path) {
|
|
11
12
|
try {
|
|
12
13
|
const zip = new adm_zip_1.default();
|
|
13
|
-
zip.addLocalFolder(path);
|
|
14
|
+
zip.addLocalFolder((0, node_path_1.resolve)(path));
|
|
14
15
|
console.log("");
|
|
15
16
|
console.log(` ----------------------------
|
|
16
17
|
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.validateBundle = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const ACCEPTED_ENTRY_FILES = ['index.html'];
|
|
11
11
|
const getEntryFile = (files) => files.find((file) => ACCEPTED_ENTRY_FILES.includes(file));
|
|
@@ -14,14 +14,14 @@ const fileContainsAbsolutePath = (fileContent) => {
|
|
|
14
14
|
return [...fileContent.matchAll(ABSOLUTE_PATH_REG_EXP)].length > 0;
|
|
15
15
|
};
|
|
16
16
|
const validateBundle = (path, { functions }) => {
|
|
17
|
-
const buildFolder =
|
|
18
|
-
const files =
|
|
17
|
+
const buildFolder = node_path_1.default.join('.', path);
|
|
18
|
+
const files = node_fs_1.default.readdirSync(buildFolder, { recursive: true, encoding: 'utf-8' });
|
|
19
19
|
const entry = getEntryFile(files);
|
|
20
20
|
if (!entry && !functions) {
|
|
21
21
|
throw new Error('Ensure your bundle includes a valid index.html file in its root folder, or a valid Contentful Function entrypoint (defined in your contentful-app-manifest.json file).');
|
|
22
22
|
}
|
|
23
23
|
if (entry) {
|
|
24
|
-
const entryFile =
|
|
24
|
+
const entryFile = node_fs_1.default.readFileSync(node_path_1.default.join(buildFolder, entry), { encoding: 'utf8' });
|
|
25
25
|
if (fileContainsAbsolutePath(entryFile)) {
|
|
26
26
|
console.log('----------------------------');
|
|
27
27
|
console.warn(`${chalk_1.default.red('Warning:')} This bundle uses absolute paths. Please use relative paths instead for correct rendering. See more details here https://www.contentful.com/developers/docs/extensibility/app-framework/app-bundle/#limitations`);
|
|
@@ -29,9 +29,10 @@ const validateBundle = (path, { functions }) => {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
if (functions) {
|
|
32
|
-
const
|
|
32
|
+
const posixFormattedFiles = new Set(files.map((file) => file.replace(/\\/g, '/')));
|
|
33
|
+
const functionWithoutEntryFile = functions.find(({ path }) => !posixFormattedFiles.has(path));
|
|
33
34
|
if (functionWithoutEntryFile) {
|
|
34
|
-
throw new Error(`Function "${functionWithoutEntryFile.id}" is missing its entry file at "${
|
|
35
|
+
throw new Error(`Function "${functionWithoutEntryFile.id}" is missing its entry file at "${node_path_1.default.join(buildFolder, functionWithoutEntryFile.path)}".`);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
};
|
package/lib/utils.js
CHANGED
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ID_REGEX = exports.resolveManifestFile = exports.selectFromList = exports.throwError = exports.showCreationError = exports.stripProtocol = exports.isValidNetwork = exports.throwValidationException = void 0;
|
|
7
7
|
exports.getFunctionsFromManifest = getFunctionsFromManifest;
|
|
8
8
|
exports.getWebAppHostname = getWebAppHostname;
|
|
9
|
-
const
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
12
|
const cache_credential_1 = require("./cache-credential");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const node_path_1 = require("node:path");
|
|
15
|
-
const DEFAULT_MANIFEST_PATH = '
|
|
15
|
+
const DEFAULT_MANIFEST_PATH = (0, node_path_1.resolve)('.', 'contentful-app-manifest.json');
|
|
16
16
|
const functionEvents = {
|
|
17
17
|
appActionCall: 'appaction.call',
|
|
18
18
|
appEventFilter: 'appevent.filter',
|
|
@@ -107,12 +107,12 @@ const selectFromList = async (list, message, cachedOptionEnvVar) => {
|
|
|
107
107
|
};
|
|
108
108
|
exports.selectFromList = selectFromList;
|
|
109
109
|
function getFunctionsFromManifest() {
|
|
110
|
-
const isManifestExists =
|
|
110
|
+
const isManifestExists = node_fs_1.default.existsSync(DEFAULT_MANIFEST_PATH);
|
|
111
111
|
if (!isManifestExists) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
try {
|
|
115
|
-
const manifest = JSON.parse(
|
|
115
|
+
const manifest = JSON.parse(node_fs_1.default.readFileSync(DEFAULT_MANIFEST_PATH, { encoding: 'utf8' }));
|
|
116
116
|
if (!Array.isArray(manifest['functions']) || manifest['functions'].length === 0) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
@@ -155,9 +155,10 @@ function getWebAppHostname(host) {
|
|
|
155
155
|
return host && host.includes('api') ? host.replace('api', 'app') : constants_1.DEFAULT_CONTENTFUL_APP_HOST;
|
|
156
156
|
}
|
|
157
157
|
const resolveManifestFile = (options, cwd = process.cwd()) => {
|
|
158
|
-
|
|
158
|
+
const manifestPath = options.manifestFile
|
|
159
159
|
? (0, node_path_1.resolve)(cwd, options.manifestFile)
|
|
160
|
-
: (0, node_path_1.resolve)(cwd, 'contentful-app-manifest.json')
|
|
160
|
+
: (0, node_path_1.resolve)(cwd, 'contentful-app-manifest.json');
|
|
161
|
+
return JSON.parse(node_fs_1.default.readFileSync(manifestPath, 'utf-8'));
|
|
161
162
|
};
|
|
162
163
|
exports.resolveManifestFile = resolveManifestFile;
|
|
163
164
|
exports.ID_REGEX = /^[a-zA-Z0-9]+$/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/app-scripts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A collection of scripts for building Contentful Apps",
|
|
5
5
|
"author": "Contentful GmbH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"commander": "12.1.0",
|
|
58
58
|
"contentful-management": "11.48.0",
|
|
59
59
|
"dotenv": "16.4.7",
|
|
60
|
-
"esbuild": "^0.25.
|
|
60
|
+
"esbuild": "^0.25.1",
|
|
61
61
|
"ignore": "7.0.3",
|
|
62
62
|
"inquirer": "8.2.6",
|
|
63
63
|
"lodash": "4.17.21",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tiged": "^2.12.7",
|
|
68
68
|
"zod": "^3.24.1"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "f74bc713b10f3b7eafc95193327bebc91ec64d74",
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/adm-zip": "0.5.7",
|
|
73
73
|
"@types/analytics-node": "3.1.14",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@types/inquirer": "8.2.1",
|
|
76
76
|
"@types/lodash": "4.17.16",
|
|
77
77
|
"@types/mocha": "10.0.10",
|
|
78
|
+
"@types/node": "^22.13.10",
|
|
78
79
|
"@types/proxyquire": "1.3.31",
|
|
79
80
|
"@types/sinon": "17.0.4",
|
|
80
81
|
"chai": "4.5.0",
|