fix(project): Fixed minor formatting issues and improved code consistency.

This commit is contained in:
2024-11-05 00:34:56 +01:00
parent 125be257d6
commit 750f081c03
11 changed files with 59 additions and 39 deletions

View File

@@ -28,7 +28,7 @@ export class PublishModule {
public async init() {
this.options.packageSubFolderFullPath = plugins.path.join(
this.options.monoRepoDir,
this.options.packageSubFolder
this.options.packageSubFolder,
);
// check requirements
@@ -36,10 +36,12 @@ export class PublishModule {
throw new Error('subFolder must start with "ts"');
}
this.options.tsPublishJson = plugins.smartfile.fs.toObjectSync(
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json')
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json'),
);
const monoRepoPackageJson = JSON.parse(
plugins.smartfile.fs.toStringSync(plugins.path.join(this.options.monoRepoDir, 'package.json'))
plugins.smartfile.fs.toStringSync(
plugins.path.join(this.options.monoRepoDir, 'package.json'),
),
);
this.options.dependencies = {
...this.options.dependencies,
@@ -67,7 +69,10 @@ export class PublishModule {
const availableVersions = packageInfo.allVersions.map((versionArg) => versionArg.version);
logger.log('info', `available versions are: ${availableVersions.toString()}`);
if (availableVersions.includes(this.options.version)) {
logger.log('error', `package ${this.options.name} already exists with version ${this.options.version}`);
logger.log(
'error',
`package ${this.options.name} already exists with version ${this.options.version}`,
);
process.exit(1);
}
}
@@ -84,11 +89,12 @@ export class PublishModule {
public async createTsconfigJson() {
const originalTsConfig = plugins.smartfile.fs.toObjectSync(
plugins.path.join(paths.cwd, 'tsconfig.json')
plugins.path.join(paths.cwd, 'tsconfig.json'),
);
if (originalTsConfig?.compilerOptions?.paths) {
for (const path of Object.keys(originalTsConfig.compilerOptions.paths)) {
originalTsConfig.compilerOptions.paths[path][0] = `.${originalTsConfig.compilerOptions.paths[path][0]}`;
originalTsConfig.compilerOptions.paths[path][0] =
`.${originalTsConfig.compilerOptions.paths[path][0]}`;
}
}
const tsconfigJson = {
@@ -102,9 +108,7 @@ export class PublishModule {
verbatimModuleSyntax: true,
paths: originalTsConfig?.compilerOptions?.paths,
},
exclude: [
'dist_*/**/*.d.ts',
],
exclude: ['dist_*/**/*.d.ts'],
};
return JSON.stringify(tsconfigJson, null, 2);
}
@@ -146,7 +150,7 @@ export class PublishModule {
public async createPublishModuleDir() {
this.options.publishModDirFullPath = plugins.path.join(
this.options.monoRepoDir,
`dist_publish_${this.options.packageSubFolder}`
`dist_publish_${this.options.packageSubFolder}`,
);
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
@@ -154,7 +158,7 @@ export class PublishModule {
const packageJson = await plugins.smartfile.SmartFile.fromString(
plugins.path.join(this.options.publishModDirFullPath, 'package.json'),
await this.createPackageJson(),
'utf8'
'utf8',
);
await packageJson.write();
@@ -162,26 +166,26 @@ export class PublishModule {
const originalTsConfigJson = await plugins.smartfile.SmartFile.fromString(
plugins.path.join(this.options.publishModDirFullPath, 'tsconfig.json'),
await this.createTsconfigJson(),
'utf8'
'utf8',
);
await originalTsConfigJson.write();
// ts folder
await plugins.smartfile.fs.copy(
this.options.packageSubFolderFullPath,
plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder)
plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder),
);
// readme
await plugins.smartfile.fs.copy(
plugins.path.join(this.options.packageSubFolderFullPath, 'readme.md'),
plugins.path.join(this.options.publishModDirFullPath, 'readme.md')
plugins.path.join(this.options.publishModDirFullPath, 'readme.md'),
);
// license
await plugins.smartfile.fs.copy(
plugins.path.join(this.options.monoRepoDir, 'license'),
plugins.path.join(this.options.publishModDirFullPath, 'license')
plugins.path.join(this.options.publishModDirFullPath, 'license'),
);
}
@@ -203,7 +207,7 @@ export class PublishModule {
await smartshellInstance.exec(
`cd ${this.options.publishModDirFullPath} && pnpm publish ${
registryAccessLevel === 'public' ? '--access public' : ''
} --no-git-checks --registry https://${registryUrl}`
} --no-git-checks --registry https://${registryUrl}`,
);
}
}