From c46979a93c9b9541be49fcf6a9edec8ed36f508d Mon Sep 17 00:00:00 2001 From: Zewasik Date: Tue, 22 Oct 2024 13:57:33 +0300 Subject: [PATCH] remove --no-project flag change the tests so that they fit the deleted flag --- js/cli/src/app.ts | 11 +++-------- js/cli/src/generate/index.ts | 22 ++++------------------ js/test/demo.test.ts | 2 +- js/test/setup.js | 6 +++--- 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/js/cli/src/app.ts b/js/cli/src/app.ts index 5470dfc6..d6ec7b99 100644 --- a/js/cli/src/app.ts +++ b/js/cli/src/app.ts @@ -8,23 +8,18 @@ import { ProjectBuilder } from './generate/index.js'; const program = new Command(); -const handler = async (path: string, out: string, name: string, project: boolean, yes: boolean) => { +const handler = async (path: string, out: string, name: string, yes: boolean) => { const parser = new SailsIdlParser(); await parser.init(); const sails = new Sails(parser); - const projectBuilder = new ProjectBuilder(sails, name) - .setRootPath(out) - .setIdlPath(path) - .setIsProject(project) - .setAutomaticOverride(yes); + const projectBuilder = new ProjectBuilder(sails, name).setRootPath(out).setIdlPath(path).setAutomaticOverride(yes); await projectBuilder.build(); }; program .command('generate ') - .option('--no-project', 'Generate single file without project structure') .option('-n --name ', 'Name of the library', 'program') .option('-o --out ', 'Output directory') .option('-y --yes', 'Automatic yes to file override prompts') @@ -40,7 +35,7 @@ program }, ) => { try { - await handler(path, options.out, options.name, options.project, options.yes); + await handler(path, options.out, options.name, options.yes); } catch (error) { console.error(error.message); process.exit(1); diff --git a/js/cli/src/generate/index.ts b/js/cli/src/generate/index.ts index df536cf5..4749f7c9 100644 --- a/js/cli/src/generate/index.ts +++ b/js/cli/src/generate/index.ts @@ -10,7 +10,6 @@ import * as config from '../config.json'; export class ProjectBuilder { private projectPath = ['.', 'src']; - private isProject: boolean = true; private isAutomaricOverride: boolean = false; constructor( @@ -62,12 +61,6 @@ export class ProjectBuilder { return this; } - setIsProject(isProject: boolean) { - this.isProject = isProject; - - return this; - } - setAutomaticOverride(isAutomaricOverride: boolean) { this.isAutomaricOverride = isAutomaricOverride; @@ -78,14 +71,12 @@ export class ProjectBuilder { const rootPath = this.projectPath[0]; const srcPath = path.join(...this.projectPath); - const libPath = this.isProject ? srcPath : rootPath; - - if (!existsSync(libPath)) { - mkdirSync(libPath, { recursive: true }); + if (!existsSync(srcPath)) { + mkdirSync(srcPath, { recursive: true }); } const libCode = this.generateLib(); - const libFile = path.join(libPath, 'lib.ts'); + const libFile = path.join(srcPath, 'lib.ts'); if (await this.canCreateFile(libFile)) { writeFileSync(libFile, libCode); } else { @@ -93,18 +84,13 @@ export class ProjectBuilder { } const typesCode = this.generateTypes(); - const typesFile = path.join(libPath, 'global.d.ts'); + const typesFile = path.join(srcPath, 'global.d.ts'); if (await this.canCreateFile(typesFile)) { writeFileSync(typesFile, typesCode); } else { process.exit(0); } - if (!this.isProject) { - console.log(`Lib generated at ${libPath}`); - return; - } - const tsconfigPath = path.join(rootPath, 'tsconfig.json'); const pkgJsonPath = path.join(rootPath, 'package.json'); diff --git a/js/test/demo.test.ts b/js/test/demo.test.ts index 2f539f8e..17dd76fc 100644 --- a/js/test/demo.test.ts +++ b/js/test/demo.test.ts @@ -6,7 +6,7 @@ import { hexToU8a } from '@polkadot/util'; import { readFileSync } from 'fs'; import { getFnNamePrefix, getServiceNamePrefix, H256, NonZeroU32, NonZeroU8, Sails, ZERO_ADDRESS } from '..'; -import { Program } from './demo/lib'; +import { Program } from './demo/src/lib'; import { SailsIdlParser } from 'sails-js-parser'; let sails: Sails; diff --git a/js/test/setup.js b/js/test/setup.js index 1207d2da..24f7f7e9 100644 --- a/js/test/setup.js +++ b/js/test/setup.js @@ -9,14 +9,14 @@ export default () => { execSync('rm -rf ./test/demo'); // Generate demo ts client - execSync('node cli/build/app.js generate ../examples/demo/client/demo.idl -o ./test/demo --no-project --yes'); + execSync('node cli/build/app.js generate ../examples/demo/client/demo.idl -o ./test/demo --yes'); // Modify client imports - const filesToModify = ['test/demo/lib.ts']; + const filesToModify = ['test/demo/src/lib.ts']; for (const path of filesToModify) { - const data = fs.readFileSync(path, 'utf8').replace(`from 'sails-js'`, `from '../..'`); + const data = fs.readFileSync(path, 'utf8').replace(`from 'sails-js'`, `from '../../..'`); fs.writeFileSync(path, data, 'utf8'); } };