Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 37/transpile-check-…
Browse files Browse the repository at this point in the history
…sources
  • Loading branch information
HaidarJbeily7 committed Nov 9, 2024
2 parents 957928c + 3056046 commit 0989688
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
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 @@ -117,6 +117,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 @@ -126,17 +127,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, verbose: options.verbose},
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, verbose: options.verbose}, transformations, parser)
processed++
})
console.log(`Successfully processed ${processed} files`)
}

module.exports = transpile

0 comments on commit 0989688

Please sign in to comment.