edge-functions 2.12.1 → 3.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [3.0.0](https://github.com/aziontech/vulcan/compare/v2.12.1...v3.0.0) (2024-07-29)
2
+
3
+
4
+ ### ⚠ BREAKING CHANGES
5
+
6
+ * change init command behavior.
7
+
8
+ ### Miscellaneous Chores
9
+
10
+ * remove init cmd ([#364](https://github.com/aziontech/vulcan/issues/364)) ([eeb26bd](https://github.com/aziontech/vulcan/commit/eeb26bdac9a3f877cf54741b321e658ea5719158))
11
+
12
+ ## [3.0.0-stage.1](https://github.com/aziontech/vulcan/compare/v2.12.1...v3.0.0-stage.1) (2024-07-25)
13
+
14
+
15
+ ### ⚠ BREAKING CHANGES
16
+
17
+ * change init command behavior.
18
+
19
+ ### Miscellaneous Chores
20
+
21
+ * remove init cmd ([#364](https://github.com/aziontech/vulcan/issues/364)) ([eeb26bd](https://github.com/aziontech/vulcan/commit/eeb26bdac9a3f877cf54741b321e658ea5719158))
22
+
1
23
  ### [2.12.1](https://github.com/aziontech/vulcan/compare/v2.12.0...v2.12.1) (2024-07-16)
2
24
 
3
25
 
package/README.md CHANGED
@@ -43,7 +43,7 @@ Table:
43
43
  | Simple Js Esm | ✅ |
44
44
  | Simple Ts Esm | ✅ |
45
45
 
46
- Last test run date: 07/16/24 03:27:44 AM
46
+ Last test run date: 07/29/24 03:38:09 AM
47
47
  ## Quick Installation
48
48
 
49
49
  For those who just want to use Vulcan in their project without contributing to the development, you can install it directly from npm.
@@ -1,131 +1,38 @@
1
- import { join } from 'path';
2
- import { existsSync } from 'fs';
3
- import inquirer, { createPromptModule } from 'inquirer';
4
- import { TemplatesInitializer, TemplatesOptions, Messages } from '#constants';
5
- import { feedback, debug } from '#utils';
6
1
  import { vulcan } from '#env';
2
+ import { feedback } from '#utils';
7
3
 
8
4
  import { Commands } from '#namespaces';
9
5
 
10
- const prompt = createPromptModule();
11
-
12
6
  /**
13
- * @description Get the selected template from the user
14
- * @param {Array} templateOptions - Array of template options
15
- * @param {string} template - Preset to select
16
- * @returns {object} - The selected template
7
+ * Throw a required attribute error.
8
+ * @param {string} arg - attribute that is required
9
+ * @throws {Error} - throws error based on arg
17
10
  */
18
- async function getTemplateSelection(templateOptions, template) {
19
- if (template) {
20
- const templateSelectionByLine = templateOptions.find(
21
- (option) => option.message === template,
22
- );
23
- if (templateSelectionByLine) {
24
- return templateSelectionByLine;
25
- }
26
- }
27
-
28
- if (templateOptions.length > 1) {
29
- const { templateChoice } = await inquirer.prompt([
30
- {
31
- type: 'list',
32
- name: 'templateChoice',
33
- message: 'Choose the template:',
34
- choices: templateOptions.map((option) => ({
35
- name: option.message,
36
- value: option,
37
- })),
38
- },
39
- ]);
40
- return templateChoice;
41
- }
42
-
43
- return templateOptions[0]; // Assuming the first option is the default
11
+ function throwError(arg) {
12
+ throw new Error(`'${arg}' is required.`);
44
13
  }
45
14
 
46
15
  /**
47
16
  * @function
48
17
  * @memberof Commands
49
- * @description Initializes a new project based on the selected framework template.
50
- * @param {object} options - Configuration options for initialization.
51
- * @param {string} options.template - Template to use for the project.
52
- * @param {string} options.preset - Preset to use for the project.
53
- * @param {string} options.name - Name of the new project.
54
- * If not provided, the function will prompt for it.
55
- * @example
56
- * initCommand({ name: 'my_new_project' });
18
+ * @description Initializes a new '.vulcan' file.
19
+ * @param {object} options - Configuration options for file initialization.
20
+ * @param {string} options.preset - Used preset.
21
+ * @param {string} options.mode - Used preset mode.
22
+ * @param {string} options.scope - Base path to create the file.
57
23
  */
58
- async function initCommand({ name, template, preset }) {
24
+ async function initCommand({ preset, mode, scope }) {
59
25
  try {
60
- const AVAILABLE_PRESETS = Object.keys(TemplatesInitializer);
61
- let projectName = name;
62
- let templateOptions = [];
63
- let frameworkChoice;
64
- const isPresetAvailable = AVAILABLE_PRESETS.find((t) => t === preset);
65
-
66
- if (!isPresetAvailable && preset) {
67
- feedback.error(
68
- 'The option entered does not exist, please select one of the options below.',
69
- );
70
- }
71
-
72
- if (!isPresetAvailable) {
73
- const { frameworkChoiceOps } = await prompt([
74
- {
75
- type: 'list',
76
- name: 'frameworkChoiceOps',
77
- message: 'Choose a preset for your project:',
78
- choices: AVAILABLE_PRESETS,
79
- pageSize: AVAILABLE_PRESETS.length,
80
- },
81
- ]);
82
- frameworkChoice = frameworkChoiceOps;
83
- } else {
84
- frameworkChoice = preset;
85
- }
86
- templateOptions = TemplatesOptions[frameworkChoice]?.options || [];
87
-
88
- const templateSelection = await getTemplateSelection(
89
- templateOptions,
90
- template,
91
- );
92
-
93
- while (!projectName) {
94
- const dirExists = (dirName) => existsSync(join(process.cwd(), dirName));
95
-
96
- // eslint-disable-next-line no-await-in-loop
97
- const { projectName: inputName } = await prompt([
98
- {
99
- type: 'input',
100
- name: 'projectName',
101
- message: 'Enter your project name:',
102
- },
103
- ]);
26
+ if (!preset) throwError('preset');
27
+ if (!mode) throwError('mode');
28
+ if (!scope) throwError('scope');
104
29
 
105
- if (inputName && !dirExists(inputName)) {
106
- projectName = inputName;
107
- } else if (dirExists(inputName)) {
108
- feedback.pending(Messages.errors.folder_name_already_exists(inputName));
109
- } else {
110
- feedback.pending(Messages.info.name_required);
111
- }
112
- }
30
+ await vulcan.createVulcanEnv({ preset, mode }, scope);
113
31
 
114
- const createFrameworkTemplate = TemplatesInitializer[frameworkChoice];
115
- if (createFrameworkTemplate) {
116
- const dest = join(process.cwd(), projectName);
117
- feedback.interactive.await(Messages.init.info.preparing);
118
- await createFrameworkTemplate(projectName, templateSelection.value);
119
- feedback.interactive.success(Messages.init.success.ready);
120
- await vulcan.createVulcanEnv(
121
- { preset: frameworkChoice.toLowerCase(), mode: templateSelection.mode },
122
- dest,
123
- );
124
- } else {
125
- feedback.error(Messages.errors.invalid_choice);
126
- }
32
+ feedback.info(`'.vulcan file created!'`);
127
33
  } catch (error) {
128
- debug.error(error);
34
+ feedback.error(`Error creating '.vulcan' file: ${error.message}`);
35
+ process.exit(1);
129
36
  }
130
37
  }
131
38
 
@@ -1,15 +1,5 @@
1
1
  import RuntimeApis from './runtime-apis.constants.js';
2
2
  import AzionEdges from './azion-edges.constants.js';
3
3
  import Messages from './messages/index.js';
4
- import {
5
- TemplatesInitializer,
6
- TemplatesOptions,
7
- } from './framework-initializer.constants.js';
8
4
 
9
- export {
10
- AzionEdges,
11
- RuntimeApis,
12
- Messages,
13
- TemplatesInitializer,
14
- TemplatesOptions,
15
- };
5
+ export { AzionEdges, RuntimeApis, Messages };
@@ -1,11 +1,9 @@
1
1
  import build from './build.messages.js';
2
2
  import env from './env.messages.js';
3
- import init from './init.messages.js';
4
3
  import global from './global.messages.js'; // generic messages
5
4
 
6
5
  const Messages = {
7
6
  env,
8
- init,
9
7
  build,
10
8
  ...global,
11
9
  };
package/lib/main.js CHANGED
@@ -116,10 +116,10 @@ function startVulcanProgram() {
116
116
 
117
117
  program
118
118
  .command('init')
119
- .option('--name <project_name>', 'Project name')
120
119
  .option('--preset <preset_name>', 'Preset name', false)
121
- .option('--template <template_name>', 'Template name', false)
122
- .description('Initialize a new project')
120
+ .option('--mode <preset_mode>', 'Preset mode', false)
121
+ .option('--scope <scope>', 'project scope - base path', false)
122
+ .description('Initialize .vulcan file')
123
123
  .action(async (options) => {
124
124
  const { initCommand } = await import('#commands');
125
125
  await initCommand(options);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "edge-functions",
3
3
  "type": "module",
4
- "version": "2.12.1",
4
+ "version": "3.0.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": {
@@ -1,190 +0,0 @@
1
- import { exec } from '#utils';
2
-
3
- const generateCloneCommand = (projectName, subdirectory) => {
4
- const fullPath = `templates/${subdirectory}`;
5
-
6
- return `
7
- mkdir ${projectName}
8
- cd ${projectName}
9
- git init
10
- git remote add -f origin https://github.com/aziontech/vulcan-examples.git > /dev/null 2>&1
11
- git config core.sparseCheckout true
12
- echo "${fullPath}/*" >> .git/info/sparse-checkout
13
- git pull origin main > /dev/null 2>&1
14
- mv ${fullPath}/* ./
15
- rm -rf templates .git
16
- `.trim();
17
- };
18
-
19
- const TemplatesOptions = {
20
- JavaScript: {
21
- options: [
22
- {
23
- value: 'javascript/simple-js-router',
24
- message: 'Simple JS Router',
25
- mode: 'compute',
26
- },
27
- {
28
- value: 'javascript/simple-js-node',
29
- message: 'Simple Node.js with Polyfills',
30
- mode: 'compute',
31
- },
32
- ],
33
- },
34
- TypeScript: {
35
- options: [{ value: 'typescript/simple-ts-router', mode: 'compute' }],
36
- },
37
- Angular: {
38
- options: [
39
- { value: 'angular-static', message: 'static supported', mode: 'deliver' },
40
- ],
41
- },
42
- Astro: {
43
- options: [
44
- { value: 'astro-static', message: 'static supported', mode: 'deliver' },
45
- ],
46
- },
47
- Gatsby: {
48
- options: [
49
- { value: 'gatsby-static', message: 'static supported', mode: 'deliver' },
50
- ],
51
- },
52
- Hexo: {
53
- options: [
54
- { value: 'hexo-static', message: 'static supported', mode: 'deliver' },
55
- ],
56
- },
57
- Jekyll: {
58
- options: [
59
- { value: 'jekyll-static', message: 'static supported', mode: 'deliver' },
60
- ],
61
- },
62
- Next: {
63
- options: [
64
- {
65
- value: 'nextjs/next-13-static',
66
- message: 'Next 13 - Static (export)',
67
- mode: 'deliver',
68
- },
69
- {
70
- value: 'nextjs/edge-app-13-5-6',
71
- message: 'Next 13 - Edge Runtime (App Router) ',
72
- mode: 'compute',
73
- },
74
- {
75
- value: 'nextjs/edge-pages-13-5-6',
76
- message: 'Next 13 - Edge Runtime (Pages Router)',
77
- mode: 'compute',
78
- },
79
- {
80
- value: 'nextjs/node-pages-12-3-1',
81
- message: 'Next 12 - Node Runtime (Edge compatible with polyfills)',
82
- mode: 'compute',
83
- },
84
- ],
85
- },
86
- React: {
87
- options: [
88
- { value: 'react-static', message: 'static supported', mode: 'deliver' },
89
- ],
90
- },
91
- Svelte: {
92
- options: [
93
- { value: 'svelte-static', message: 'static supported', mode: 'deliver' },
94
- ],
95
- },
96
- Vue: {
97
- options: [
98
- { value: 'vue-static', message: 'static supported', mode: 'deliver' },
99
- ],
100
- },
101
- Vite: {
102
- options: [
103
- {
104
- value: 'vue3-vite-static',
105
- message: 'static supported',
106
- mode: 'deliver',
107
- },
108
- ],
109
- },
110
- Emscripten: {
111
- options: [{ value: 'emscripten-wasm', mode: 'compute' }],
112
- },
113
- Rustwasm: {
114
- options: [{ value: 'rust-wasm-yew-ssr', mode: 'compute' }],
115
- },
116
- Eleventy: {
117
- options: [
118
- {
119
- value: 'eleventy-static',
120
- message: 'static supported',
121
- mode: 'deliver',
122
- },
123
- ],
124
- },
125
- };
126
-
127
- const TemplatesInitializer = {
128
- JavaScript: async (projectName, subdirectory) => {
129
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
130
- await exec(cloneCommands, 'JavaScript', false, false);
131
- },
132
- TypeScript: async (projectName, subdirectory) => {
133
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
134
- await exec(cloneCommands, 'TypeScript', false, false);
135
- },
136
- Rustwasm: async (projectName, subdirectory) => {
137
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
138
- await exec(cloneCommands, 'RustWasm', false, false);
139
- },
140
- Emscripten: async (projectName, subdirectory) => {
141
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
142
- await exec(cloneCommands, 'Emscripten', false, false);
143
- },
144
- Angular: async (projectName, subdirectory) => {
145
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
146
- await exec(cloneCommands, 'Angular', false, false);
147
- },
148
- Astro: async (projectName, subdirectory) => {
149
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
150
- await exec(cloneCommands, 'Astro', false, false);
151
- },
152
- Gatsby: async (projectName, subdirectory) => {
153
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
154
- await exec(cloneCommands, 'Gatsby', false, false);
155
- },
156
- Hexo: async (projectName, subdirectory) => {
157
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
158
- await exec(cloneCommands, 'Hexo', false, false);
159
- },
160
- Jekyll: async (projectName, subdirectory) => {
161
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
162
- await exec(cloneCommands, 'Jekyll', false, false);
163
- },
164
- Next: async (projectName, subdirectory) => {
165
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
166
- await exec(cloneCommands, 'Next', false, false);
167
- },
168
- React: async (projectName, subdirectory) => {
169
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
170
- await exec(cloneCommands, 'React', false, false);
171
- },
172
- Svelte: async (projectName, subdirectory) => {
173
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
174
- await exec(cloneCommands, 'Svelte', false, false);
175
- },
176
- Vue: async (projectName, subdirectory) => {
177
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
178
- await exec(cloneCommands, 'Vue', false, false);
179
- },
180
- Vite: async (projectName, subdirectory) => {
181
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
182
- await exec(cloneCommands, 'Vite', false, false);
183
- },
184
- Eleventy: async (projectName, subdirectory) => {
185
- const cloneCommands = generateCloneCommand(projectName, subdirectory);
186
- await exec(cloneCommands, 'Eleventy', false, false);
187
- },
188
- };
189
-
190
- export { TemplatesInitializer, TemplatesOptions };
@@ -1,17 +0,0 @@
1
- /**
2
- Init command messages object.
3
- @property {object} success - Success messages.
4
- @property {object} info - Information messages.
5
- @property {object} errors - Error messages.
6
- */
7
- const init = {
8
- success: {
9
- ready: 'All ready. The template has been initialized.',
10
- },
11
- info: {
12
- preparing: 'Preparing everything. Wait a moment...',
13
- },
14
- errors: {},
15
- };
16
-
17
- export default init;