edge-functions 1.0.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +60 -15
- package/.github/workflows/major.yml +1 -1
- package/.github/workflows/minor.yml +1 -2
- package/README.md +36 -0
- package/aliases.js +1 -1
- package/docs/overview.md +4 -3
- package/docs/presets.md +18 -6
- package/examples/angular-static/package.json +0 -1
- package/examples/simple-js-esm/main.js +13 -8
- package/examples/simple-js-esm-node/index.js +45 -0
- package/examples/simple-ts-esm/main.ts +24 -0
- package/examples/simple-ts-esm/messages.ts +11 -0
- package/examples/simple-ts-esm/package.json +9 -0
- package/examples/simple-ts-esm/tsconfig.json +109 -0
- package/examples/simple-ts-esm/yarn.lock +8 -0
- package/examples/vue-vite-static/README.md +29 -0
- package/examples/vue-vite-static/index.html +13 -0
- package/examples/vue-vite-static/package.json +18 -0
- package/examples/vue-vite-static/public/favicon.ico +0 -0
- package/examples/vue-vite-static/src/App.vue +85 -0
- package/examples/vue-vite-static/src/assets/base.css +73 -0
- package/examples/vue-vite-static/src/assets/logo.svg +1 -0
- package/examples/vue-vite-static/src/assets/main.css +35 -0
- package/examples/vue-vite-static/src/components/HelloWorld.vue +44 -0
- package/examples/vue-vite-static/src/components/TheWelcome.vue +86 -0
- package/examples/vue-vite-static/src/components/WelcomeItem.vue +86 -0
- package/examples/vue-vite-static/src/components/icons/IconCommunity.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconDocumentation.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconEcosystem.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconSupport.vue +7 -0
- package/examples/vue-vite-static/src/components/icons/IconTooling.vue +19 -0
- package/examples/vue-vite-static/src/main.js +11 -0
- package/examples/vue-vite-static/src/router/index.js +23 -0
- package/examples/vue-vite-static/src/views/AboutView.vue +15 -0
- package/examples/vue-vite-static/src/views/HomeView.vue +9 -0
- package/examples/vue-vite-static/vite.config.js +16 -0
- package/jsconfig.json +1 -1
- package/lib/build/bundlers/esbuild/esbuild.config.js +12 -0
- package/lib/build/bundlers/esbuild/index.js +46 -0
- package/lib/build/bundlers/esbuild/plugins/node-polyfills/index.js +147 -0
- package/lib/build/bundlers/esbuild/plugins/node-polyfills/node-polyfills-paths.js +124 -0
- package/lib/build/bundlers/index.js +2 -2
- package/lib/build/bundlers/webpack/index.js +16 -7
- package/lib/build/bundlers/webpack/webpack.config.js +5 -25
- package/lib/build/dispatcher/dispatcher.js +116 -66
- package/lib/constants/framework-initializer.constants.js +51 -0
- package/lib/constants/index.js +4 -1
- package/lib/constants/messages/build.messages.js +2 -0
- package/lib/constants/messages/env.messages.js +5 -3
- package/lib/constants/messages/global.messages.js +4 -1
- package/lib/env/polyfills/FetchEvent.polyfills.js +13 -0
- package/lib/env/polyfills/fetch.polyfills.js +39 -0
- package/lib/env/polyfills/index.js +4 -0
- package/lib/env/runtime.env.js +57 -63
- package/lib/env/server.env.js +32 -76
- package/lib/main.js +234 -90
- package/lib/notations/namespaces.js +5 -0
- package/lib/platform/actions/core/auth.actions.js +1 -1
- package/lib/platform/actions/core/propagation.actions.js +8 -5
- package/lib/platform/actions/core/storage.actions.js +1 -1
- package/lib/platform/actions/function/showFunctionLogs.actions.js +71 -92
- package/lib/platform/edgehooks/debugRequest/debugRequest.hooks.js +28 -0
- package/lib/platform/edgehooks/debugRequest/index.js +3 -0
- package/lib/platform/edgehooks/index.js +4 -1
- package/lib/polyfills/FetchEvent.polyfills.js +13 -0
- package/lib/polyfills/fetch.polyfills.js +39 -0
- package/lib/polyfills/index.js +4 -0
- package/lib/presets/custom/angular/deliver/config.js +2 -4
- package/lib/presets/custom/angular/deliver/handler.js +12 -5
- package/lib/presets/custom/angular/deliver/prebuild.js +8 -11
- package/lib/presets/custom/astro/deliver/config.js +2 -4
- package/lib/presets/custom/astro/deliver/handler.js +14 -7
- package/lib/presets/custom/astro/deliver/prebuild.js +18 -21
- package/lib/presets/custom/hexo/deliver/config.js +2 -4
- package/lib/presets/custom/hexo/deliver/handler.js +13 -6
- package/lib/presets/custom/hexo/deliver/prebuild.js +18 -21
- package/lib/presets/custom/next/deliver/config.js +2 -6
- package/lib/presets/custom/next/deliver/handler.js +14 -7
- package/lib/presets/custom/next/deliver/prebuild.js +37 -40
- package/lib/presets/custom/react/deliver/config.js +2 -4
- package/lib/presets/custom/react/deliver/handler.js +10 -3
- package/lib/presets/custom/react/deliver/prebuild.js +4 -7
- package/lib/presets/custom/vue/deliver/config.js +2 -4
- package/lib/presets/custom/vue/deliver/handler.js +10 -3
- package/lib/presets/custom/vue/deliver/prebuild.js +66 -10
- package/lib/presets/default/html/deliver/config.js +1 -4
- package/lib/presets/default/html/deliver/handler.js +14 -7
- package/lib/presets/default/html/deliver/prebuild.js +3 -2
- package/lib/presets/default/javascript/compute/config.js +2 -5
- package/lib/presets/default/javascript/compute/handler.js +15 -4
- package/lib/presets/default/javascript/compute/prebuild.js +2 -1
- package/lib/presets/default/typescript/compute/config.js +10 -0
- package/lib/presets/default/typescript/compute/handler.js +16 -0
- package/lib/presets/default/typescript/compute/prebuild.js +7 -0
- package/lib/providers/azion/worker.js +6 -2
- package/lib/utils/exec/exec.utils.js +34 -23
- package/lib/utils/feedback/feedback.utils.js +6 -2
- package/lib/utils/getAbsoluteLibDirPath/getAbsoluteLibDirPath.utils.js +11 -2
- package/lib/utils/getVulcanBuildId/getVulcanBuildId.utils.js +1 -1
- package/lib/utils/index.js +4 -2
- package/lib/utils/overrideStaticOutputPath/overrideStaticOutputPath.utils.js +2 -2
- package/lib/utils/presets/index.js +3 -0
- package/lib/utils/presets/presets.utils.js +169 -0
- package/lib/utils/spinner/index.js +3 -0
- package/lib/utils/spinner/spinner.utils.js +32 -0
- package/package.json +17 -4
- package/examples/hexo-static/yarn.lock +0 -1625
- package/lib/build/polyfills/index.js +0 -0
- package/lib/utils/getPresetsList/getPresetsList.utils.js +0 -50
- package/lib/utils/getPresetsList/index.js +0 -3
- /package/lib/utils/{getPresetsList/getPresetsList.utils.test.js → presets/presets.utils.test.js} +0 -0
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { mountSSG } from
|
|
1
|
+
import { mountSSG } from '#edge';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Handles the 'fetch' event.
|
|
5
|
+
* @param {FetchEvent} event - The fetch event.
|
|
6
|
+
* @returns {Promise<Response>} The response for the request.
|
|
7
|
+
*/
|
|
8
|
+
async function handle(event) {
|
|
9
|
+
try {
|
|
10
|
+
const myApp = await mountSSG(event.request.url, AZION_VERSION_ID);
|
|
11
|
+
return myApp;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
const notFoundError = new URL(`${AZION_VERSION_ID}/404.html`, 'file://');
|
|
14
|
+
return fetch(notFoundError);
|
|
15
|
+
}
|
|
9
16
|
}
|
|
@@ -4,10 +4,11 @@ import { copyDirectory } from '#utils';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Runs custom prebuild actions
|
|
7
|
+
* @param {object} buildContext - info about the build
|
|
7
8
|
*/
|
|
8
|
-
async function prebuild() {
|
|
9
|
+
async function prebuild(buildContext) {
|
|
9
10
|
const sourceDir = process.cwd();
|
|
10
|
-
const targetDir = join('.', '.edge', '
|
|
11
|
+
const targetDir = join('.', '.edge', 'storage');
|
|
11
12
|
|
|
12
13
|
copyDirectory(sourceDir, targetDir);
|
|
13
14
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
__JS_CODE__
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles the 'fetch' event.
|
|
6
|
+
* @param {FetchEvent} event - The fetch event.
|
|
7
|
+
* @returns {Promise<Response>} The response for the request.
|
|
8
|
+
*/
|
|
9
|
+
async function handle(event) {
|
|
10
|
+
try {
|
|
11
|
+
return main(event);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return new Response(e.message || e.toString(), { status: 500 });
|
|
14
|
+
}
|
|
5
15
|
}
|
|
16
|
+
/* eslint-enable */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
__JS_CODE__
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles the 'fetch' event.
|
|
6
|
+
* @param {FetchEvent} event - The fetch event.
|
|
7
|
+
* @returns {Promise<Response>} The response for the request.
|
|
8
|
+
*/
|
|
9
|
+
async function handle(event) {
|
|
10
|
+
try {
|
|
11
|
+
return main(event);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return new Response(e.message || e.toString(), { status: 500 });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/* eslint-enable */
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
__HANDLER__
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Handles the 'fetch' event.
|
|
3
6
|
* @param {FetchEvent} event - The fetch event.
|
|
4
7
|
* @returns {Promise<Response>} The response for the request.
|
|
5
8
|
*/
|
|
6
9
|
async function handleEvent(event) {
|
|
7
|
-
|
|
10
|
+
return handle(event);
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
addEventListener('fetch', (event) => {
|
|
11
14
|
event.respondWith(handleEvent(event));
|
|
12
|
-
});
|
|
15
|
+
});
|
|
16
|
+
/* eslint-enable */
|
|
@@ -9,50 +9,61 @@ import signale from 'signale';
|
|
|
9
9
|
* @param {string} command - The command to be executed.
|
|
10
10
|
* @param {string} [scope='Process'] - Log scope. The default is 'Process'.
|
|
11
11
|
* @param {boolean} [verbose=false] - Whether to display the output in real-time.
|
|
12
|
+
* @param {boolean} [interactive=false] - Whether to allow user
|
|
13
|
+
* interaction with the running process.
|
|
12
14
|
* @returns {Promise<void>} A promise that resolves when the command completes successfully.
|
|
15
|
+
* @throws Will throw an error if the command exits with a non-zero status code.
|
|
13
16
|
* @example
|
|
14
17
|
* // Executing a command without verbose output
|
|
15
18
|
* await exec('npm install');
|
|
16
19
|
*
|
|
17
20
|
* // Executing a command with verbose output
|
|
18
21
|
* await exec('npm run build', 'Build', true);
|
|
22
|
+
*
|
|
23
|
+
* // Executing an interactive command
|
|
24
|
+
* await exec('npx vue create my-project', 'Vue', false, true);
|
|
19
25
|
*/
|
|
20
|
-
async function exec(command, scope = 'Process', verbose = false) {
|
|
26
|
+
async function exec(command, scope = 'Process', verbose = false, interactive = false) {
|
|
21
27
|
const stream = new signale.Signale({ interactive: true, scope: ['Process', scope] });
|
|
22
28
|
|
|
23
29
|
return new Promise((resolve, reject) => {
|
|
24
30
|
const args = command.split(' ');
|
|
25
31
|
const cmd = args.shift();
|
|
26
32
|
|
|
27
|
-
const
|
|
33
|
+
const execProcess = spawn(cmd, args, {
|
|
34
|
+
shell: true,
|
|
35
|
+
stdio: interactive ? 'inherit' : 'pipe',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!interactive) {
|
|
39
|
+
if (verbose) {
|
|
40
|
+
execProcess.stdout.on('data', (data) => {
|
|
41
|
+
stream.info(data.toString());
|
|
42
|
+
});
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
execProcess.stderr.on('data', (data) => {
|
|
45
|
+
const dataStr = data.toString();
|
|
46
|
+
if (dataStr.toLowerCase().includes('error')) {
|
|
47
|
+
stream.error(dataStr);
|
|
48
|
+
} else {
|
|
49
|
+
stream.info(dataStr);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
execProcess.on('error', (error) => {
|
|
55
|
+
reject(error);
|
|
32
56
|
});
|
|
33
57
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (dataStr.toLowerCase().includes('error')) {
|
|
38
|
-
stream.error(dataStr);
|
|
58
|
+
execProcess.on('close', (code) => {
|
|
59
|
+
if (code === 0) {
|
|
60
|
+
resolve();
|
|
39
61
|
} else {
|
|
40
|
-
|
|
62
|
+
reject(new Error(`Command '${command}' failed with code ${code}`));
|
|
41
63
|
}
|
|
42
64
|
});
|
|
43
65
|
}
|
|
44
|
-
|
|
45
|
-
buildProcess.on('error', (error) => {
|
|
46
|
-
reject(error);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
buildProcess.on('close', (code) => {
|
|
50
|
-
if (code === 0) {
|
|
51
|
-
resolve();
|
|
52
|
-
} else {
|
|
53
|
-
reject(new Error(`Command '${command}' failed with code ${code}`));
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
66
|
});
|
|
57
67
|
}
|
|
68
|
+
|
|
58
69
|
export default exec;
|
|
@@ -57,10 +57,14 @@ if (cleanOutputEnabled) {
|
|
|
57
57
|
*/
|
|
58
58
|
const scopes = {
|
|
59
59
|
...global,
|
|
60
|
+
interactive: { ...getLogger({ interactive: true, scope: ['Vulcan'], types: methods }) },
|
|
61
|
+
server: { ...global.scope('Vulcan', 'Server'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Server'], types: methods }) },
|
|
62
|
+
runtime: { ...global.scope('Vulcan', 'Runtime'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Runtime'], types: methods }) },
|
|
60
63
|
prebuild: { ...global.scope('Vulcan', 'Pre Build'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Pre Build'], types: methods }) },
|
|
61
64
|
build: { ...global.scope('Vulcan', 'Build'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Build'], types: methods }) },
|
|
62
|
-
platform: { ...global.scope('Vulcan', 'Platform'), interactive: getLogger({ interactive: true, scope: ['Vulcan', '
|
|
63
|
-
statics: { ...global.scope('Vulcan', '
|
|
65
|
+
platform: { ...global.scope('Vulcan', 'Platform'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Platform'], types: methods }) },
|
|
66
|
+
statics: { ...global.scope('Vulcan', 'Storage'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'storage'], types: methods }) },
|
|
67
|
+
logs: (scope1, scope2, scope3) => ({ ...global.scope('Azion', `${scope1}`, scope2, scope3) }),
|
|
64
68
|
propagation: { ...global.scope('Azion', 'Edge Network'), interactive: getLogger({ interactive: true, scope: ['Vulcan', 'Azion Network'], types: methods }) },
|
|
65
69
|
};
|
|
66
70
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const isWindows = process.platform === 'win32';
|
|
1
2
|
/**
|
|
2
3
|
* Get the absolute path of the lib directory based on the current module.
|
|
3
4
|
* @function
|
|
@@ -8,12 +9,20 @@
|
|
|
8
9
|
*
|
|
9
10
|
* // Example usage:
|
|
10
11
|
* const libDirPath = getAbsoluteLibDirPath();
|
|
11
|
-
* console.log(libDirPath); //
|
|
12
|
+
* console.log(libDirPath); // 'lib/full/path/to/directory'
|
|
12
13
|
*/
|
|
13
14
|
function getAbsoluteLibDirPath() {
|
|
14
15
|
const currentModuleFullPath = import.meta.url;
|
|
15
16
|
let baselibPath = currentModuleFullPath.match(/(.*lib)(.*)/)[1];
|
|
16
|
-
|
|
17
|
+
if (isWindows) {
|
|
18
|
+
baselibPath = new URL(baselibPath).pathname;
|
|
19
|
+
if (baselibPath.startsWith('/')) {
|
|
20
|
+
baselibPath = baselibPath.slice(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!isWindows) {
|
|
24
|
+
baselibPath = baselibPath.replace('file://', '');
|
|
25
|
+
}
|
|
17
26
|
|
|
18
27
|
return baselibPath;
|
|
19
28
|
}
|
package/lib/utils/index.js
CHANGED
|
@@ -6,11 +6,12 @@ import generateTimestamp from './generateTimestamp/index.js';
|
|
|
6
6
|
import getAbsoluteLibDirPath from './getAbsoluteLibDirPath/index.js';
|
|
7
7
|
import getVulcanBuildId from './getVulcanBuildId/index.js';
|
|
8
8
|
import getPackageManager from './getPackageManager/index.js';
|
|
9
|
-
import
|
|
9
|
+
import presets from './presets/index.js';
|
|
10
10
|
import readWorkerFile from './readWorkerFile/index.js';
|
|
11
11
|
import overrideStaticOutputPath from './overrideStaticOutputPath/index.js';
|
|
12
12
|
import getProjectJsonFile from './getProjectJsonFile/index.js';
|
|
13
13
|
import getPackageVersion from './getPackageVersion/index.js';
|
|
14
|
+
import Spinner from './spinner/index.js';
|
|
14
15
|
|
|
15
16
|
export {
|
|
16
17
|
copyDirectory,
|
|
@@ -23,7 +24,8 @@ export {
|
|
|
23
24
|
getPackageVersion,
|
|
24
25
|
getProjectJsonFile,
|
|
25
26
|
getVulcanBuildId,
|
|
26
|
-
|
|
27
|
+
presets,
|
|
27
28
|
overrideStaticOutputPath,
|
|
28
29
|
readWorkerFile,
|
|
30
|
+
Spinner,
|
|
29
31
|
};
|
|
@@ -12,13 +12,13 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
12
12
|
* The regex pattern should include a capturing group (i.e., (.*) )
|
|
13
13
|
* to identify the value to be replaced.
|
|
14
14
|
* For example, /out:(.*)\n/.
|
|
15
|
-
* @param {string} [newOutputPath='.edge/
|
|
15
|
+
* @param {string} [newOutputPath='.edge/storage'] - The default is '.edge/storage'.
|
|
16
16
|
* @throws Will throw an error if the function fails to override the output path.
|
|
17
17
|
* @example
|
|
18
18
|
*
|
|
19
19
|
* overrideStaticOutputPath('./config.js', /out:(.*)\n/);
|
|
20
20
|
*/
|
|
21
|
-
function overrideStaticOutputPath(configFilePath, regexPattern, newOutputPath = '.edge/
|
|
21
|
+
function overrideStaticOutputPath(configFilePath, regexPattern, newOutputPath = '.edge/storage') {
|
|
22
22
|
try {
|
|
23
23
|
const fileContent = readFileSync(configFilePath, 'utf-8');
|
|
24
24
|
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const isWindows = process.platform === 'win32';
|
|
5
|
+
const currentModuleFullPath = import.meta.url;
|
|
6
|
+
let baselibPath = currentModuleFullPath.match(/(.*lib)(.*)/)[1];
|
|
7
|
+
|
|
8
|
+
if (isWindows) {
|
|
9
|
+
baselibPath = new URL(baselibPath).pathname;
|
|
10
|
+
if (baselibPath.startsWith('/')) {
|
|
11
|
+
baselibPath = baselibPath.slice(1);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (!isWindows) {
|
|
15
|
+
baselibPath = baselibPath.replace('file://', '');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves a list of presets from 'default' and 'custom' directories in a beautified format.
|
|
20
|
+
* Unlike `getKeys`, this method returns preset names formatted
|
|
21
|
+
* for display and includes modes like '(Static)' or '(Server)'.
|
|
22
|
+
* @function
|
|
23
|
+
* @memberof presets
|
|
24
|
+
* @name getBeautify
|
|
25
|
+
* @param {string[]} [types=['default', 'custom']] - The types of presets to list.
|
|
26
|
+
* Each type corresponds to a folder in the 'presets' directory.
|
|
27
|
+
* @returns {string[]} The list of presets with modes like '(Static)' or '(Server)' if applicable.
|
|
28
|
+
* @example
|
|
29
|
+
* const presetsList = getBeautify(['default', 'custom']);
|
|
30
|
+
* console.log(presetsList);
|
|
31
|
+
* // Output might be: ['Angular (Static)', 'React (Server)', 'Vue (Static)']
|
|
32
|
+
*/
|
|
33
|
+
function getBeautify(types = ['default', 'custom']) {
|
|
34
|
+
const presets = [];
|
|
35
|
+
|
|
36
|
+
types.forEach((type) => {
|
|
37
|
+
const presetsDir = path.join(baselibPath, `presets/${type}`);
|
|
38
|
+
const folders = fs
|
|
39
|
+
.readdirSync(presetsDir, { withFileTypes: true })
|
|
40
|
+
|
|
41
|
+
.filter((dirent) => dirent.isDirectory())
|
|
42
|
+
.flatMap((dirent) => {
|
|
43
|
+
const presetName = dirent.name;
|
|
44
|
+
const subDirs = fs
|
|
45
|
+
.readdirSync(path.join(presetsDir, presetName), {
|
|
46
|
+
withFileTypes: true,
|
|
47
|
+
})
|
|
48
|
+
.filter((subDirent) => subDirent.isDirectory());
|
|
49
|
+
|
|
50
|
+
if (subDirs.length === 0) {
|
|
51
|
+
return [presetName.charAt(0).toUpperCase() + presetName.slice(1)];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return subDirs.map((subDir) => {
|
|
55
|
+
const subDirName = subDir.name.charAt(0).toUpperCase() + subDir.name.slice(1);
|
|
56
|
+
return `${
|
|
57
|
+
presetName.charAt(0).toUpperCase() + presetName.slice(1)
|
|
58
|
+
} (${subDirName})`;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
presets.push(...folders);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return presets;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves an array of valid preset keys by scanning through
|
|
70
|
+
* the preset directories 'default' and 'custom'.
|
|
71
|
+
* Each folder name in these directories is considered as a valid preset key.
|
|
72
|
+
* Unlike `getBeautify`, this method returns raw preset names without any formatting or modes.
|
|
73
|
+
* @function
|
|
74
|
+
* @memberof presets
|
|
75
|
+
* @name getKeys
|
|
76
|
+
* @returns {string[]} An array of valid build presets.
|
|
77
|
+
* @example
|
|
78
|
+
* const validPresetsKeys = getKeys();
|
|
79
|
+
* console.log(validKeys);
|
|
80
|
+
* // Output might be: ['angular', 'react', 'vue']
|
|
81
|
+
* @throws {Error} Throws an error if unable to read the directory.
|
|
82
|
+
*/
|
|
83
|
+
function getKeys() {
|
|
84
|
+
const types = ['default', 'custom'];
|
|
85
|
+
const validPresets = [];
|
|
86
|
+
|
|
87
|
+
types.forEach((type) => {
|
|
88
|
+
const presetsPath = path.join(baselibPath, 'presets', type);
|
|
89
|
+
const directories = fs
|
|
90
|
+
.readdirSync(presetsPath, { withFileTypes: true })
|
|
91
|
+
.filter((dirent) => dirent.isDirectory())
|
|
92
|
+
.map((dirent) => dirent.name);
|
|
93
|
+
|
|
94
|
+
validPresets.push(...directories);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return validPresets;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new preset in the lib/presets/custom/${mode} directory.
|
|
102
|
+
* Also generates three required files: handler.js, prebuild.js, and config.js.
|
|
103
|
+
* @function
|
|
104
|
+
* @memberof utils
|
|
105
|
+
* @name set
|
|
106
|
+
* @param {string} name - The name of the new preset.
|
|
107
|
+
* @param {'compute'|'deliver'} mode - The mode for the preset, either 'compute' or 'deliver'.
|
|
108
|
+
* @throws {Error} Throws an error if a preset with the same name
|
|
109
|
+
* already exists or if mode is invalid.
|
|
110
|
+
* @example
|
|
111
|
+
*
|
|
112
|
+
* // Create a new preset named 'MyPreset' in 'compute' mode
|
|
113
|
+
* presets.set('MyPreset', 'compute');
|
|
114
|
+
*/
|
|
115
|
+
function set(name, mode) {
|
|
116
|
+
const presetPath = path.join(baselibPath, 'presets', 'custom', name, mode);
|
|
117
|
+
fs.mkdirSync(presetPath, { recursive: true });
|
|
118
|
+
|
|
119
|
+
if (mode === 'compute') {
|
|
120
|
+
const defaultFilesPath = path.join(
|
|
121
|
+
baselibPath,
|
|
122
|
+
'presets',
|
|
123
|
+
'default',
|
|
124
|
+
'javascript',
|
|
125
|
+
'compute',
|
|
126
|
+
);
|
|
127
|
+
const filesToCopy = ['handler.js', 'config.js', 'prebuild.js'];
|
|
128
|
+
|
|
129
|
+
filesToCopy.forEach((file) => {
|
|
130
|
+
const srcPath = path.join(defaultFilesPath, file);
|
|
131
|
+
const destPath = path.join(presetPath, file);
|
|
132
|
+
fs.copyFileSync(srcPath, destPath);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (mode === 'deliver') {
|
|
136
|
+
// TODO: Create template for 'deliver' mode init
|
|
137
|
+
fs.writeFileSync(path.join(presetPath, 'handler.js'), '');
|
|
138
|
+
fs.writeFileSync(path.join(presetPath, 'prebuild.js'), '');
|
|
139
|
+
fs.writeFileSync(path.join(presetPath, 'config.js'), '');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Presets object containing utility functions for working with build presets.
|
|
145
|
+
* @memberof utils
|
|
146
|
+
* @property {Function} getKeys - Function to retrieve an array of valid preset keys.
|
|
147
|
+
* These keys are raw and do not include any modes or formatting.
|
|
148
|
+
* @property {Function} getBeautify - Function to retrieve a list of presets in a beautified format.
|
|
149
|
+
* Unlike `getKeys`, the names are formatted and include modes like '(Static)' or '(Server)'.
|
|
150
|
+
* @property {Function} set - Function to create a new preset along with its required files.
|
|
151
|
+
* @example
|
|
152
|
+
* import { presets } from '#utils';
|
|
153
|
+
*
|
|
154
|
+
* // Get raw preset keys
|
|
155
|
+
* const rawKeys = presets.getKeys();
|
|
156
|
+
*
|
|
157
|
+
* // Get beautified preset names
|
|
158
|
+
* const beautifiedNames = presets.getBeautify();
|
|
159
|
+
*
|
|
160
|
+
* // Create a new preset
|
|
161
|
+
* presets.set('MyNewPreset', 'compute');
|
|
162
|
+
*/
|
|
163
|
+
const presets = {
|
|
164
|
+
getKeys,
|
|
165
|
+
getBeautify,
|
|
166
|
+
set,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default presets;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import signale from 'signale';
|
|
2
|
+
|
|
3
|
+
class Spinner {
|
|
4
|
+
constructor(action) {
|
|
5
|
+
this.action = action;
|
|
6
|
+
this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
7
|
+
this.intervalId = null;
|
|
8
|
+
this.currentFrameIndex = 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
start() {
|
|
12
|
+
signale.pending(`Starting ${this.action}...`);
|
|
13
|
+
|
|
14
|
+
this.intervalId = setInterval(() => {
|
|
15
|
+
const frame = this.frames[this.currentFrameIndex];
|
|
16
|
+
process.stdout.write(`\r${frame} Running ${this.action} ...`);
|
|
17
|
+
this.currentFrameIndex = (this.currentFrameIndex + 1) % this.frames.length;
|
|
18
|
+
}, 100);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
stop() {
|
|
22
|
+
clearInterval(this.intervalId);
|
|
23
|
+
signale.success(`${this.action} complete!`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fail() {
|
|
27
|
+
clearInterval(this.intervalId);
|
|
28
|
+
signale.error(`${this.action} error`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default Spinner;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-functions",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.",
|
|
6
6
|
"main": "lib/main.js",
|
|
7
7
|
"bin": {
|
|
@@ -34,16 +34,29 @@
|
|
|
34
34
|
],
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@angular/cli": "^16.2.0",
|
|
38
|
+
"@edge-runtime/node-utils": "^2.1.1",
|
|
39
|
+
"@edge-runtime/primitives": "^3.0.4",
|
|
37
40
|
"@semantic-release/changelog": "^6.0.3",
|
|
38
41
|
"@semantic-release/commit-analyzer": "^10.0.1",
|
|
39
42
|
"@semantic-release/git": "^10.0.1",
|
|
40
43
|
"@semantic-release/npm": "^10.0.4",
|
|
41
44
|
"@semantic-release/release-notes-generator": "^11.0.4",
|
|
45
|
+
"@vue/cli": "^5.0.8",
|
|
42
46
|
"bottleneck": "^2.19.5",
|
|
43
47
|
"chokidar": "^3.5.3",
|
|
44
48
|
"commander": "^10.0.1",
|
|
45
49
|
"conventional-changelog-conventionalcommits": "^6.1.0",
|
|
50
|
+
"create-astro": "^3.2.2",
|
|
51
|
+
"create-next-app": "^13.4.19",
|
|
52
|
+
"create-react-app": "^5.0.1",
|
|
53
|
+
"create-vue": "^3.7.3",
|
|
54
|
+
"deepmerge": "^4.3.1",
|
|
55
|
+
"edge-runtime": "^2.4.5",
|
|
56
|
+
"esbuild": "^0.18.11",
|
|
57
|
+
"escape-string-regexp": "^5.0.0",
|
|
46
58
|
"form-data": "^4.0.0",
|
|
59
|
+
"hexo": "^7.0.0-rc2",
|
|
47
60
|
"inquirer": "^9.2.7",
|
|
48
61
|
"install": "^0.13.0",
|
|
49
62
|
"lodash": "^4.17.21",
|
|
@@ -51,8 +64,8 @@
|
|
|
51
64
|
"mime-types": "^2.1.35",
|
|
52
65
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
53
66
|
"npm": "^9.8.0",
|
|
54
|
-
"open": "^9.1.0",
|
|
55
67
|
"pkg-dir": "^7.0.0",
|
|
68
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
56
69
|
"semantic-release": "^21.0.7",
|
|
57
70
|
"semver": "^7.5.2",
|
|
58
71
|
"signale": "^1.4.0",
|
|
@@ -79,7 +92,7 @@
|
|
|
79
92
|
"#root/*": "./",
|
|
80
93
|
"#lib/*": "./lib",
|
|
81
94
|
"#utils": "./lib/utils/index.js",
|
|
82
|
-
"#polyfills": "./lib/
|
|
95
|
+
"#polyfills": "./lib/env/polyfills/index.js",
|
|
83
96
|
"#build": "./lib/build/dispatcher/index.js",
|
|
84
97
|
"#bundlers": "./lib/build/bundlers/index.js",
|
|
85
98
|
"#notations/*": "./lib/notations",
|
|
@@ -96,4 +109,4 @@
|
|
|
96
109
|
"url": "https://github.com/aziontech/vulcan/issues"
|
|
97
110
|
},
|
|
98
111
|
"homepage": "https://github.com/aziontech/vulcan#readme"
|
|
99
|
-
}
|
|
112
|
+
}
|