motia 0.8.2-beta.140-111855 → 0.8.2-beta.140-559269
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/dist/cjs/generate-plugins.js +23 -17
- package/dist/esm/generate-plugins.js +23 -17
- package/package.json +4 -4
|
@@ -42,17 +42,17 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
42
42
|
const node_path_1 = __importDefault(require("node:path"));
|
|
43
43
|
const core_1 = require("@motiadev/core");
|
|
44
44
|
const glob_1 = require("glob");
|
|
45
|
-
const collectPluginSteps = async (dirname, stepPatterns, projectRoot) => {
|
|
45
|
+
const collectPluginSteps = async (dirname, stepPatterns, projectRoot, printer) => {
|
|
46
46
|
const pluginSteps = [];
|
|
47
47
|
if (!node_fs_1.default.existsSync(dirname)) {
|
|
48
|
-
|
|
48
|
+
printer.printPluginWarn(`Directory not found: ${dirname}`);
|
|
49
49
|
return pluginSteps;
|
|
50
50
|
}
|
|
51
51
|
for (const pattern of stepPatterns) {
|
|
52
52
|
try {
|
|
53
53
|
const stepFiles = (0, glob_1.globSync)(pattern, { absolute: true, cwd: dirname });
|
|
54
54
|
if (stepFiles.length === 0) {
|
|
55
|
-
|
|
55
|
+
printer.printPluginLog(`No files found matching pattern: ${pattern} in ${dirname}`);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
for (const filePath of stepFiles) {
|
|
@@ -62,35 +62,36 @@ const collectPluginSteps = async (dirname, stepPatterns, projectRoot) => {
|
|
|
62
62
|
pluginSteps.push({ filePath, config });
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
|
|
65
|
+
printer.printPluginWarn(`No config found in step ${filePath}, step skipped`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
69
|
-
|
|
69
|
+
printer.printPluginError(`Error loading step ${filePath}:`, error);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
catch (error) {
|
|
74
|
-
|
|
74
|
+
printer.printPluginError(`Error processing pattern ${pattern}:`, error);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
return pluginSteps;
|
|
78
78
|
};
|
|
79
|
-
const loadConfig = async (baseDir) => {
|
|
79
|
+
const loadConfig = async (baseDir, printer) => {
|
|
80
80
|
const configFiles = (0, glob_1.globSync)('motia.config.{ts,js}', { absolute: true, cwd: baseDir });
|
|
81
81
|
if (configFiles.length === 0) {
|
|
82
82
|
const templatePath = node_path_1.default.join(__dirname, 'create/templates/nodejs/motia.config.ts.txt');
|
|
83
83
|
const templateContent = node_fs_1.default.readFileSync(templatePath, 'utf-8');
|
|
84
84
|
const configPath = node_path_1.default.join(baseDir, 'motia.config.ts');
|
|
85
85
|
node_fs_1.default.writeFileSync(configPath, templateContent);
|
|
86
|
-
|
|
86
|
+
printer.printPluginLog('Created motia.config.ts');
|
|
87
87
|
return (await Promise.resolve(`${configPath}`).then(s => __importStar(require(s)))).default;
|
|
88
88
|
}
|
|
89
89
|
return (await Promise.resolve(`${configFiles[0]}`).then(s => __importStar(require(s)))).default;
|
|
90
90
|
};
|
|
91
91
|
const createPluginContext = (motiaServer) => {
|
|
92
|
-
const { motia, addRoute, removeRoute } = motiaServer;
|
|
92
|
+
const { motia, addRoute, removeRoute, printer } = motiaServer;
|
|
93
93
|
return {
|
|
94
|
+
printer,
|
|
94
95
|
tracerFactory: motia.tracerFactory,
|
|
95
96
|
state: motia.stateAdapter,
|
|
96
97
|
lockedData: motia.lockedData,
|
|
@@ -117,12 +118,12 @@ const createPluginContext = (motiaServer) => {
|
|
|
117
118
|
};
|
|
118
119
|
};
|
|
119
120
|
const processSteps = async (motiaServer, plugins, baseDir) => {
|
|
120
|
-
const { motia, addRoute } = motiaServer;
|
|
121
|
+
const { motia, addRoute, printer } = motiaServer;
|
|
121
122
|
for (const plugin of plugins) {
|
|
122
123
|
if (plugin.dirname && plugin.steps) {
|
|
123
|
-
|
|
124
|
+
printer.printPluginLog(`Loading steps from ${plugin.dirname}`);
|
|
124
125
|
try {
|
|
125
|
-
const pluginSteps = await collectPluginSteps(plugin.dirname, plugin.steps, baseDir);
|
|
126
|
+
const pluginSteps = await collectPluginSteps(plugin.dirname, plugin.steps, baseDir, printer);
|
|
126
127
|
const version = `plugin_${(0, node_crypto_1.randomUUID)()}:${Math.floor(Date.now() / 1000)}`;
|
|
127
128
|
for (const { filePath, config } of pluginSteps) {
|
|
128
129
|
try {
|
|
@@ -134,24 +135,29 @@ const processSteps = async (motiaServer, plugins, baseDir) => {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
else {
|
|
137
|
-
|
|
138
|
+
printer.printPluginWarn(`Failed to register step: ${config.name} from ${filePath}`);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
catch (error) {
|
|
141
|
-
|
|
142
|
+
printer.printPluginError(`Error registering step ${filePath}:`, error);
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
catch (error) {
|
|
146
|
-
|
|
147
|
+
printer.printPluginError(`Error loading steps from ${plugin.dirname}:`, error);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
};
|
|
151
152
|
const processPlugins = async (motiaServer) => {
|
|
152
|
-
const
|
|
153
|
+
const { printer, motia } = motiaServer;
|
|
154
|
+
const baseDir = motia.lockedData.baseDir;
|
|
153
155
|
const context = createPluginContext(motiaServer);
|
|
154
|
-
const appConfig = await loadConfig(baseDir);
|
|
156
|
+
const appConfig = await loadConfig(baseDir, printer);
|
|
157
|
+
if (!appConfig?.plugins) {
|
|
158
|
+
printer.printPluginError('No plugins found in motia.config.ts');
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
155
161
|
const plugins = appConfig.plugins?.flatMap((item) => item(context)) || [];
|
|
156
162
|
await processSteps(motiaServer, plugins, baseDir);
|
|
157
163
|
return plugins;
|
|
@@ -3,17 +3,17 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { getStepConfig, PLUGIN_FLOW_ID, } from '@motiadev/core';
|
|
5
5
|
import { globSync } from 'glob';
|
|
6
|
-
const collectPluginSteps = async (dirname, stepPatterns, projectRoot) => {
|
|
6
|
+
const collectPluginSteps = async (dirname, stepPatterns, projectRoot, printer) => {
|
|
7
7
|
const pluginSteps = [];
|
|
8
8
|
if (!fs.existsSync(dirname)) {
|
|
9
|
-
|
|
9
|
+
printer.printPluginWarn(`Directory not found: ${dirname}`);
|
|
10
10
|
return pluginSteps;
|
|
11
11
|
}
|
|
12
12
|
for (const pattern of stepPatterns) {
|
|
13
13
|
try {
|
|
14
14
|
const stepFiles = globSync(pattern, { absolute: true, cwd: dirname });
|
|
15
15
|
if (stepFiles.length === 0) {
|
|
16
|
-
|
|
16
|
+
printer.printPluginLog(`No files found matching pattern: ${pattern} in ${dirname}`);
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
19
19
|
for (const filePath of stepFiles) {
|
|
@@ -23,35 +23,36 @@ const collectPluginSteps = async (dirname, stepPatterns, projectRoot) => {
|
|
|
23
23
|
pluginSteps.push({ filePath, config });
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
|
|
26
|
+
printer.printPluginWarn(`No config found in step ${filePath}, step skipped`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
|
|
30
|
+
printer.printPluginError(`Error loading step ${filePath}:`, error);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
|
|
35
|
+
printer.printPluginError(`Error processing pattern ${pattern}:`, error);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
return pluginSteps;
|
|
39
39
|
};
|
|
40
|
-
const loadConfig = async (baseDir) => {
|
|
40
|
+
const loadConfig = async (baseDir, printer) => {
|
|
41
41
|
const configFiles = globSync('motia.config.{ts,js}', { absolute: true, cwd: baseDir });
|
|
42
42
|
if (configFiles.length === 0) {
|
|
43
43
|
const templatePath = path.join(__dirname, 'create/templates/nodejs/motia.config.ts.txt');
|
|
44
44
|
const templateContent = fs.readFileSync(templatePath, 'utf-8');
|
|
45
45
|
const configPath = path.join(baseDir, 'motia.config.ts');
|
|
46
46
|
fs.writeFileSync(configPath, templateContent);
|
|
47
|
-
|
|
47
|
+
printer.printPluginLog('Created motia.config.ts');
|
|
48
48
|
return (await import(configPath)).default;
|
|
49
49
|
}
|
|
50
50
|
return (await import(configFiles[0])).default;
|
|
51
51
|
};
|
|
52
52
|
const createPluginContext = (motiaServer) => {
|
|
53
|
-
const { motia, addRoute, removeRoute } = motiaServer;
|
|
53
|
+
const { motia, addRoute, removeRoute, printer } = motiaServer;
|
|
54
54
|
return {
|
|
55
|
+
printer,
|
|
55
56
|
tracerFactory: motia.tracerFactory,
|
|
56
57
|
state: motia.stateAdapter,
|
|
57
58
|
lockedData: motia.lockedData,
|
|
@@ -78,12 +79,12 @@ const createPluginContext = (motiaServer) => {
|
|
|
78
79
|
};
|
|
79
80
|
};
|
|
80
81
|
const processSteps = async (motiaServer, plugins, baseDir) => {
|
|
81
|
-
const { motia, addRoute } = motiaServer;
|
|
82
|
+
const { motia, addRoute, printer } = motiaServer;
|
|
82
83
|
for (const plugin of plugins) {
|
|
83
84
|
if (plugin.dirname && plugin.steps) {
|
|
84
|
-
|
|
85
|
+
printer.printPluginLog(`Loading steps from ${plugin.dirname}`);
|
|
85
86
|
try {
|
|
86
|
-
const pluginSteps = await collectPluginSteps(plugin.dirname, plugin.steps, baseDir);
|
|
87
|
+
const pluginSteps = await collectPluginSteps(plugin.dirname, plugin.steps, baseDir, printer);
|
|
87
88
|
const version = `plugin_${randomUUID()}:${Math.floor(Date.now() / 1000)}`;
|
|
88
89
|
for (const { filePath, config } of pluginSteps) {
|
|
89
90
|
try {
|
|
@@ -95,24 +96,29 @@ const processSteps = async (motiaServer, plugins, baseDir) => {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
|
-
|
|
99
|
+
printer.printPluginWarn(`Failed to register step: ${config.name} from ${filePath}`);
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
catch (error) {
|
|
102
|
-
|
|
103
|
+
printer.printPluginError(`Error registering step ${filePath}:`, error);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
catch (error) {
|
|
107
|
-
|
|
108
|
+
printer.printPluginError(`Error loading steps from ${plugin.dirname}:`, error);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
};
|
|
112
113
|
export const processPlugins = async (motiaServer) => {
|
|
113
|
-
const
|
|
114
|
+
const { printer, motia } = motiaServer;
|
|
115
|
+
const baseDir = motia.lockedData.baseDir;
|
|
114
116
|
const context = createPluginContext(motiaServer);
|
|
115
|
-
const appConfig = await loadConfig(baseDir);
|
|
117
|
+
const appConfig = await loadConfig(baseDir, printer);
|
|
118
|
+
if (!appConfig?.plugins) {
|
|
119
|
+
printer.printPluginError('No plugins found in motia.config.ts');
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
116
122
|
const plugins = appConfig.plugins?.flatMap((item) => item(context)) || [];
|
|
117
123
|
await processSteps(motiaServer, plugins, baseDir);
|
|
118
124
|
return plugins;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motia",
|
|
3
3
|
"description": "A Modern Unified Backend Framework for APIs, Events and Agents",
|
|
4
|
-
"version": "0.8.2-beta.140-
|
|
4
|
+
"version": "0.8.2-beta.140-559269",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"python-ast": "^0.1.0",
|
|
47
47
|
"table": "^6.9.0",
|
|
48
48
|
"ts-node": "^10.9.2",
|
|
49
|
-
"@motiadev/
|
|
50
|
-
"@motiadev/
|
|
51
|
-
"@motiadev/
|
|
49
|
+
"@motiadev/core": "0.8.2-beta.140-559269",
|
|
50
|
+
"@motiadev/workbench": "0.8.2-beta.140-559269",
|
|
51
|
+
"@motiadev/stream-client-node": "0.8.2-beta.140-559269"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@amplitude/analytics-types": "^2.9.2",
|