Skip to content
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

Feat/add proper logging #116

Merged
merged 9 commits into from
Nov 9, 2024
4 changes: 4 additions & 0 deletions eo2js/src/commands/dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const {execSync} = require('child_process')
const dataize = function(obj, args, options) {
options = {...program.opts(), ...options}
const main = path.resolve(options.target, options.project, '__main__.js')
console.log(`Dataizing object: ${obj}\nUsing main file: ${main}`)
if (args.length > 0) {
console.log(`With arguments: ${args.join(' ')}`)
}
execSync(['node', main, obj, ...args].join(' '), {stdio: 'inherit'})
}

Expand Down
7 changes: 7 additions & 0 deletions eo2js/src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,28 @@ const link = function(options) {
path.resolve(project, 'package.json'),
JSON.stringify(pckg(options))
)
console.log(
`Created package.json in: ${path.resolve(project, 'package.json')}`
)
const lock = path.resolve(project, 'package-lock.json')
if (!fs.existsSync(lock)) {
console.log('Installing dependencies...')
execSync('npm install', {cwd: project})
if (options.dependency) {
fs.cpSync(
options.dependency,
path.resolve(project, 'node_modules/eo2js-runtime'),
{recursive: true}
)
console.log(`Copied eo2js-runtime from ${options.dependency} to ${path.resolve(project, 'node_modules/eo2js-runtime')}`)
}
}
fs.copyFileSync(
path.resolve(options.resources, `js/${main}`),
path.resolve(project, main)
)
console.log(`Copied ${main} file to ${path.resolve(project)}`)
console.log('Project build completed successfully')
}

module.exports = link
5 changes: 5 additions & 0 deletions eo2js/src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const {execSync} = require('child_process')
const test = function(options) {
options = {...program.opts(), ...options}
const dir = path.resolve(options.target, options.project)
console.log(`Running tests in directory: ${dir}`)
const excludeGlobs = options.exclude ? options.exclude.split(',') : []
if (excludeGlobs.length > 0) {
console.log(`Excluding patterns: ${excludeGlobs.join(', ')}`)
}
try {
execSync(
[
Expand Down
19 changes: 12 additions & 7 deletions eo2js/src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const transform = function(tojo, options, transformations, parser) {
const transpile = function(options) {
options = {...program.opts(), ...options}
const foreign = path.resolve(options['target'], options['foreign'])
console.log(`Reading foreign tojos from: ${foreign}`)
if (!fs.existsSync(foreign)) {
throw new Error(`File ${foreign} is not found`)
}
Expand All @@ -112,17 +113,21 @@ const transpile = function(options) {
const transformations = [
'objects', 'package', 'tests', 'attrs', 'data', 'to-js'
].map((name) => path.resolve(options['resources'], `json/${name}.sef.json`))
console.log(`Using transformations from: ${options['resources']}/json/`)
const parser = new XMLParser({ignoreAttributes: false})
const project = path.resolve(options['target'], options['project'])
console.log(`Output directory: ${project}`)
fs.mkdirSync(project, {recursive: true})
JSON.parse(fs.readFileSync(foreign).toString())
const tojos = JSON.parse(fs.readFileSync(foreign).toString())
.filter((tojo) => tojo.hasOwnProperty(verified))
.forEach((tojo) => transform(
tojo,
{target: options['target'], project},
transformations,
parser
))
console.log(`Found ${tojos.length} verified tojos to process`)
let processed = 0
tojos.forEach((tojo) => {
console.log(`Processing: ${tojo[verified]}`)
transform(tojo, {target: options['target'], project}, transformations, parser)
processed++
})
console.log(`Successfully processed ${processed} files`)
}

module.exports = transpile