@microlight/core 0.3.0 → 1.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.
@@ -24,9 +24,6 @@ export default function RootLayout({
24
24
  children
25
25
  }) {
26
26
  return <html lang="en">
27
- <head>
28
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" />
29
- </head>
30
27
  <body className={inter.className} style={{
31
28
  margin: 0,
32
29
  padding: 0
@@ -1,8 +1,6 @@
1
- 'use client';
2
-
3
1
  import { Table, Box, Container, Typography } from '@mui/joy';
4
- import React from 'react';
5
- import Icon from "../../../components/Icon";
2
+ import SendIcon from '@mui/icons-material/Send';
3
+ import FolderIcon from '@mui/icons-material/FolderOutlined';
6
4
 
7
5
  // import Link from '@/components/Link';
8
6
 
@@ -68,8 +66,8 @@ export default function ViewFolder({
68
66
  </thead>
69
67
  <tbody>
70
68
  {contents.map(content => {
71
- return <React.Fragment key={`${content.type}__${content.slug}`}>
72
- <tr>
69
+ return <>
70
+ <tr key={`${content.type}__${content.slug}`}>
73
71
  <td>
74
72
  {content.type == 'folder' && <>
75
73
  <Box sx={{
@@ -77,9 +75,8 @@ export default function ViewFolder({
77
75
  alignItems: 'center',
78
76
  gap: 1
79
77
  }}>
80
- {/* <Icon icon='folder' color='#444444'/> */}
81
- <i class="fa-regular fa-folder fa-xl"></i>
82
- <Link href={'/library' + '/' + content.slug}>{content.name}</Link>
78
+ <FolderIcon />
79
+ <Link href={'/library' + dir + '/' + content.slug}>{content.name}</Link>
83
80
  </Box>
84
81
  </>}
85
82
  {content.type == 'task' && <>
@@ -88,10 +85,9 @@ export default function ViewFolder({
88
85
  alignItems: 'center',
89
86
  gap: 1
90
87
  }}>
91
- {/* <Icon icon='send' color='#6435c9'/> */}
92
- <i class="fa-solid fa-paper-plane fa-xl" style={{
88
+ <SendIcon sx={{
93
89
  color: '#6435c9'
94
- }}></i>
90
+ }} />
95
91
  <Link href={'/tasks/' + content.slug}>{content.name}</Link>
96
92
  </Box>
97
93
  </>}
@@ -99,7 +95,7 @@ export default function ViewFolder({
99
95
  <td>{content.description}</td>
100
96
  <td></td>
101
97
  </tr>
102
- </React.Fragment>;
98
+ </>;
103
99
  })}
104
100
 
105
101
 
@@ -7,11 +7,11 @@ async function getFolderDetails({
7
7
  params
8
8
  }) {
9
9
  const dir = params?.f_path?.join('/') || '';
10
- // console.log('\n\n\n\n======');
11
- // console.log("dir - ",dir);
10
+ console.log('\n\n\n\n======');
11
+ console.log("dir - ", dir);
12
12
  let folderConfig = {};
13
13
  folderConfig = folderMap[dir];
14
- // console.log(folderConfig);
14
+ console.log(folderConfig);
15
15
  // console.log('\n\n\n\n\n===========');
16
16
  // console.log(dir)
17
17
  // console.log(folderMap)
@@ -3,6 +3,7 @@
3
3
  import OpenInNew from '@mui/icons-material/OpenInNew';
4
4
  import { Container, Typography, Box, Card, ButtonGroup, Button, Table, Chip, Link as MuiLink } from '@mui/joy';
5
5
  import PageHeader from "../../../components/PageHeader";
6
+ import SendIcon from '@mui/icons-material/Send';
6
7
  import MLInput from "../../../components/MLInput";
7
8
  import { useState } from 'react';
8
9
  import { executeTask } from "./action";
@@ -49,7 +50,7 @@ export default function ViewTask({
49
50
  return <>
50
51
  {task?.links?.map(link => {
51
52
  return <>
52
- <MuiLink underline="none" variant="outlined" color="neutral" target='_blank' href={link.href} startDecorator={<i class="fa-solid fa-up-right-from-square"></i>} sx={{
53
+ <MuiLink underline="none" variant="outlined" color="neutral" target='_blank' href={link.href} startDecorator={<OpenInNew fontSize="10px" />} sx={{
53
54
  mx: 0.5,
54
55
  px: 1,
55
56
  py: 0.5,
@@ -79,7 +80,9 @@ export default function ViewTask({
79
80
  <PageHeader breadcrumbs={breadcrumbs} header={{
80
81
  part1: 'Task:',
81
82
  part2: task.name
82
- }} RightButtons={RightButtons} />
83
+ }} RightButtons={RightButtons} icon={<SendIcon sx={{
84
+ color: '#6435c9'
85
+ }} />} />
83
86
  <Typography level="body-sm">{task.description}</Typography>
84
87
 
85
88
 
@@ -29,7 +29,7 @@ export async function executeTask({
29
29
  };
30
30
  try {
31
31
  const results = await async.auto(workflow);
32
- // console.log(results);
32
+ console.log(results);
33
33
  revalidatePath(`/tasks/${task.slug}`);
34
34
  return {
35
35
  success: true,
@@ -51,20 +51,23 @@ export default function ViewRun({
51
51
  <DropdownActions run={run} />
52
52
  </>;
53
53
  };
54
- useEffect(() => {
55
- let intervalId;
56
- if (run.status === 'running' || run.status === 'pending') {
57
- intervalId = setInterval(() => {
58
- // Refresh the page data using router.refresh()
59
- router.refresh();
60
- }, 500);
61
- }
62
- return () => {
63
- if (intervalId) {
64
- clearInterval(intervalId);
65
- }
66
- };
67
- }, [run]);
54
+ // useEffect(() => {
55
+
56
+ // let intervalId;
57
+ // if (run.status === 'running' || run.status === 'pending') {
58
+ // intervalId = setInterval(() => {
59
+ // // Refresh the page data using router.refresh()
60
+ // router.refresh();
61
+ // }, 500);
62
+ // }
63
+
64
+ // return () => {
65
+ // if (intervalId) {
66
+ // clearInterval(intervalId);
67
+ // }
68
+ // };
69
+ // }, [run]);
70
+
68
71
  return <>
69
72
  <Container>
70
73
  <PageHeader breadcrumbs={breadcrumbs} header={{
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { Menu, MenuItem, MenuButton, Dropdown } from '@mui/joy';
4
+ import MoreVertIcon from '@mui/icons-material/MoreVert';
4
5
  import * as React from 'react';
5
6
  import Button from '@mui/joy/Button';
6
7
  // import Divider from '@mui/joy/Divider';
@@ -35,7 +36,7 @@ export default function DropdownActions({
35
36
  }} onClick={event => {
36
37
  event.preventDefault();
37
38
  event.stopPropagation();
38
- }}><i class="fa-solid fa-ellipsis-vertical fa-lg"></i></MenuButton>
39
+ }}><MoreVertIcon size='sm' /></MenuButton>
39
40
  <Menu placement='bottom-end'>
40
41
  <MenuItem disabled onClick={onClickCreateVersion}>Rerun job</MenuItem>
41
42
  <MenuItem onClick={onClickCopyRerunAsCurl}>Copy rerun as curl</MenuItem>
@@ -2,7 +2,6 @@ import getTaskDetails from "../../../../../lib/getTaskDetails";
2
2
  import ViewRun from "./ViewRun";
3
3
  import async from 'async';
4
4
  import microlightDB from "../../../../../database/microlight";
5
- import { notFound } from "next/navigation";
6
5
  export default async function Page({
7
6
  params,
8
7
  searchParams
@@ -24,7 +23,6 @@ export default async function Page({
24
23
  id: params.r_id
25
24
  }
26
25
  });
27
- if (!run) return notFound();
28
26
  return run.toJSON();
29
27
  },
30
28
  getLogs: async function () {
@@ -1,16 +1,14 @@
1
1
  export const register = async () => {
2
2
  if (process.env.NEXT_RUNTIME === 'nodejs') {
3
- // Dynamically import loadSchedules only when we're in Node.js runtime
4
- const {
5
- default: loadSchedules
6
- } = await import("./lib/loadSchedules");
7
- await loadSchedules();
8
- // const interval = setInterval(async () => {
9
- // await executeRuns();
10
- // console.log('Instrumentation check running...');
11
- // }, 5000);
3
+ // // Dynamically import loadSchedules only when we're in Node.js runtime
4
+ // const { default: loadSchedules } = await import('./lib/loadSchedules');
5
+ // await loadSchedules();
6
+ // // const interval = setInterval(async () => {
7
+ // // await executeRuns();
8
+ // // console.log('Instrumentation check running...');
9
+ // // }, 5000);
12
10
 
13
- // Clean up interval on process exit
11
+ // // Clean up interval on process exit
14
12
  process.on('SIGTERM', () => {
15
13
  clearInterval(interval);
16
14
  });
@@ -1,8 +1,9 @@
1
1
  import cron from "node-cron";
2
- import taskMap from "../../taskMap";
2
+ import getAllTasks from "./getAllTasks";
3
3
  import async from 'async';
4
4
  import executeRun from "./executeRun";
5
5
  import microlightDB from "../database/microlight";
6
+ import tasks from "../tasks";
6
7
  async function executeTask({
7
8
  inputs,
8
9
  task
@@ -39,9 +40,9 @@ async function executeTask({
39
40
  }
40
41
  }
41
42
  export default async function loadSchedules() {
43
+ // const tasks = await getAllTasks();
42
44
  let schedules = [];
43
- Object.keys(taskMap).forEach(function (task_slug) {
44
- const task = taskMap[task_slug];
45
+ tasks.forEach(function (task) {
45
46
  // Check if task has schedules
46
47
  if (task.is_enabled && task.schedules && Array.isArray(task.schedules)) {
47
48
  task.schedules.forEach(scheduleConfig => {
@@ -49,7 +50,7 @@ export default async function loadSchedules() {
49
50
  // Create cron job
50
51
  const job = cron.schedule(scheduleConfig.schedule, async () => {
51
52
  try {
52
- // console.log('trigger the task')
53
+ console.log('trigger the task');
53
54
  // Execute task with schedule-specific inputs
54
55
  await executeTask({
55
56
  inputs: scheduleConfig.inputs || {},
@@ -70,7 +71,7 @@ export default async function loadSchedules() {
70
71
  });
71
72
  }
72
73
  });
73
- // console.log('Count of schedules :'+schedules.length);
74
- // console.log(schedules);
74
+ console.log('Count of schedules :' + schedules.length);
75
+ console.log(schedules);
75
76
  return schedules;
76
77
  }
@@ -0,0 +1,33 @@
1
+ import { glob } from 'glob';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+ console.log(__filename);
7
+ console.log(__dirname);
8
+
9
+ // Find all task files and folder files
10
+ const taskFiles = glob.sync(['**/*.task.js', '**/microlight.folder.js'], {
11
+ cwd: __dirname,
12
+ absolute: true
13
+ });
14
+ console.log(taskFiles);
15
+
16
+ // Import all task files dynamically
17
+ const tasks = await Promise.all(taskFiles.map(async filePath => {
18
+ const task = await import(filePath);
19
+ const taskName = path.basename(filePath, '.task.js');
20
+ // return [taskName, task.default];
21
+ return [task?.default?.slug, {
22
+ ...task?.default,
23
+ ...{
24
+ file_name: taskName
25
+ }
26
+ }];
27
+ }));
28
+ console.log(tasks);
29
+
30
+ // Convert array of entries to an object
31
+ const taskMap = Object.fromEntries(tasks);
32
+ console.log(taskMap);
33
+ export default taskMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microlight/core",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,12 +9,13 @@
9
9
  "index": "node ./init/bootstrap/index_tasks_and_folders.js",
10
10
  "build:server": "babel --config-file=./babel-configs/dist.babel.config.js src --out-dir=dist/server",
11
11
  "build:scripts": "babel --config-file=./babel-configs/dist.babel.config.js scripts --out-dir=dist/scripts",
12
- "build": "rm -rf dist && npm run build:server && npm run build:scripts",
12
+ "build": "rm -rf dist && npm run build:server",
13
13
  "build:next": "next build",
14
14
  "prepare:tasks": "microlight-core prepare tasks",
15
15
  "prepare:folders": "microlight-core prepare folders",
16
16
  "prepare:server": "microlight-core prepare server",
17
17
  "prepare": "microlight-core prepare all",
18
+ "publish": "npm publish --access public",
18
19
  "start": "next start",
19
20
  "lint": "next lint"
20
21
  },
@@ -26,6 +27,9 @@
26
27
  "microlight-core": "./bin/microlight-core.js"
27
28
  },
28
29
  "dependencies": {
30
+ "@emotion/react": "^11.14.0",
31
+ "@emotion/styled": "^11.14.0",
32
+ "@mui/icons-material": "^5.15.15",
29
33
  "@mui/joy": "^5.0.0-beta.51",
30
34
  "async": "^3.2.6",
31
35
  "commander": "^13.1.0",
@@ -42,5 +46,8 @@
42
46
  "sequelize": "^6.37.5",
43
47
  "sqlite3": "^5.1.7",
44
48
  "switchless": "0.19.1"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
45
52
  }
46
53
  }
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
2
- import { glob } from 'glob';
3
- import path from 'path';
4
- import fs from 'fs';
5
- // import taskMap from '@/tasks/tasks';
6
-
7
- // Ensure we're looking in the right directory relative to the script
8
- const tasksDir = path.join(process.cwd(), 'src', 'tasks');
9
- const outputFile = path.resolve(process.cwd(), '.microlight', 'folderMap.js');
10
- const taskMapFile = path.resolve(process.cwd(), '.microlight', 'taskMap.js');
11
- const taskMap = (await import(taskMapFile))?.default;
12
- let taskMapByFileName = {};
13
- Object.keys(taskMap).forEach(function (slug) {
14
- const task = taskMap[slug];
15
- taskMapByFileName[task.__folder + '/' + task.__file_name] = task;
16
- });
17
-
18
- // console.log(taskMapByFileName);
19
-
20
- // Create tasks directory if it doesn't exist
21
- if (!fs.existsSync(tasksDir)) {
22
- fs.mkdirSync(tasksDir, {
23
- recursive: true
24
- });
25
- }
26
-
27
- // Find all folder files
28
- const folderPatterns = ['__ml.js', 'ml.js', 'ml.folder.js', '**/microlight.folder.js'];
29
- const folderFiles = glob.sync(folderPatterns, {
30
- cwd: tasksDir,
31
- absolute: false
32
- });
33
-
34
- // console.log(folderFiles);
35
-
36
- // Import all task files dynamically
37
- const folders = await Promise.all(folderFiles.map(async file => {
38
- const filePath = path.resolve(tasksDir, file);
39
- let folderName = file.split('/');
40
- folderName.pop();
41
- folderName = folderName.join('/');
42
- console.log(folderName);
43
- let folder = (await import(filePath))?.default;
44
- // console.log(folder.default);
45
- // const taskName = path.basename(filePath, '.task.js');
46
- return [folderName, folder];
47
- // return [task?.default?.slug, {...task?.default,...{file_name:taskName}}];
48
- }));
49
- // console.log(folders);
50
-
51
- // Convert array of entries to an object
52
- const folderMap = Object.fromEntries(folders);
53
- // console.log(folderMap);
54
-
55
- Object.keys(folderMap).map(folderName => {
56
- folderMap[folderName].contents = [];
57
- const contentList = fs.readdirSync(path.resolve(tasksDir, folderName));
58
- // console.log(contentList);
59
- for (const filename of contentList) {
60
- const file = path.resolve(tasksDir, folderName, filename);
61
- // const file = project_folder+`${dir}/${filename}`
62
- // console.log(file);
63
- if (fs.statSync(file).isDirectory()) {
64
- // console.log('\n\n\n====');
65
- // console.log(file);
66
- const subFolderName = file.split('/src/tasks/')[1];
67
- // console.log(subFolderName);
68
- if (folderMap[subFolderName]) {
69
- folderMap[folderName].contents.push({
70
- type: 'folder',
71
- slug: subFolderName,
72
- ...folderMap[subFolderName]
73
- });
74
- }
75
- } else {
76
- if (filename.indexOf('.task.js') > -1) {
77
- // console.log('\n\n\n====');
78
- // console.log(filename);
79
- const taskName = path.basename(filename, '.task.js');
80
- // console.log(taskMapByFileName[folderName+'/'+filename]);
81
- let item = {
82
- type: 'task',
83
- slug: taskName,
84
- ...taskMapByFileName[folderName + '/' + filename]
85
- };
86
- folderMap[folderName].contents.push(item);
87
- }
88
- }
89
- // console.log(filename);
90
- }
91
- });
92
- // folderMap.map(folder=>{
93
-
94
- //
95
- // folder.content = [
96
- // {
97
- // type:'task',
98
- // slug:'takes_time'
99
- // },
100
- // {
101
- // type:'folder',
102
- // slug:'1.intro'
103
- // }
104
- // ]
105
- // })
106
-
107
- // Write the generated code to a file
108
- const outputCode = 'export default ' + JSON.stringify(folderMap, null, 2);
109
-
110
- // Create the output directory if it doesn't exist
111
- const outputDir = path.dirname(outputFile);
112
- if (!fs.existsSync(outputDir)) {
113
- fs.mkdirSync(outputDir, {
114
- recursive: true
115
- });
116
- }
117
-
118
- // Write the file
119
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
120
- console.log(`Generated folder index at: ${outputFile}`);
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env node
2
- import { glob } from 'glob';
3
- import path from 'path';
4
- // import { join, relative, dirname } from 'path';
5
- import fs from 'fs';
6
-
7
- // Ensure we're looking in the right directory relative to the script
8
- const tasksDir = path.join(process.cwd(), 'src', 'tasks');
9
- const outputFile = path.resolve(process.cwd(), '.microlight', 'importTaskModule.js');
10
-
11
- // Create tasks directory if it doesn't exist
12
- if (!fs.existsSync(tasksDir)) {
13
- fs.mkdirSync(tasksDir, {
14
- recursive: true
15
- });
16
- }
17
-
18
- // Find all task files
19
- const taskFiles = glob.sync('**/*.task.js', {
20
- cwd: tasksDir,
21
- absolute: false
22
- });
23
-
24
- // Generate the import switch statement
25
- const generateImportSwitch = async tasks => {
26
- let cases = await Promise.all(tasks.map(async file => {
27
- const filePath = path.resolve(tasksDir, file);
28
- const task = await import(filePath);
29
- // console.log(task);
30
- const taskName = path.basename(file, '.task.js');
31
- const taskSlug = task?.default?.slug;
32
- // const taskName = path.basename(filePath, '.task.js');
33
- // return [taskName, task.default];
34
- // return [task?.default?.slug, {...task?.default,...{file_name:taskName}}];
35
-
36
- return ` case "${taskSlug || taskName}":\n return await import("../src/tasks/${file}");`;
37
- }));
38
- cases = cases.join('\n');
39
- // console.log(cases);
40
-
41
- return `
42
- export const importTaskModule = async (task_slug) => {
43
- switch (task_slug) {
44
- ${cases}
45
- default:
46
- return { default: { name: "Library", description: "All executable tasks" } };
47
- }
48
- };`.trim();
49
- };
50
-
51
- // Write the generated code to a file
52
- const outputCode = await generateImportSwitch(taskFiles);
53
-
54
- // Create the output directory if it doesn't exist
55
- const outputDir = path.dirname(outputFile);
56
- if (!fs.existsSync(outputDir)) {
57
- fs.mkdirSync(outputDir, {
58
- recursive: true
59
- });
60
- }
61
-
62
- // Write the file
63
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
64
- console.log(`Generated import switch at: ${outputFile}`);
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env node
2
- import { glob } from 'glob';
3
- import path from 'path';
4
- // import { join, relative, dirname } from 'path';
5
- import fs from 'fs';
6
-
7
- // Ensure we're looking in the right directory relative to the script
8
- const tasksDir = path.join(process.cwd(), 'src', 'tasks');
9
- const outputFile = path.resolve(process.cwd(), '.microlight', 'taskMap.js');
10
-
11
- // Create tasks directory if it doesn't exist
12
- if (!fs.existsSync(tasksDir)) {
13
- fs.mkdirSync(tasksDir, {
14
- recursive: true
15
- });
16
- }
17
-
18
- // Find all task files
19
- const taskFiles = glob.sync('**/*.task.js', {
20
- cwd: tasksDir,
21
- absolute: false
22
- });
23
- console.log(taskFiles);
24
-
25
- // Import all task files dynamically
26
- const tasks = await Promise.all(taskFiles.map(async file => {
27
- const filePath = path.resolve(tasksDir, file);
28
- const task = await import(filePath);
29
- const taskName = path.basename(filePath);
30
- let folderName = file.split('/');
31
- folderName.pop();
32
- folderName = folderName.join('/');
33
- // return [taskName, task.default];
34
- return [task?.default?.slug, {
35
- ...task?.default,
36
- ...{
37
- __file_name: taskName,
38
- __folder: folderName
39
- }
40
- }];
41
- }));
42
- // console.log(tasks);
43
-
44
- // Convert array of entries to an object
45
- const taskMap = Object.fromEntries(tasks);
46
- console.log(taskMap);
47
-
48
- // Write the generated code to a file
49
- const outputCode = 'export default ' + JSON.stringify(taskMap, null, 2);
50
-
51
- // Create the output directory if it doesn't exist
52
- const outputDir = path.dirname(outputFile);
53
- if (!fs.existsSync(outputDir)) {
54
- fs.mkdirSync(outputDir, {
55
- recursive: true
56
- });
57
- }
58
-
59
- // Write the file
60
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
61
- console.log(`Generated tasks index at: ${outputFile}`);
@@ -1,119 +0,0 @@
1
- import { glob } from 'glob';
2
- import path from 'path';
3
- // import { join, relative, dirname } from 'path';
4
- import fs from 'fs';
5
- const tasksDir = path.join(process.cwd(), 'src', 'tasks');
6
- const outputFile = path.resolve(process.cwd(), '.microlight', 'folderMap.js');
7
- const taskMapFile = path.resolve(process.cwd(), '.microlight', 'taskMap.js');
8
- const taskMap = (await import(taskMapFile))?.default;
9
- let taskMapByFileName = {};
10
- Object.keys(taskMap).forEach(function (slug) {
11
- const task = taskMap[slug];
12
- taskMapByFileName[task.__folder + '/' + task.__file_name] = task;
13
- });
14
-
15
- // Create tasks directory if it doesn't exist
16
- if (!fs.existsSync(tasksDir)) {
17
- fs.mkdirSync(tasksDir, {
18
- recursive: true
19
- });
20
- }
21
- const getFolderFiles = function () {
22
- // Find all folder files
23
- const folderPatterns = ['__ml.js', 'ml.js', 'ml.folder.js', '**/microlight.folder.js'];
24
- const folderFiles = glob.sync(folderPatterns, {
25
- cwd: tasksDir,
26
- absolute: false
27
- });
28
- return folderFiles;
29
- };
30
- export async function prepareFolders() {
31
- console.log('Preparing folders now');
32
- const folderFiles = getFolderFiles();
33
-
34
- // Import all task files dynamically
35
- const folders = await Promise.all(folderFiles.map(async file => {
36
- const filePath = path.resolve(tasksDir, file);
37
- let folderName = file.split('/');
38
- folderName.pop();
39
- folderName = folderName.join('/');
40
- // console.log(folderName);
41
- let folder = (await import(filePath))?.default;
42
- // console.log(folder.default);
43
- // const taskName = path.basename(filePath, '.task.js');
44
- return [folderName, folder];
45
- // return [task?.default?.slug, {...task?.default,...{file_name:taskName}}];
46
- }));
47
- // console.log(folders);
48
-
49
- // Convert array of entries to an object
50
- const folderMap = Object.fromEntries(folders);
51
- // console.log(folderMap);
52
-
53
- Object.keys(folderMap).map(folderName => {
54
- folderMap[folderName].contents = [];
55
- const contentList = fs.readdirSync(path.resolve(tasksDir, folderName));
56
- // console.log(contentList);
57
- for (const filename of contentList) {
58
- const file = path.resolve(tasksDir, folderName, filename);
59
- // const file = project_folder+`${dir}/${filename}`
60
- // console.log(file);
61
- if (fs.statSync(file).isDirectory()) {
62
- // console.log('\n\n\n====');
63
- // console.log(file);
64
- const subFolderName = file.split('/src/tasks/')[1];
65
- // console.log(subFolderName);
66
- if (folderMap[subFolderName]) {
67
- folderMap[folderName].contents.push({
68
- type: 'folder',
69
- slug: subFolderName,
70
- ...folderMap[subFolderName]
71
- });
72
- }
73
- } else {
74
- if (filename.indexOf('.task.js') > -1) {
75
- // console.log('\n\n\n====');
76
- // console.log(filename);
77
- const taskName = path.basename(filename, '.task.js');
78
- // console.log(taskMapByFileName[folderName+'/'+filename]);
79
- let item = {
80
- type: 'task',
81
- slug: taskName,
82
- ...taskMapByFileName[folderName + '/' + filename]
83
- };
84
- folderMap[folderName].contents.push(item);
85
- }
86
- }
87
- // console.log(filename);
88
- }
89
- });
90
- // folderMap.map(folder=>{
91
-
92
- //
93
- // folder.content = [
94
- // {
95
- // type:'task',
96
- // slug:'takes_time'
97
- // },
98
- // {
99
- // type:'folder',
100
- // slug:'1.intro'
101
- // }
102
- // ]
103
- // })
104
-
105
- // Write the generated code to a file
106
- const outputCode = 'export default ' + JSON.stringify(folderMap, null, 2);
107
-
108
- // Create the output directory if it doesn't exist
109
- const outputDir = path.dirname(outputFile);
110
- if (!fs.existsSync(outputDir)) {
111
- fs.mkdirSync(outputDir, {
112
- recursive: true
113
- });
114
- }
115
-
116
- // Write the file
117
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
118
- console.log(`Generated folder index at: ${outputFile}`);
119
- }
@@ -1,34 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import { copySync } from "fs-extra";
4
- import { createRequire } from "module";
5
- const require = createRequire(import.meta.url); // Required for resolving CommonJS modules
6
-
7
- export async function prepareServer() {
8
- console.log('preparing the server');
9
- const coreModulePath = require.resolve("@microlight/core/package.json"); // Find package.json
10
- const coreRoot = path.dirname(coreModulePath); // Get package root
11
- console.log(coreModulePath);
12
- console.log(coreRoot);
13
- const serverSrcDir = path.join(coreRoot, "dist", "server"); // Resolve /dist/server
14
- console.log(serverSrcDir);
15
-
16
- // Destination path
17
- const processDir = process.cwd();
18
- const serverDestDir = path.join(processDir, ".microlight", "server");
19
- console.log("serverSrcDir:", serverSrcDir);
20
- console.log("serverDestDir:", serverDestDir);
21
-
22
- // Ensure destination exists
23
- if (!fs.existsSync(serverDestDir)) {
24
- fs.mkdirSync(serverDestDir, {
25
- recursive: true
26
- });
27
- }
28
-
29
- // Copy files
30
- copySync(serverSrcDir, serverDestDir, {
31
- overwrite: true
32
- });
33
- console.log("Server files copied successfully!");
34
- }
@@ -1,114 +0,0 @@
1
- import { glob } from 'glob';
2
- import path from 'path';
3
- // import { join, relative, dirname } from 'path';
4
- import fs from 'fs';
5
- const tasksDir = path.join(process.cwd(), 'src', 'tasks');
6
-
7
- // Create tasks directory if it doesn't exist
8
- if (!fs.existsSync(tasksDir)) {
9
- fs.mkdirSync(tasksDir, {
10
- recursive: true
11
- });
12
- }
13
- const getTaskFiles = function () {
14
- // Find all task files
15
- const taskFiles = glob.sync('**/*.task.js', {
16
- cwd: tasksDir,
17
- absolute: false
18
- });
19
-
20
- // console.log(taskFiles);
21
- return taskFiles;
22
- };
23
-
24
- // Generate the import switch statement
25
- const generateImportSwitch = async tasks => {
26
- let cases = await Promise.all(tasks.map(async file => {
27
- const filePath = path.resolve(tasksDir, file);
28
- const task = await import(filePath);
29
- // console.log(task);
30
- const taskName = path.basename(file, '.task.js');
31
- const taskSlug = task?.default?.slug;
32
- // const taskName = path.basename(filePath, '.task.js');
33
- // return [taskName, task.default];
34
- // return [task?.default?.slug, {...task?.default,...{file_name:taskName}}];
35
-
36
- return ` case "${taskSlug || taskName}":\n return await import("../src/tasks/${file}");`;
37
- }));
38
- cases = cases.join('\n');
39
- // console.log(cases);
40
-
41
- return `
42
- export const importTaskModule = async (task_slug) => {
43
- switch (task_slug) {
44
- ${cases}
45
- default:
46
- return { default: { name: "Library", description: "All executable tasks" } };
47
- }
48
- };`.trim();
49
- };
50
- export async function prepareTasks() {
51
- console.log('Preparing tasks now');
52
- await prepareTasksIndex();
53
- await prepareTasksImports();
54
- }
55
- export async function prepareTasksIndex() {
56
- const taskFiles = getTaskFiles();
57
-
58
- // Import all task files dynamically
59
- const tasks = await Promise.all(taskFiles.map(async file => {
60
- const filePath = path.resolve(tasksDir, file);
61
- const task = await import(filePath);
62
- const taskName = path.basename(filePath);
63
- let folderName = file.split('/');
64
- folderName.pop();
65
- folderName = folderName.join('/');
66
- // return [taskName, task.default];
67
- return [task?.default?.slug, {
68
- ...task?.default,
69
- ...{
70
- __file_name: taskName,
71
- __folder: folderName
72
- }
73
- }];
74
- }));
75
- // console.log(tasks);
76
-
77
- // Convert array of entries to an object
78
- const taskMap = Object.fromEntries(tasks);
79
-
80
- // console.log(taskMap);
81
-
82
- // Write the generated code to a file
83
- const outputCode = 'export default ' + JSON.stringify(taskMap, null, 2);
84
- const outputFile = path.resolve(process.cwd(), '.microlight', 'taskMap.js');
85
- // Create the output directory if it doesn't exist
86
- const outputDir = path.dirname(outputFile);
87
- if (!fs.existsSync(outputDir)) {
88
- fs.mkdirSync(outputDir, {
89
- recursive: true
90
- });
91
- }
92
-
93
- // Write the file
94
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
95
- console.log(`Generated tasks index at: ${outputFile}`);
96
- }
97
- export async function prepareTasksImports() {
98
- const taskFiles = getTaskFiles();
99
-
100
- // Write the generated code to a file
101
- const outputCode = await generateImportSwitch(taskFiles);
102
- const outputFile = path.resolve(process.cwd(), '.microlight', 'importTaskModule.js');
103
- // Create the output directory if it doesn't exist
104
- const outputDir = path.dirname(outputFile);
105
- if (!fs.existsSync(outputDir)) {
106
- fs.mkdirSync(outputDir, {
107
- recursive: true
108
- });
109
- }
110
-
111
- // Write the file
112
- fs.writeFileSync(outputFile, outputCode, 'utf-8');
113
- console.log(`Generated importTaskModule at: ${outputFile}`);
114
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * there is an issue with mui icons.
3
- * manually setting the icons.
4
- * the svgs of icons are picked up from fontawesome
5
- * https://fontawesome.com/search?ic=free
6
- */
7
- import React from 'react';
8
- import { AspectRatio } from '@mui/joy';
9
- export default function Icon({
10
- color,
11
- icon
12
- }) {
13
- return <>
14
- <AspectRatio ratio="1" sx={{
15
- width: 20
16
- }} variant="plain">
17
- {icon == 'send' && <svg fill={color} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480l0-83.6c0-4 1.5-7.8 4.2-10.8L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z" /></svg>}
18
- {icon == 'folder' && <svg fill={color} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M0 96C0 60.7 28.7 32 64 32l132.1 0c19.1 0 37.4 7.6 50.9 21.1L289.9 96 448 96c35.3 0 64 28.7 64 64l0 256c0 35.3-28.7 64-64 64L64 480c-35.3 0-64-28.7-64-64L0 96zM64 80c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l384 0c8.8 0 16-7.2 16-16l0-256c0-8.8-7.2-16-16-16l-161.4 0c-10.6 0-20.8-4.2-28.3-11.7L213.1 87c-4.5-4.5-10.6-7-17-7L64 80z" /></svg>}
19
- {icon == 'ellipsis-vertical' && <svg fill={color} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 512"><path d="M64 360a56 56 0 1 0 0 112 56 56 0 1 0 0-112zm0-160a56 56 0 1 0 0 112 56 56 0 1 0 0-112zM120 96A56 56 0 1 0 8 96a56 56 0 1 0 112 0z" /></svg>}
20
- </AspectRatio>
21
- </>;
22
- }