@lwrjs/tools 0.15.0-alpha.9 → 0.15.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/build/cjs/index.cjs +1 -0
- package/build/cjs/plugins/build-server-plugin.cjs +0 -2
- package/build/cjs/server-build.cjs +11 -1
- package/build/cjs/util/request-script.cjs +223 -0
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/build/es/plugins/build-server-plugin.js +0 -4
- package/build/es/server-build.d.ts +1 -0
- package/build/es/server-build.js +12 -2
- package/build/es/util/request-script.d.ts +2 -0
- package/build/es/util/request-script.js +219 -0
- package/package.json +8 -8
package/build/cjs/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/tools/src/index.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
REQUEST_SCRIPT_NAME: () => import_server_build.REQUEST_SCRIPT_NAME,
|
|
27
28
|
buildServer: () => import_server_build.buildServer,
|
|
28
29
|
dedupeBundles: () => import_static.dedupeBundles
|
|
29
30
|
});
|
|
@@ -108,8 +108,6 @@ function printRouteHandlers(routeHandlers) {
|
|
|
108
108
|
}).join(",")}}`;
|
|
109
109
|
}
|
|
110
110
|
function buildLwrServer(config, buildDir) {
|
|
111
|
-
process.env.SINGLE_RENDER_MODE = "true";
|
|
112
|
-
process.env.REEVALUATE_MODULES = "true";
|
|
113
111
|
return {
|
|
114
112
|
name: "lwr-server-build",
|
|
115
113
|
setup(build) {
|
|
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/tools/src/server-build.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
REQUEST_SCRIPT_NAME: () => REQUEST_SCRIPT_NAME,
|
|
27
28
|
buildServer: () => buildServer
|
|
28
29
|
});
|
|
29
30
|
var import_path = __toModule(require("path"));
|
|
@@ -33,10 +34,17 @@ var import_perf_hooks = __toModule(require("perf_hooks"));
|
|
|
33
34
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
34
35
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
35
36
|
var import_config = __toModule(require("@lwrjs/config"));
|
|
37
|
+
var import_request_script = __toModule(require("./util/request-script.cjs"));
|
|
36
38
|
var import_generate_entry_plugin = __toModule(require("./plugins/generate-entry-plugin.cjs"));
|
|
37
39
|
var import_build_server_plugin = __toModule(require("./plugins/build-server-plugin.cjs"));
|
|
40
|
+
var REQUEST_SCRIPT_NAME = "index.js";
|
|
38
41
|
async function build(buildOptions, config) {
|
|
39
42
|
const {outputDir, normalizedOutputDir, minify} = buildOptions;
|
|
43
|
+
const ssrMetaContent = {
|
|
44
|
+
minLwcVersion: import_config.MIN_LWC_VERSION,
|
|
45
|
+
minLwrVersion: import_config.MIN_LWR_VERSION
|
|
46
|
+
};
|
|
47
|
+
const ssrMetaJsonContent = JSON.stringify(ssrMetaContent);
|
|
40
48
|
await import_esbuild.default.build({
|
|
41
49
|
entryPoints: ["./lwr.entry.js"],
|
|
42
50
|
bundle: true,
|
|
@@ -61,10 +69,12 @@ async function build(buildOptions, config) {
|
|
|
61
69
|
plugins: [(0, import_generate_entry_plugin.default)(), (0, import_build_server_plugin.default)(config, outputDir)],
|
|
62
70
|
outfile: import_path.default.join(normalizedOutputDir, "ssr.js")
|
|
63
71
|
});
|
|
72
|
+
await import_fs_extra.default.writeFile(import_path.default.join(normalizedOutputDir, REQUEST_SCRIPT_NAME), (0, import_request_script.getMainScriptContent)());
|
|
73
|
+
await import_fs_extra.default.writeFile(import_path.default.join(normalizedOutputDir, "ssr-meta.json"), ssrMetaJsonContent);
|
|
64
74
|
}
|
|
65
75
|
async function buildServer(configArg, options) {
|
|
66
76
|
const startTime = import_perf_hooks.performance.now();
|
|
67
|
-
const outputDir = options?.outputDir
|
|
77
|
+
const outputDir = options?.outputDir ?? "/build";
|
|
68
78
|
const normalizedOutputDir = import_path.default.join(configArg?.rootDir || process.cwd(), outputDir);
|
|
69
79
|
await import_fs_extra.default.ensureDir(normalizedOutputDir);
|
|
70
80
|
await build({outputDir, normalizedOutputDir, minify: !!options?.minify}, configArg);
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/tools/src/util/request-script.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
getMainScriptContent: () => getMainScriptContent
|
|
12
|
+
});
|
|
13
|
+
function getMainScriptContent() {
|
|
14
|
+
return getEnvironmentSetup() + getHandlerFunction() + getDefaultInput() + getDefaultContext() + getParseArguments() + getPrintHelpMessage() + getUpdateInput() + getMainExecution();
|
|
15
|
+
}
|
|
16
|
+
function getEnvironmentSetup() {
|
|
17
|
+
return `
|
|
18
|
+
// Overwrite Envs from SSR.js
|
|
19
|
+
process.env.LWR_TRACING = process.env.LWR_TRACING ?? 'default';
|
|
20
|
+
// Suppress TLS checking for now
|
|
21
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
|
22
|
+
// Set SSR timeout to 30 seconds (allow override)
|
|
23
|
+
process.env.SSR_TIMEOUT = process.env.SSR_TIMEOUT ?? 30000;
|
|
24
|
+
|
|
25
|
+
// Lambda Envs (required by pwa-kit runtime)
|
|
26
|
+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'get';
|
|
27
|
+
process.env.BUNDLE_ID = '1';
|
|
28
|
+
process.env.DEPLOY_TARGET = 'set';
|
|
29
|
+
process.env.EXTERNAL_DOMAIN_NAME = 'mock-domain.example.com';
|
|
30
|
+
process.env.MOBIFY_PROPERTY_ID = 'set';
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
function getHandlerFunction() {
|
|
34
|
+
return `
|
|
35
|
+
/**
|
|
36
|
+
* Main handler function to be invoked by Java client.
|
|
37
|
+
* @param {Object} input - The input object containing JavaScript code.
|
|
38
|
+
* @returns {Promise<Object>} - The result object with linting results.
|
|
39
|
+
*/
|
|
40
|
+
async function handler(input) {
|
|
41
|
+
if (!input) {
|
|
42
|
+
input = DEFAULT_INPUT;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Import the SSR module
|
|
46
|
+
const ssr = require('./ssr.js');
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
ssr.get(input, DEFAULT_CONTEXT, (error, result) => {
|
|
49
|
+
if (error) {
|
|
50
|
+
return reject(error);
|
|
51
|
+
} else {
|
|
52
|
+
// Check if we wanted to override the artifactPath
|
|
53
|
+
if (input.artifactPath && result.body) {
|
|
54
|
+
result.body = result.body.replaceAll(/\\/mobify\\/bundle\\/[a-z0-9]*\\//g, input.artifactPath);
|
|
55
|
+
}
|
|
56
|
+
resolve(result);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
function getDefaultInput() {
|
|
64
|
+
return `
|
|
65
|
+
// Example Input
|
|
66
|
+
const DEFAULT_INPUT = {
|
|
67
|
+
path: '/',
|
|
68
|
+
httpMethod: 'GET',
|
|
69
|
+
headers: {
|
|
70
|
+
host: 'mock-domain.example.com',
|
|
71
|
+
'user-agent': 'curl/7.64.1',
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
function getDefaultContext() {
|
|
77
|
+
return `
|
|
78
|
+
// Define the context object (with basic properties, you can add more as needed)
|
|
79
|
+
const DEFAULT_CONTEXT = {
|
|
80
|
+
awsRequestId: 'test-request-id',
|
|
81
|
+
logGroupName: '/aws/lambda/test',
|
|
82
|
+
logStreamName: 'test-log-stream',
|
|
83
|
+
functionName: 'get',
|
|
84
|
+
functionVersion: '1',
|
|
85
|
+
invokedFunctionArn: 'arn:aws:lambda:test-region:123456789012:function:test-function',
|
|
86
|
+
memoryLimitInMB: '128',
|
|
87
|
+
};
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
function getParseArguments() {
|
|
91
|
+
return `
|
|
92
|
+
// Parse command-line arguments
|
|
93
|
+
function parseArguments() {
|
|
94
|
+
const args = process.argv.slice(2);
|
|
95
|
+
const options = {
|
|
96
|
+
host: null,
|
|
97
|
+
proto: null,
|
|
98
|
+
basePath: null,
|
|
99
|
+
path: DEFAULT_INPUT.path,
|
|
100
|
+
output: null,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
104
|
+
printHelpMessage();
|
|
105
|
+
process.exit(0); // Exit after printing help message
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
args.forEach((arg) => {
|
|
109
|
+
const [key, value] = arg.split('=');
|
|
110
|
+
switch (key) {
|
|
111
|
+
case '--host':
|
|
112
|
+
case '-H':
|
|
113
|
+
options.host = value;
|
|
114
|
+
break;
|
|
115
|
+
case '--proto':
|
|
116
|
+
case '-p':
|
|
117
|
+
options.proto = value;
|
|
118
|
+
break;
|
|
119
|
+
case '--basePath':
|
|
120
|
+
case '-b':
|
|
121
|
+
options.basePath = value;
|
|
122
|
+
break;
|
|
123
|
+
case '--path':
|
|
124
|
+
case '-P':
|
|
125
|
+
options.path = value;
|
|
126
|
+
break;
|
|
127
|
+
case '--output':
|
|
128
|
+
case '-o':
|
|
129
|
+
options.output = value;
|
|
130
|
+
break;
|
|
131
|
+
case '--artifactPath':
|
|
132
|
+
case '-a':
|
|
133
|
+
options.artifactPath = value;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return options;
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
function getPrintHelpMessage() {
|
|
143
|
+
return `
|
|
144
|
+
function printHelpMessage() {
|
|
145
|
+
console.log(
|
|
146
|
+
'Usage: node index.js [options]\\n' +
|
|
147
|
+
'\\n' +
|
|
148
|
+
'Options:\\n' +
|
|
149
|
+
' -H, --host=<host> Specify the host\\n' +
|
|
150
|
+
' -p, --proto=<protocol> Specify the protocol (e.g., http, https)\\n' +
|
|
151
|
+
' -b, --basePath=<basePath> Specify the base path\\n' +
|
|
152
|
+
' -P, --path=<path> Specify the input path (default: ' + DEFAULT_INPUT.path + ')\\n' +
|
|
153
|
+
' -o, --output=<output> Specify the output file path\\n' +
|
|
154
|
+
' -a, --artifactPath=<path> Replace /mobify/bundle/xxx/ with a path provided (e.g. /webruntime/ssr-in-core/)\\n' +
|
|
155
|
+
' -h, --help Show this help message\\n' +
|
|
156
|
+
'\\n' +
|
|
157
|
+
'Example:\\n' +
|
|
158
|
+
' node index.js --host=localhost --proto=http --basePath=/api --path=/data --output=result.json\\n' +
|
|
159
|
+
' node index.js -H=localhost -p=http -b=/api -P=/data -o=result.json\\n'
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
function getUpdateInput() {
|
|
165
|
+
return `
|
|
166
|
+
// Update the DEFAULT_INPUT object based on arguments
|
|
167
|
+
function updateInput(input, args) {
|
|
168
|
+
if (args.host) {
|
|
169
|
+
const proto = args.proto || 'https'; // Default to 'https' if proto is not provided
|
|
170
|
+
input.headers.forwarded = 'host=' + args.host + ';proto=' + proto;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (args.basePath !== null) {
|
|
174
|
+
// Ensure basePath starts with a '/'
|
|
175
|
+
const normalizedBasePath = args.basePath.startsWith('/') ? args.basePath : '/' + args.basePath;
|
|
176
|
+
input.headers['x-mobify-request-class'] = 'basePath=' + normalizedBasePath;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (args.path) {
|
|
180
|
+
input.path = args.path;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (args.artifactPath) {
|
|
184
|
+
input.artifactPath = args.artifactPath;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return input;
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
}
|
|
191
|
+
function getMainExecution() {
|
|
192
|
+
return `
|
|
193
|
+
// Automatically perform a request when this script is executed directly
|
|
194
|
+
if (require.main === module) {
|
|
195
|
+
const args = parseArguments();
|
|
196
|
+
const updatedInput = updateInput(DEFAULT_INPUT, args);
|
|
197
|
+
handler(updatedInput).then((result) => {
|
|
198
|
+
const fs = require('fs');
|
|
199
|
+
const path = require('path');
|
|
200
|
+
|
|
201
|
+
// Write to a file
|
|
202
|
+
if (args.output) {
|
|
203
|
+
fs.writeFileSync(args.output, JSON.stringify(result, null, 2), 'utf-8');
|
|
204
|
+
|
|
205
|
+
const outputPath = args.output;
|
|
206
|
+
const isAbsolutePath = path.isAbsolute(outputPath);
|
|
207
|
+
const filePath = isAbsolutePath ? outputPath : path.resolve(process.cwd(), outputPath);
|
|
208
|
+
|
|
209
|
+
console.log('\\nRequest Saved: \\x1b[34mfile://' + filePath + '\\x1b[0m');
|
|
210
|
+
} else {
|
|
211
|
+
// Print to console
|
|
212
|
+
console.log(result);
|
|
213
|
+
}
|
|
214
|
+
process.exit(0);
|
|
215
|
+
}).catch(err => {
|
|
216
|
+
console.error(err);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
module.exports = handler;
|
|
222
|
+
`;
|
|
223
|
+
}
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
|
@@ -100,10 +100,6 @@ function printRouteHandlers(routeHandlers) {
|
|
|
100
100
|
* @returns esbuild plugin
|
|
101
101
|
*/
|
|
102
102
|
export default function buildLwrServer(config, buildDir) {
|
|
103
|
-
// Lambda always runs one request at a time
|
|
104
|
-
process.env.SINGLE_RENDER_MODE = 'true';
|
|
105
|
-
// TODO: remove once W-16104831 is resolved
|
|
106
|
-
process.env.REEVALUATE_MODULES = 'true';
|
|
107
103
|
return {
|
|
108
104
|
name: 'lwr-server-build',
|
|
109
105
|
setup(build) {
|
|
@@ -4,6 +4,7 @@ export interface BuildOptions {
|
|
|
4
4
|
normalizedOutputDir?: string;
|
|
5
5
|
minify?: boolean;
|
|
6
6
|
}
|
|
7
|
+
export declare const REQUEST_SCRIPT_NAME = "index.js";
|
|
7
8
|
/**
|
|
8
9
|
* Resolve configurations, generate a server build module, and bundle
|
|
9
10
|
* the LWR server. The bundled server will be written to the file system.
|
package/build/es/server-build.js
CHANGED
|
@@ -4,11 +4,18 @@ import esbuild from 'esbuild';
|
|
|
4
4
|
import { performance } from 'perf_hooks';
|
|
5
5
|
import { logger } from '@lwrjs/diagnostics';
|
|
6
6
|
import { getFeatureFlags } from '@lwrjs/shared-utils';
|
|
7
|
-
import { LWR_VERSION, LWC_VERSION, PWA_KIT_RUNTIME_VERSION } from '@lwrjs/config';
|
|
7
|
+
import { LWR_VERSION, LWC_VERSION, PWA_KIT_RUNTIME_VERSION, MIN_LWR_VERSION, MIN_LWC_VERSION, } from '@lwrjs/config';
|
|
8
|
+
import { getMainScriptContent } from './util/request-script.js';
|
|
8
9
|
import generateLwrEntry from './plugins/generate-entry-plugin.js';
|
|
9
10
|
import buildLwrServer from './plugins/build-server-plugin.js';
|
|
11
|
+
export const REQUEST_SCRIPT_NAME = 'index.js';
|
|
10
12
|
async function build(buildOptions, config) {
|
|
11
13
|
const { outputDir, normalizedOutputDir, minify } = buildOptions;
|
|
14
|
+
const ssrMetaContent = {
|
|
15
|
+
minLwcVersion: MIN_LWC_VERSION,
|
|
16
|
+
minLwrVersion: MIN_LWR_VERSION,
|
|
17
|
+
};
|
|
18
|
+
const ssrMetaJsonContent = JSON.stringify(ssrMetaContent);
|
|
12
19
|
// building specifically for MRT/Lambda
|
|
13
20
|
await esbuild.build({
|
|
14
21
|
entryPoints: ['./lwr.entry.js'],
|
|
@@ -41,6 +48,9 @@ async function build(buildOptions, config) {
|
|
|
41
48
|
// MRT expects an entry point named `ssr.js`
|
|
42
49
|
outfile: path.join(normalizedOutputDir, 'ssr.js'),
|
|
43
50
|
});
|
|
51
|
+
// Save the request script to the app folder
|
|
52
|
+
await fs.writeFile(path.join(normalizedOutputDir, REQUEST_SCRIPT_NAME), getMainScriptContent());
|
|
53
|
+
await fs.writeFile(path.join(normalizedOutputDir, 'ssr-meta.json'), ssrMetaJsonContent);
|
|
44
54
|
}
|
|
45
55
|
/**
|
|
46
56
|
* Resolve configurations, generate a server build module, and bundle
|
|
@@ -51,7 +61,7 @@ async function build(buildOptions, config) {
|
|
|
51
61
|
*/
|
|
52
62
|
export async function buildServer(configArg, options) {
|
|
53
63
|
const startTime = performance.now();
|
|
54
|
-
const outputDir = options?.outputDir
|
|
64
|
+
const outputDir = options?.outputDir ?? '/build';
|
|
55
65
|
const normalizedOutputDir = path.join(configArg?.rootDir || process.cwd(), outputDir);
|
|
56
66
|
await fs.ensureDir(normalizedOutputDir);
|
|
57
67
|
await build({ outputDir, normalizedOutputDir, minify: !!options?.minify }, configArg);
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
export function getMainScriptContent() {
|
|
2
|
+
return (getEnvironmentSetup() +
|
|
3
|
+
getHandlerFunction() +
|
|
4
|
+
getDefaultInput() +
|
|
5
|
+
getDefaultContext() +
|
|
6
|
+
getParseArguments() +
|
|
7
|
+
getPrintHelpMessage() +
|
|
8
|
+
getUpdateInput() +
|
|
9
|
+
getMainExecution());
|
|
10
|
+
}
|
|
11
|
+
function getEnvironmentSetup() {
|
|
12
|
+
return `
|
|
13
|
+
// Overwrite Envs from SSR.js
|
|
14
|
+
process.env.LWR_TRACING = process.env.LWR_TRACING ?? 'default';
|
|
15
|
+
// Suppress TLS checking for now
|
|
16
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
|
17
|
+
// Set SSR timeout to 30 seconds (allow override)
|
|
18
|
+
process.env.SSR_TIMEOUT = process.env.SSR_TIMEOUT ?? 30000;
|
|
19
|
+
|
|
20
|
+
// Lambda Envs (required by pwa-kit runtime)
|
|
21
|
+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'get';
|
|
22
|
+
process.env.BUNDLE_ID = '1';
|
|
23
|
+
process.env.DEPLOY_TARGET = 'set';
|
|
24
|
+
process.env.EXTERNAL_DOMAIN_NAME = 'mock-domain.example.com';
|
|
25
|
+
process.env.MOBIFY_PROPERTY_ID = 'set';
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
function getHandlerFunction() {
|
|
29
|
+
return `
|
|
30
|
+
/**
|
|
31
|
+
* Main handler function to be invoked by Java client.
|
|
32
|
+
* @param {Object} input - The input object containing JavaScript code.
|
|
33
|
+
* @returns {Promise<Object>} - The result object with linting results.
|
|
34
|
+
*/
|
|
35
|
+
async function handler(input) {
|
|
36
|
+
if (!input) {
|
|
37
|
+
input = DEFAULT_INPUT;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Import the SSR module
|
|
41
|
+
const ssr = require('./ssr.js');
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
ssr.get(input, DEFAULT_CONTEXT, (error, result) => {
|
|
44
|
+
if (error) {
|
|
45
|
+
return reject(error);
|
|
46
|
+
} else {
|
|
47
|
+
// Check if we wanted to override the artifactPath
|
|
48
|
+
if (input.artifactPath && result.body) {
|
|
49
|
+
result.body = result.body.replaceAll(/\\/mobify\\/bundle\\/[a-z0-9]*\\//g, input.artifactPath);
|
|
50
|
+
}
|
|
51
|
+
resolve(result);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
function getDefaultInput() {
|
|
59
|
+
return `
|
|
60
|
+
// Example Input
|
|
61
|
+
const DEFAULT_INPUT = {
|
|
62
|
+
path: '/',
|
|
63
|
+
httpMethod: 'GET',
|
|
64
|
+
headers: {
|
|
65
|
+
host: 'mock-domain.example.com',
|
|
66
|
+
'user-agent': 'curl/7.64.1',
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
function getDefaultContext() {
|
|
72
|
+
return `
|
|
73
|
+
// Define the context object (with basic properties, you can add more as needed)
|
|
74
|
+
const DEFAULT_CONTEXT = {
|
|
75
|
+
awsRequestId: 'test-request-id',
|
|
76
|
+
logGroupName: '/aws/lambda/test',
|
|
77
|
+
logStreamName: 'test-log-stream',
|
|
78
|
+
functionName: 'get',
|
|
79
|
+
functionVersion: '1',
|
|
80
|
+
invokedFunctionArn: 'arn:aws:lambda:test-region:123456789012:function:test-function',
|
|
81
|
+
memoryLimitInMB: '128',
|
|
82
|
+
};
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
function getParseArguments() {
|
|
86
|
+
return `
|
|
87
|
+
// Parse command-line arguments
|
|
88
|
+
function parseArguments() {
|
|
89
|
+
const args = process.argv.slice(2);
|
|
90
|
+
const options = {
|
|
91
|
+
host: null,
|
|
92
|
+
proto: null,
|
|
93
|
+
basePath: null,
|
|
94
|
+
path: DEFAULT_INPUT.path,
|
|
95
|
+
output: null,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
99
|
+
printHelpMessage();
|
|
100
|
+
process.exit(0); // Exit after printing help message
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
args.forEach((arg) => {
|
|
104
|
+
const [key, value] = arg.split('=');
|
|
105
|
+
switch (key) {
|
|
106
|
+
case '--host':
|
|
107
|
+
case '-H':
|
|
108
|
+
options.host = value;
|
|
109
|
+
break;
|
|
110
|
+
case '--proto':
|
|
111
|
+
case '-p':
|
|
112
|
+
options.proto = value;
|
|
113
|
+
break;
|
|
114
|
+
case '--basePath':
|
|
115
|
+
case '-b':
|
|
116
|
+
options.basePath = value;
|
|
117
|
+
break;
|
|
118
|
+
case '--path':
|
|
119
|
+
case '-P':
|
|
120
|
+
options.path = value;
|
|
121
|
+
break;
|
|
122
|
+
case '--output':
|
|
123
|
+
case '-o':
|
|
124
|
+
options.output = value;
|
|
125
|
+
break;
|
|
126
|
+
case '--artifactPath':
|
|
127
|
+
case '-a':
|
|
128
|
+
options.artifactPath = value;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return options;
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
}
|
|
137
|
+
function getPrintHelpMessage() {
|
|
138
|
+
return `
|
|
139
|
+
function printHelpMessage() {
|
|
140
|
+
console.log(
|
|
141
|
+
'Usage: node index.js [options]\\n' +
|
|
142
|
+
'\\n' +
|
|
143
|
+
'Options:\\n' +
|
|
144
|
+
' -H, --host=<host> Specify the host\\n' +
|
|
145
|
+
' -p, --proto=<protocol> Specify the protocol (e.g., http, https)\\n' +
|
|
146
|
+
' -b, --basePath=<basePath> Specify the base path\\n' +
|
|
147
|
+
' -P, --path=<path> Specify the input path (default: ' + DEFAULT_INPUT.path + ')\\n' +
|
|
148
|
+
' -o, --output=<output> Specify the output file path\\n' +
|
|
149
|
+
' -a, --artifactPath=<path> Replace /mobify/bundle/xxx/ with a path provided (e.g. /webruntime/ssr-in-core/)\\n' +
|
|
150
|
+
' -h, --help Show this help message\\n' +
|
|
151
|
+
'\\n' +
|
|
152
|
+
'Example:\\n' +
|
|
153
|
+
' node index.js --host=localhost --proto=http --basePath=/api --path=/data --output=result.json\\n' +
|
|
154
|
+
' node index.js -H=localhost -p=http -b=/api -P=/data -o=result.json\\n'
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
function getUpdateInput() {
|
|
160
|
+
return `
|
|
161
|
+
// Update the DEFAULT_INPUT object based on arguments
|
|
162
|
+
function updateInput(input, args) {
|
|
163
|
+
if (args.host) {
|
|
164
|
+
const proto = args.proto || 'https'; // Default to 'https' if proto is not provided
|
|
165
|
+
input.headers.forwarded = 'host=' + args.host + ';proto=' + proto;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (args.basePath !== null) {
|
|
169
|
+
// Ensure basePath starts with a '/'
|
|
170
|
+
const normalizedBasePath = args.basePath.startsWith('/') ? args.basePath : '/' + args.basePath;
|
|
171
|
+
input.headers['x-mobify-request-class'] = 'basePath=' + normalizedBasePath;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (args.path) {
|
|
175
|
+
input.path = args.path;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (args.artifactPath) {
|
|
179
|
+
input.artifactPath = args.artifactPath;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return input;
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
}
|
|
186
|
+
function getMainExecution() {
|
|
187
|
+
return `
|
|
188
|
+
// Automatically perform a request when this script is executed directly
|
|
189
|
+
if (require.main === module) {
|
|
190
|
+
const args = parseArguments();
|
|
191
|
+
const updatedInput = updateInput(DEFAULT_INPUT, args);
|
|
192
|
+
handler(updatedInput).then((result) => {
|
|
193
|
+
const fs = require('fs');
|
|
194
|
+
const path = require('path');
|
|
195
|
+
|
|
196
|
+
// Write to a file
|
|
197
|
+
if (args.output) {
|
|
198
|
+
fs.writeFileSync(args.output, JSON.stringify(result, null, 2), 'utf-8');
|
|
199
|
+
|
|
200
|
+
const outputPath = args.output;
|
|
201
|
+
const isAbsolutePath = path.isAbsolute(outputPath);
|
|
202
|
+
const filePath = isAbsolutePath ? outputPath : path.resolve(process.cwd(), outputPath);
|
|
203
|
+
|
|
204
|
+
console.log('\\nRequest Saved: \\x1b[34mfile://' + filePath + '\\x1b[0m');
|
|
205
|
+
} else {
|
|
206
|
+
// Print to console
|
|
207
|
+
console.log(result);
|
|
208
|
+
}
|
|
209
|
+
process.exit(0);
|
|
210
|
+
}).catch(err => {
|
|
211
|
+
console.error(err);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
module.exports = handler;
|
|
217
|
+
`;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=request-script.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.0
|
|
7
|
+
"version": "0.15.0",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"package.cjs"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lwrjs/config": "0.15.0
|
|
38
|
-
"@lwrjs/core": "0.15.0
|
|
39
|
-
"@lwrjs/diagnostics": "0.15.0
|
|
40
|
-
"@lwrjs/shared-utils": "0.15.0
|
|
41
|
-
"@lwrjs/static": "0.15.0
|
|
37
|
+
"@lwrjs/config": "0.15.0",
|
|
38
|
+
"@lwrjs/core": "0.15.0",
|
|
39
|
+
"@lwrjs/diagnostics": "0.15.0",
|
|
40
|
+
"@lwrjs/shared-utils": "0.15.0",
|
|
41
|
+
"@lwrjs/static": "0.15.0",
|
|
42
42
|
"esbuild": "^0.17.4",
|
|
43
43
|
"fs-extra": "^11.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@lwrjs/types": "0.15.0
|
|
46
|
+
"@lwrjs/types": "0.15.0",
|
|
47
47
|
"jest": "^26.6.3",
|
|
48
48
|
"ts-jest": "^26.5.6"
|
|
49
49
|
},
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"volta": {
|
|
57
57
|
"extends": "../../../package.json"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ee374df435d5342f63e4da126a09461e761837f3"
|
|
60
60
|
}
|