-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite the binaries and the PlantUML library
BREAKING CHANGE: full refactoring
- Loading branch information
Showing
45,137 changed files
with
446,105 additions
and
329,508 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.gdiag | ||
.idea | ||
build/ | ||
node_modules | ||
test/**/*.png | ||
tmp/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/.* | ||
/test | ||
/tmp | ||
/build | ||
/*.sh | ||
/*.md | ||
/*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,9 @@ | ||
#!/usr/bin/env node | ||
|
||
const F = require('fs'); | ||
const P = require('path'); | ||
const moment = require('moment'); | ||
const glob = require('glob'); | ||
const fetch = require('node-fetch'); | ||
const winston = require('winston'); | ||
const util = require('util'); | ||
const CP = require('child_process'); | ||
const {execute} = require('../lib/gdiag/cli'); | ||
const {log} = require('../lib/logger'); | ||
|
||
const exec = util.promisify(CP.exec); | ||
|
||
const log = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.splat(), | ||
winston.format.simple() | ||
), | ||
transports: [ | ||
new winston.transports.Console({}) | ||
] | ||
}); | ||
|
||
const argv = require('yargs') | ||
.scriptName('gdiag') | ||
.option('working-directory', { | ||
alias: 'w', | ||
default: '.', | ||
describe: 'The directory where the PlantUML files will be discovered and rendered.', | ||
type: 'string' | ||
}) | ||
.option('technical-directory', { | ||
alias: 't', | ||
default: '.gdiag', | ||
describe: 'The directory where technical resources will be stored.', | ||
type: 'string' | ||
}) | ||
.option('library-directory', { | ||
alias: 'l', | ||
default: P.join(__dirname, '../'), | ||
describe: 'The directory where the library is located.', | ||
type: 'string' | ||
}) | ||
.option('java-command', { | ||
alias: 'j', | ||
default: 'java', | ||
describe: 'The command of the java binary.', | ||
type: 'string' | ||
}) | ||
.option('clean', { | ||
alias: 'c', | ||
default: false, | ||
describe: 'Delete recursively the pictures located in the working directory.', | ||
type: 'boolean' | ||
}) | ||
.help() | ||
.usage('$0', 'Render PlantUML diagrams discovered (*.{puml,plantuml}) in the working directory.') | ||
.argv; | ||
|
||
const techDir = argv.t; | ||
const latestRunFile = P.join(argv.t, 'LATEST_RUN'); | ||
const workDir = argv.w; | ||
const libDir = argv.l; | ||
const doCleaning = argv.c; | ||
const javaCmd = argv.j; | ||
|
||
async function plantuml(file) { | ||
await exec(`${javaCmd} -jar ${techDir}/plantuml.jar ${file}`, { | ||
stdio: process.stdout | ||
}).catch(error => log.warn(error.message)); | ||
} | ||
|
||
async function download(url, destination) { | ||
const directory = P.dirname(destination); | ||
if (!F.existsSync(directory)) { | ||
log.info('create destination directory [%s]', directory); | ||
F.mkdirSync(directory, {recursive: true}); | ||
} | ||
if (!F.existsSync(destination)) { | ||
log.info('download [%s] to [%s]', url, destination); | ||
const resource = await fetch(url); | ||
const dest = F.createWriteStream(destination); | ||
resource.body.pipe(dest); | ||
return new Promise((resolve, reject) => { | ||
resource.body.on('end', resolve); | ||
resource.body.on('error', reject); | ||
}); | ||
} | ||
} | ||
|
||
async function downloadPlantUML() { | ||
// https://sourceforge.net/projects/plantuml/files | ||
const url = `https://sourceforge.net/projects/plantuml/files/1.2020.18/plantuml.1.2020.18.jar/download`; | ||
const destination = `${techDir}/plantuml.jar`; | ||
await download(url, destination); | ||
} | ||
|
||
async function cleanDirectory(directory) { | ||
log.info('clean directory [%s]', directory); | ||
const pictures = glob.sync(`**/*.png`, { | ||
cwd: directory | ||
}); | ||
for (const picture of pictures) { | ||
const picturePath = P.join(directory, picture); | ||
log.info('delete [%s]', picturePath); | ||
F.unlinkSync(picturePath); | ||
} | ||
} | ||
|
||
async function getLatestRun() { | ||
if (F.existsSync(latestRunFile)) { | ||
const stat = F.statSync(latestRunFile); | ||
log.info('ran previously on [%s]', stat.mtime); | ||
return moment(stat.mtime); | ||
} | ||
log.info('never ran previously'); | ||
} | ||
|
||
async function setLatestRun() { | ||
F.writeFileSync(latestRunFile, ''); | ||
} | ||
|
||
async function cleanLatestRun() { | ||
if (F.existsSync(latestRunFile)) { | ||
F.unlinkSync(latestRunFile); | ||
} | ||
} | ||
|
||
async function parseDirectory(directory, latestRun) { | ||
log.info('parse directory [%s]', directory); | ||
const sources = glob.sync(`**/*.{puml,plantuml}`, { | ||
cwd: directory | ||
}); | ||
for (const source of sources) { | ||
const file = P.join(directory, source); | ||
const stat = F.statSync(file); | ||
if (!latestRun || moment(stat.mtime).isAfter(latestRun)) { | ||
log.info('process source [%s]', source); | ||
await plantuml(file) | ||
} | ||
} | ||
} | ||
|
||
function linkPlantumlLibs() { | ||
const src = libDir; | ||
const dst = P.join(techDir, 'plantuml-libs'); | ||
log.info('link plantuml-libs from [%s] to [%s]', src, dst); | ||
if (F.existsSync(dst)) { | ||
F.unlinkSync(dst); | ||
} | ||
F.symlinkSync(src, dst, 'dir'); | ||
} | ||
|
||
(async function execute() { | ||
await downloadPlantUML(); | ||
if (doCleaning) { | ||
await cleanLatestRun(); | ||
await cleanDirectory(workDir); | ||
} | ||
linkPlantumlLibs(); | ||
const latestRun = await getLatestRun(); | ||
await parseDirectory(workDir, latestRun); | ||
await setLatestRun(); | ||
}()).catch(e => { | ||
execute().catch(e => { | ||
log.error('gdiag failed'); | ||
log.error(e); | ||
console.error(e) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env node | ||
|
||
const {execute} = require('../lib/glib/cli'); | ||
const {log} = require('../lib/logger'); | ||
|
||
execute().catch(e => { | ||
log.error('glib failed'); | ||
console.error(e) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#rm -Rf build | ||
set -ex | ||
npm run build:aws-20200430 -- $@ | ||
npm run build:aws-20200911 -- $@ | ||
npm run build:azure-v2 -- $@ | ||
npm run build:c4model -- $@ | ||
npm run build:homecloud -- $@ | ||
npm run build:material-4.0 -- $@ |
Oops, something went wrong.