From cd24b1cff533f4e89200c4fd2808c457d816e5c5 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Wed, 6 Nov 2024 21:44:52 +0300 Subject: [PATCH 1/8] add proper logging --- eo2js/src/commands/dataize.js | 5 +++++ eo2js/src/commands/link.js | 11 +++++++++++ eo2js/src/commands/test.js | 9 ++++++++- eo2js/src/commands/transpile.js | 20 +++++++++++++------- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/eo2js/src/commands/dataize.js b/eo2js/src/commands/dataize.js index bdcb064..00add64 100644 --- a/eo2js/src/commands/dataize.js +++ b/eo2js/src/commands/dataize.js @@ -11,6 +11,11 @@ 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}`) + console.log(`Using main file: ${main}`) + if (args.length > 0) { + console.log(`With arguments: ${args.join(' ')}`) + } execSync(['node', main, obj, ...args].join(' '), {stdio: 'inherit'}) } diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index 4c7d1bc..a4cbc29 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -52,22 +52,33 @@ const pckg = function(options) { const link = function(options) { options = {...program.opts(), ...options} const project = path.resolve(options.target, options.project) + console.log(`Building npm project in: ${project}`) + + console.log('Creating package.json...') fs.writeFileSync( path.resolve(project, 'package.json'), JSON.stringify(pckg(options)) ) + + console.log('Installing dependencies...') execSync('npm install', {cwd: project}) + + console.log(`Copying ${main} file...`) fs.copyFileSync( path.resolve(options.resources, `js/${main}`), path.resolve(project, main) ) + if (options.dependency) { + console.log(`Copying local eo2js-runtime from: ${options.dependency}`) fs.cpSync( options.dependency, path.resolve(project, 'node_modules/eo2js-runtime'), {recursive: true} ) } + + console.log('Project build completed successfully') } module.exports = link diff --git a/eo2js/src/commands/test.js b/eo2js/src/commands/test.js index 7b6e238..facb6c4 100644 --- a/eo2js/src/commands/test.js +++ b/eo2js/src/commands/test.js @@ -9,6 +9,13 @@ 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( [ @@ -21,7 +28,7 @@ const test = function(options) { {stdio: 'inherit', cwd: dir} ) } catch (ex) { - console.error('Failed to execute mochajs', ex.message) + console.error('Failed to execute mochajs:', ex.message) throw ex } } diff --git a/eo2js/src/commands/transpile.js b/eo2js/src/commands/transpile.js index bcdc904..9a76929 100644 --- a/eo2js/src/commands/transpile.js +++ b/eo2js/src/commands/transpile.js @@ -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`) } @@ -112,17 +113,22 @@ 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 From 71f5b7180a8f4dc09c9f21d28a9189ac2637bec6 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Wed, 6 Nov 2024 21:47:35 +0300 Subject: [PATCH 2/8] revert link test --- eo2js/test/commands/link.test.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/eo2js/test/commands/link.test.js b/eo2js/test/commands/link.test.js index 06050f7..eff85e7 100644 --- a/eo2js/test/commands/link.test.js +++ b/eo2js/test/commands/link.test.js @@ -39,20 +39,4 @@ describe('link', function() { assertFilesExist(link('--tests'), project, ['node_modules/mocha']) done() }) - it('should not reinstall npm packages if package-lock.json exists', function(done) { - // First run to create initial files - link() - - // Get modification time of package-lock.json - const lockFilePath = path.resolve(project, 'package-lock.json') - const initialMtime = fs.statSync(lockFilePath).mtime - - // Run link again - link() - - // Check if package-lock.json was not modified - const finalMtime = fs.statSync(lockFilePath).mtime - assert.strictEqual(initialMtime.getTime(), finalMtime.getTime(), 'package-lock.json was modified on second run') - done() - }) }) From ff9fe49f50e38d041b3545ea570a0c8c6bfda4bb Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Wed, 6 Nov 2024 21:57:29 +0300 Subject: [PATCH 3/8] fix lint warnings --- eo2js/src/commands/test.js | 1 - eo2js/src/commands/transpile.js | 1 - 2 files changed, 2 deletions(-) diff --git a/eo2js/src/commands/test.js b/eo2js/src/commands/test.js index facb6c4..4519969 100644 --- a/eo2js/src/commands/test.js +++ b/eo2js/src/commands/test.js @@ -10,7 +10,6 @@ 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(', ')}`) diff --git a/eo2js/src/commands/transpile.js b/eo2js/src/commands/transpile.js index 9a76929..0fd6d7f 100644 --- a/eo2js/src/commands/transpile.js +++ b/eo2js/src/commands/transpile.js @@ -120,7 +120,6 @@ const transpile = function(options) { fs.mkdirSync(project, {recursive: true}) const tojos = JSON.parse(fs.readFileSync(foreign).toString()) .filter((tojo) => tojo.hasOwnProperty(verified)) - console.log(`Found ${tojos.length} verified tojos to process`) let processed = 0 tojos.forEach((tojo) => { From 685751a889a84798d519079bbd5ae74726d643f8 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Sat, 9 Nov 2024 13:22:13 +0300 Subject: [PATCH 4/8] feat(logging): enhance logging quality --- eo2js/src/commands/dataize.js | 3 +-- eo2js/src/commands/link.js | 15 ++++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/eo2js/src/commands/dataize.js b/eo2js/src/commands/dataize.js index 00add64..69a2cc9 100644 --- a/eo2js/src/commands/dataize.js +++ b/eo2js/src/commands/dataize.js @@ -11,8 +11,7 @@ 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}`) - console.log(`Using main file: ${main}`) + console.log(`Dataizing object: ${obj}\nUsing main file: ${main}`) if (args.length > 0) { console.log(`With arguments: ${args.join(' ')}`) } diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index 6e55054..87df40e 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -52,20 +52,14 @@ const pckg = function(options) { const link = function(options) { options = {...program.opts(), ...options} const project = path.resolve(options.target, options.project) - console.log(`Building npm project in: ${project}`) - - console.log('Creating package.json...') fs.writeFileSync( path.resolve(project, 'package.json'), JSON.stringify(pckg(options)) ) - - console.log('Installing dependencies...') - execSync('npm install', {cwd: project}) - - console.log(`Copying ${main} file...`) + 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( @@ -79,16 +73,15 @@ const link = function(options) { path.resolve(options.resources, `js/${main}`), path.resolve(project, main) ) - + console.log(`Copied ${main} file to ${path.resolve(project)}`) if (options.dependency) { - console.log(`Copying local eo2js-runtime from: ${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')}`) } - console.log('Project build completed successfully') } From 6fdc617e6f6b09b28dc79fac4cb8165d0e838665 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Sat, 9 Nov 2024 13:24:25 +0300 Subject: [PATCH 5/8] feat(logging): enhance logging quality --- eo2js/src/commands/link.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index 87df40e..effa967 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -1,7 +1,7 @@ -const {program} = require('commander'); -const path = require('path'); -const fs = require('fs'); -const {execSync} = require('child_process'); +const { program } = require('commander') +const path = require('path') +const fs = require('fs') +const { execSync } = require('child_process') /** * Entry point JS file. @@ -15,7 +15,7 @@ const main = '__main__.js' * @param {{dependency: string, tests: boolean, runtimeVersion: string}} options - Program options * @return {{author: string, name: string, version: string}} - The content for package.json file */ -const pckg = function(options) { +const pckg = function (options) { const def = { name: 'project', version: '1.0.0', @@ -32,7 +32,7 @@ const pckg = function(options) { if (!!options.tests) { def.dependencies = { ...def.dependencies, - 'mocha': 'latest' + mocha: 'latest' } } return def @@ -49,24 +49,27 @@ const pckg = function(options) { * dependency: ?String, * }} options - Program options */ -const link = function(options) { - options = {...program.opts(), ...options} +const link = function (options) { + options = { ...program.opts(), ...options } const project = path.resolve(options.target, options.project) fs.writeFileSync( path.resolve(project, 'package.json'), JSON.stringify(pckg(options)) ) - console.log(`Created package.json in: ${path.resolve(project, 'package.json')}`) + 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}) + execSync('npm install', { cwd: project }) if (options.dependency) { fs.cpSync( options.dependency, path.resolve(project, 'node_modules/eo2js-runtime'), - {recursive: true} + { recursive: true } ) + console.log(`Copied eo2js-runtime from ${options.dependency} to ${path.resolve(project, 'node_modules/eo2js-runtime')}`) } } fs.copyFileSync( @@ -74,14 +77,6 @@ const link = function(options) { path.resolve(project, main) ) console.log(`Copied ${main} file to ${path.resolve(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')}`) - } console.log('Project build completed successfully') } From 56418d908894112aa02396f85106acdabb33a681 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Sat, 9 Nov 2024 13:26:37 +0300 Subject: [PATCH 6/8] feat(logging): enhance logging quality --- eo2js/src/commands/link.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index effa967..bc8896f 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -1,7 +1,7 @@ -const { program } = require('commander') -const path = require('path') -const fs = require('fs') -const { execSync } = require('child_process') +const {program} = require('commander'); +const path = require('path'); +const fs = require('fs'); +const {execSync} = require('child_process'); /** * Entry point JS file. @@ -15,7 +15,7 @@ const main = '__main__.js' * @param {{dependency: string, tests: boolean, runtimeVersion: string}} options - Program options * @return {{author: string, name: string, version: string}} - The content for package.json file */ -const pckg = function (options) { +const pckg = function(options) { const def = { name: 'project', version: '1.0.0', @@ -32,7 +32,7 @@ const pckg = function (options) { if (!!options.tests) { def.dependencies = { ...def.dependencies, - mocha: 'latest' + 'mocha': 'latest' } } return def @@ -49,8 +49,8 @@ const pckg = function (options) { * dependency: ?String, * }} options - Program options */ -const link = function (options) { - options = { ...program.opts(), ...options } +const link = function(options) { + options = {...program.opts(), ...options} const project = path.resolve(options.target, options.project) fs.writeFileSync( path.resolve(project, 'package.json'), @@ -62,14 +62,19 @@ const link = function (options) { const lock = path.resolve(project, 'package-lock.json') if (!fs.existsSync(lock)) { console.log('Installing dependencies...') - execSync('npm install', { cwd: project }) + execSync('npm install', {cwd: project}) if (options.dependency) { fs.cpSync( options.dependency, path.resolve(project, 'node_modules/eo2js-runtime'), - { recursive: true } + {recursive: true} + ) + console.log( + `Copied eo2js-runtime from ${options.dependency} to ${path.resolve( + project, + 'node_modules/eo2js-runtime' + )}` ) - console.log(`Copied eo2js-runtime from ${options.dependency} to ${path.resolve(project, 'node_modules/eo2js-runtime')}`) } } fs.copyFileSync( From 8142eb0afc2f0ff977009dbb502d174dcad15b42 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Sat, 9 Nov 2024 13:29:20 +0300 Subject: [PATCH 7/8] feat(logging): enhance logging quality --- eo2js/src/commands/link.js | 7 +------ eo2js/src/commands/test.js | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/eo2js/src/commands/link.js b/eo2js/src/commands/link.js index bc8896f..63c9e36 100644 --- a/eo2js/src/commands/link.js +++ b/eo2js/src/commands/link.js @@ -69,12 +69,7 @@ const link = function(options) { 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' - )}` - ) + console.log(`Copied eo2js-runtime from ${options.dependency} to ${path.resolve(project, 'node_modules/eo2js-runtime')}`) } } fs.copyFileSync( diff --git a/eo2js/src/commands/test.js b/eo2js/src/commands/test.js index 4519969..0b136c0 100644 --- a/eo2js/src/commands/test.js +++ b/eo2js/src/commands/test.js @@ -27,7 +27,7 @@ const test = function(options) { {stdio: 'inherit', cwd: dir} ) } catch (ex) { - console.error('Failed to execute mochajs:', ex.message) + console.error('Failed to execute mochajs', ex.message) throw ex } } From 305604647e51b9186490be3cc5e692cc14d18b88 Mon Sep 17 00:00:00 2001 From: HaidarJbeily7 Date: Sat, 9 Nov 2024 13:31:51 +0300 Subject: [PATCH 8/8] feat(logging): enhance logging quality --- eo2js/src/commands/test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eo2js/src/commands/test.js b/eo2js/src/commands/test.js index 0b136c0..042cc8b 100644 --- a/eo2js/src/commands/test.js +++ b/eo2js/src/commands/test.js @@ -14,7 +14,6 @@ const test = function(options) { if (excludeGlobs.length > 0) { console.log(`Excluding patterns: ${excludeGlobs.join(', ')}`) } - try { execSync( [