Skip to content

Fix for running on Windows and skip node_modules #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

All notable changes to this project will be documented in this file.

## [1.2.4] 2024-01-06

- Improve Flutter/Dar dependency container names

## [1.2.3] 2023-12-04

- Sort tooltips

## [1.2.2] 2023-12-04

- Better colors

## [1.2.1] 2023-11-18

- Show Dart module versions

## [1.2.0] 2023-08-07

- Support for Flutter/Dart projects

## [1.1.5] 2023-08-07

- Update packages

## [1.1.4] 2023-01-12

- Exclude "node_modules" from import targets

## [1.1.3] 2023-01-11

- Fix for running on Windows

## [1.1.2] 2022-08-04

- package.json fix "main: cli/index.js"
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# GLAD - Generate Layer Architecture Diagram

Automatically generate **layer diagram** view of your Javascript/Typescript source code dependencies.
Automatically generate **layer diagram** view of your Javascript/Typescript/Dart source code dependencies.

## Motivation

View and Keep your project source files layer dependencies clean. Avoid circular reference or referencing an upper layer from a lower layer.

Supports source files of type JS & TS, simply launch the ```glad``` and open the resulting ```glad.svg``` file.
### Project type supported
* NodeJS - source files of type **JS & TS**, simply launch the ```glad``` and open the resulting ```glad.svg``` file.
* **NEW** - Now supports **Flutter/Dart** package dependencies

## Example

Expand Down Expand Up @@ -80,6 +82,7 @@ Options:
--lineEffect, --le Special effect on the lines [string] [default: "flat"]
-l, --layers Display the layers background and numbers [boolean] [default: false]
-d, --details Show additional values for each folders [boolean] [default: false]
--externals Show external dependencies [boolean] [default: false]
--json Output the graph to file called glad.json [boolean] [default: false]
--debug For tech support [boolean] [default: false]
--listFiles List all input files found [boolean] [default: false]
Expand Down
58 changes: 55 additions & 3 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { GLAD } from '../lib/glad.js'
import { createRequire } from 'module'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
const require = createRequire(import.meta.url)

const require = createRequire(import.meta.url)
const fs = require('fs')
const { exec } = require('node:child_process')
const packageJSon = require('../package.json')

// eslint-disable-next-line no-unused-expressions
Expand Down Expand Up @@ -77,6 +79,17 @@ const arg = yargs(hideBin(process.argv))
type: 'boolean',
default: false
})
.option('externals', {
alias: 'ex',
description: 'Show external dependencies',
type: 'boolean',
default: false
})
.option('dev', {
description: 'Show Dev dependencies',
type: 'boolean',
default: false
})
.option('json', {
description: 'Output the graph to file called glad.json',
type: 'boolean',
Expand All @@ -98,7 +111,7 @@ const arg = yargs(hideBin(process.argv))
type: 'boolean',
default: false
})
// .version(true, 'Show version number', packageJSon.version)
// .version(true, 'Show version number', packageJSon.version)
.alias('v', 'version')
.wrap(null)
.epilog('for more information visit https://github.com/amzn/generate-layer-architecture-diagram')
Expand All @@ -118,8 +131,23 @@ if (!arg.silent) {
showTitle()
}

if (!arg.silent) {
console.time('Completed')
}

const glad = new GLAD(arg)
glad.scanSourceFilesBuildGraphAndGenerateSvg()

if (fs.existsSync('./pubspec.yaml')) {
// Dart Project
runDartDept()
} else {
// NodeJS project
glad.scanSourceFilesBuildGraphAndGenerateSvg()
}

if (!arg.silent) {
console.timeEnd('Completed')
}

if (glad.graph.getHasCircularDependencies()) {
console.error(chalk.red('found some circular dependencies'))
Expand All @@ -133,3 +161,27 @@ if (glad.graph.getHasCircularDependencies()) {
function showTitle () {
console.info(chalk.blueBright('GLAD') + ' ' + chalk.blue(packageJSon.version || ''))
}

// run the `ls` command using exec
/**
*
*/
function runDartDept () {
exec('dart pub deps --json', (err, output) => {
// once the command has completed, the callback function is called
if (err) {
// log and return if we encounter an error
console.error('could not execute command: ', err)
return
}
// Read the input dependency structure
const blob = JSON.parse(output)
glad.loadGraphFromFlutterDependencies(blob)
})

// // when a child process exits, it fires
// // the "close" event
// command.on('close', (code) => {
// console.log('process has exited')
// })
}
Loading