Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ICON_TYPES = {
DATA: `${ICON_PATH}data.svg`,
FIGURE: `${ICON_PATH}figure.svg`,
RUST: `${ICON_PATH}rust.svg`,
DART: `${ICON_PATH}dart.svg`,
SQL: `${ICON_PATH}sql.svg`,
GO: `${ICON_PATH}go.svg`,
C: `${ICON_PATH}c.svg`,
Expand Down Expand Up @@ -48,6 +49,8 @@ function CodeNode({ node, renderType }) {
iconUrl = ICON_TYPES.GO;
} else if (node.assetType === 'c') {
iconUrl = ICON_TYPES.C;
} else if (node.assetType === 'dart') {
iconUrl = ICON_TYPES.DART;
} else if (node.assetType === Constants.DependencyType.DATA) {
iconUrl = ICON_TYPES.DATA;
} else if (node.assetType === Constants.DependencyType.FIGURE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ICON_TYPES = {
DATA: `${ICON_PATH}data.svg`,
FIGURE: `${ICON_PATH}figure.svg`,
RUST: `${ICON_PATH}rust.svg`,
DART: `${ICON_PATH}dart.svg`,
SQL: `${ICON_PATH}sql.svg`,
GO: `${ICON_PATH}go.svg`,
C: `${ICON_PATH}c.svg`,
Expand Down Expand Up @@ -56,6 +57,8 @@ function getIcon(node) {
iconUrl = ICON_TYPES.GO;
} else if (node.value === 'c') {
iconUrl = ICON_TYPES.C;
} else if (node.value === 'dart') {
iconUrl = ICON_TYPES.DART;
} else if (node.value === Constants.DependencyType.DATA) {
iconUrl = ICON_TYPES.DATA;
} else if (node.value === Constants.DependencyType.FIGURE) {
Expand Down
5 changes: 5 additions & 0 deletions app/constants/assets-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ module.exports = {
extensions: ['rs'],
categories: ['code'],
},
{
name: 'Dart',
extensions: ['dart'],
categories: ['code'],
},
{
name: 'SQL',
extensions: ['sql'],
Expand Down
1 change: 1 addition & 0 deletions app/images/dart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import CppHandler from './services/assets/handlers/cpp';
import CHandler from './services/assets/handlers/c';
import Constants from './constants/constants';
import SQLHandler from './services/assets/handlers/sql';
import DartHandler from './services/assets/handlers/dart';

const projectService = new ProjectService();
const projectListService = new ProjectListService();
Expand Down Expand Up @@ -64,6 +65,7 @@ contextBridge.exposeInMainWorld('workerElectronBridge', {
new GoHandler(),
new CppHandler(),
new CHandler(),
new DartHandler(),
]);
response.assets = service.scan(project.path); // Returns absolute paths

Expand Down
133 changes: 133 additions & 0 deletions app/services/assets/handlers/dart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import BaseCodeHandler from './baseCode';
import Constants from '../../../constants/constants';

const FILE_EXTENSION_LIST = ['dart'];

export default class DartHandler extends BaseCodeHandler {
static id = 'StatWrap.DartHandler';

constructor() {
super(DartHandler.id, FILE_EXTENSION_LIST);
}

id() {
return DartHandler.id;
}

getLibraryId(moduleName, importName) {
return moduleName || importName || '(unknown)';
}

getInputs(uri, text) {
const inputs = [];
if (!text || text.trim() === '') {
return inputs;
}

const processedPaths = new Set();

// Typical Dart file read operations:
// e.g. File('path/to/file')
const fileMatches = [
...text.matchAll(/File\s*\(\s*(r?['"]{1}[^'"]+['"]{1})\s*\)/gim),
...text.matchAll(/loadString\s*\(\s*(r?['"]{1}[^'"]+['"]{1})\s*\)/gim),
];
for (let index = 0; index < fileMatches.length; index++) {
const match = fileMatches[index];
const path = match[1].trim();
if (!processedPaths.has(path)) {
inputs.push({
id: `File Read - ${path}`,
type: Constants.DependencyType.DATA,
path,
});
processedPaths.add(path);
}
}

// Typical SQLite/database open operations:
// e.g. openDatabase('my_db.db')
const dbMatches = [
...text.matchAll(/openDatabase\s*\(\s*(r?['"]{1,}[\s\S]+?['"]{1,})[\s\S]*?\)/gim)
];
for (let index = 0; index < dbMatches.length; index++) {
const match = dbMatches[index];
const path = match[1].trim();
if (!processedPaths.has(path)) {
inputs.push({
id: `DB Conn - ${path}`,
type: Constants.DependencyType.DATA,
path,
});
processedPaths.add(path);
}
}

return inputs;
}

getOutputs(uri, text) {
const outputs = [];
if (!text || text.trim() === '') {
return outputs;
}

const processedPaths = new Set();

// Typical Dart file write operations:
// e.g. File('path/to/file').writeAsString()
const fileMatches = [
...text.matchAll(/File\s*\(\s*(r?['"]{1,}[\s\S]+?['"]{1,})\s*\)\s*\.\s*write[a-zA-Z]*\s*\(/gim),
];
for (let index = 0; index < fileMatches.length; index++) {
const match = fileMatches[index];
const path = match[1].trim();
if (!processedPaths.has(path)) {
outputs.push({
id: `File Write - ${path}`,
type: Constants.DependencyType.DATA,
path,
});
processedPaths.add(path);
}
}

return outputs;
}

getLibraries(uri, text) {
const libraries = [];
if (!text || text.trim() === '') {
return libraries;
}

// Dart imports:
// import 'package:http/http.dart' as http;
// import 'dart:io';
// import '../local_file.dart';
const importMatches = [
...text.matchAll(/^import\s+(['"]([^'"]+)['"])(?:\s+as\s+([a-zA-Z0-9_]+))?\s*(?:show\s+[^;]+|hide\s+[^;]+)?\s*;/gm),
];
for (let index = 0; index < importMatches.length; index++) {
const match = importMatches[index];
const importPath = match[2];
const alias = match[3] || null;

let moduleName = importPath;
if (moduleName.startsWith('package:')) {
moduleName = moduleName.substring(8); // Remove 'package:'
} else if (moduleName.startsWith('dart:')) {
moduleName = moduleName.substring(5); // Remove 'dart:'
}

libraries.push({
id: this.getLibraryId(moduleName, importPath),
module: moduleName,
import: importPath,
alias,
});
}

return libraries;
}
}
6 changes: 5 additions & 1 deletion app/utils/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SQLHandler from '../services/assets/handlers/sql';
import GoHandler from '../services/assets/handlers/go';
import CppHandler from '../services/assets/handlers/cpp';
import CHandler from '../services/assets/handlers/c';
import DartHandler from '../services/assets/handlers/dart';
import path from 'path';

export default class WorkflowUtil {
Expand Down Expand Up @@ -67,6 +68,8 @@ export default class WorkflowUtil {
assetType = 'go';
} else if (AssetUtil.getHandlerMetadata(CHandler.id, asset.metadata)) {
assetType = 'c';
} else if (AssetUtil.getHandlerMetadata(DartHandler.id, asset.metadata)) {
assetType = 'dart';
}
return assetType;
}
Expand Down Expand Up @@ -371,6 +374,7 @@ export default class WorkflowUtil {
WorkflowUtil._getMetadataDependencies(asset, CppHandler.id, libraries, inputs, outputs);
WorkflowUtil._getMetadataDependencies(asset, CHandler.id, libraries, inputs, outputs);

WorkflowUtil._getMetadataDependencies(asset, DartHandler.id, libraries, inputs, outputs);
return libraries
.map((e) => {
return { ...e, direction: Constants.DependencyDirection.IN };
Expand Down Expand Up @@ -438,7 +442,7 @@ export default class WorkflowUtil {
WorkflowUtil._getMetadataDependencies(asset, GoHandler.id, libraries, [], []);
WorkflowUtil._getMetadataDependencies(asset, CppHandler.id, libraries, [], []);
WorkflowUtil._getMetadataDependencies(asset, CHandler.id, libraries, [], []);

WorkflowUtil._getMetadataDependencies(asset, DartHandler.id, libraries, [], []);
return libraries;
}

Expand Down
Loading