Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b3d77189a | |||
eb21dcc4a4 | |||
66145c904e | |||
23f89eabf3 | |||
51ca619151 | |||
6a8c860c79 | |||
9fdbf7f154 | |||
50456fc004 | |||
1cb97cbf95 | |||
f8ceff48b2 | |||
910cb4c8bf | |||
9bddf09aa7 | |||
4e8671a21d | |||
78c73ee713 | |||
5b768288c5 | |||
023aea2494 | |||
ac839d5419 | |||
750f081c03 | |||
125be257d6 | |||
d4c7fa8d6b | |||
9d41d036f5 | |||
94c38e21b3 | |||
6b3cd84b65 | |||
b2f63efa18 | |||
1d749417a1 | |||
7dc98f9dd3 | |||
1ea207cda1 | |||
ff365ee508 | |||
a3226efd9a | |||
f74a6bf2ad | |||
d47ac4793d | |||
9a89b63cf9 | |||
4ee31f85ab | |||
2b518722df | |||
5f9bd73904 | |||
91f3c90607 | |||
f518670443 | |||
dc97693ec8 | |||
386504b0fb | |||
a7c631bba1 | |||
5922249742 | |||
274b730492 | |||
5bdc3e8bcc | |||
5389034108 | |||
a656e3e040 | |||
819c1dca0f | |||
f3d641d1c1 | |||
1fd74928c5 | |||
0f4c2cbba4 | |||
0b68a2dd57 | |||
fda3204cfb | |||
76a1da6ca5 | |||
1653e48714 |
166
changelog.md
166
changelog.md
@ -1,5 +1,171 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-01-02 - 1.9.1 - fix(publishmodule)
|
||||
Fix incorrect CLI script path during publish module creation
|
||||
|
||||
- Updated the `createBinCliSetup` method to correctly adjust the CLI script path.
|
||||
- Replaced path in base64-decoded CLI file content from './dist_ts/index.js' to './dist_<packageSubFolder>/index.js'.
|
||||
|
||||
## 2025-01-02 - 1.9.0 - feat(core)
|
||||
Refactor gitea asset handling and module initialization
|
||||
|
||||
- Introduced GiteaAssets class to handle gitea asset fetching.
|
||||
- Updated TsPublish and PublishModule classes to use GiteaAssets.
|
||||
- Fixed queryParams in getFiles method of GiteaAssets.
|
||||
|
||||
## 2025-01-01 - 1.8.0 - feat(core)
|
||||
Added GiteaAssets class for managing files in Gitea repositories
|
||||
|
||||
- Introduced GiteaAssets class to handle file retrieval from Gitea repositories.
|
||||
- Added tests for GiteaAssets implementation.
|
||||
- Updated plugins module to include smartrequest for HTTP requests.
|
||||
|
||||
## 2024-11-05 - 1.7.7 - fix(core)
|
||||
Fix dependency resolution in package initialization
|
||||
|
||||
- Corrected the resolution of dependencies from tspublish.json against monorepo's package.json.
|
||||
- Ensures unlisted dependencies in monorepo's package.json default to its version.
|
||||
|
||||
## 2024-11-05 - 1.7.6 - fix(tspublish)
|
||||
Fix the logging of the number of found publish modules
|
||||
|
||||
- Corrected the way the number of publish modules is logged by using Object.keys(publishModules).length instead of publishModules.length.
|
||||
|
||||
## 2024-11-05 - 1.7.5 - fix(core)
|
||||
Fix issue with tspublish.json name validation in TsPublish class
|
||||
|
||||
- Resolved incorrect JSON parsing and validation for 'name' property in tspublish.json in the TsPublish.publish method.
|
||||
- Removed redundant JSON parse from plugin.smartfile.fs.toStringSync in publish method.
|
||||
|
||||
## 2024-11-05 - 1.7.4 - fix(classes.tspublish)
|
||||
Refactor getModuleSubDirs method to streamline name validation for publish modules
|
||||
|
||||
- Moved the check for the presence of the 'name' field in tspublish.json from getModuleSubDirs to the publish method.
|
||||
- Added log warning and continue flow if 'name' is not found during the publish process.
|
||||
|
||||
## 2024-11-05 - 1.7.3 - fix(TsPublish)
|
||||
Add validation for tspublish.json name field
|
||||
|
||||
- Ensure that the tspublish.json file contains a valid name field before processing.
|
||||
- Log a warning message if the name is not found in tspublish.json.
|
||||
|
||||
## 2024-11-05 - 1.7.2 - fix(project)
|
||||
Fixed minor formatting issues and improved code consistency.
|
||||
|
||||
- Added missing semicolons for consistency
|
||||
- Improved indentation in various files for better readability
|
||||
- Corrected usage of newlines and whitespace across the codebase
|
||||
|
||||
## 2024-11-05 - 1.7.1 - fix(core)
|
||||
Implement error handling for missing publish module directories
|
||||
|
||||
- Improved logging for package publish steps
|
||||
- Enhanced CLI feedback messages during the publishing process
|
||||
- Restructured package.json to ensure proper dependencies are published
|
||||
|
||||
## 2024-11-05 - 1.7.0 - feat(core)
|
||||
Enhanced tspublish with ordered compilation and updated dependencies
|
||||
|
||||
- Added 'order' property to ITsPublishJson interface to ensure project compilation order.
|
||||
- Updated development dependencies: @git.zone/tsbuild, @git.zone/tsbundle, @git.zone/tsrun, and @types/node.
|
||||
|
||||
## 2024-10-28 - 1.6.0 - feat(classes.publishmodule)
|
||||
Added copying of readme and license files to publish directory
|
||||
|
||||
- Enhanced the createPublishModuleDir method in PublishModule class to copy the 'readme.md' and 'license' files to the publish directory.
|
||||
|
||||
## 2024-10-28 - 1.5.5 - fix(core)
|
||||
Handled non-existent package in publish module to avoid errors
|
||||
|
||||
- Added error handling in TsPublish for packages not yet existing in the registry.
|
||||
|
||||
## 2024-10-28 - 1.5.4 - fix(core)
|
||||
Fix issues with path keys in tsconfig and logger setup in logging.ts.
|
||||
|
||||
- Corrected the iteration over paths in the createTsconfigJson method of PublishModule.
|
||||
- Fixed logger setup by ensuring console is enabled in logging.ts.
|
||||
|
||||
## 2024-10-28 - 1.5.3 - fix(core)
|
||||
Fix incorrect logging and directory preparation
|
||||
|
||||
- Corrected logging to accurately report the number of detected publish modules.
|
||||
- Ensured the publish directory is emptied before creating package.json.
|
||||
|
||||
## 2024-10-28 - 1.5.2 - fix(core)
|
||||
Add logging for found publish modules
|
||||
|
||||
- Added console logging to display the count and list of discovered publish modules during the publish process.
|
||||
- Included a startup log message indicating the beginning of the tspublish process.
|
||||
|
||||
## 2024-10-28 - 1.5.1 - fix(core)
|
||||
Fixes handling of undefined paths in tsconfig generation.
|
||||
|
||||
- Added a null check for `paths` in the original tsconfig before modifying it.
|
||||
- Enhanced testing by adding a test case for creating a TsPublish instance.
|
||||
|
||||
## 2024-10-28 - 1.5.0 - feat(classes.publishmodule)
|
||||
Add method to create and write tsconfig.json during publish module setup
|
||||
|
||||
- Introduced createTsconfigJson method in PublishModule class to generate a tsconfig.json for each publishable module.
|
||||
- Modified createPublishModuleDir method to include writing of tsconfig.json file.
|
||||
|
||||
## 2024-10-26 - 1.4.0 - feat(core)
|
||||
Refactor directory reading and module discovery for publishing process
|
||||
|
||||
- Renamed 'readDirectory' method to 'getModuleSubDirs' for clarity in describing function purpose.
|
||||
- Enhanced 'getModuleSubDirs' to return module information including parsed 'tspublish.json' data for each module.
|
||||
- Introduced new 'interfaces' directory to define TypeScript interfaces like 'ITsPublishJson'.
|
||||
|
||||
## 2024-10-23 - 1.3.3 - fix(core)
|
||||
Fix logging mechanism on existing package version check
|
||||
|
||||
- Changed the error handling mechanism when a package with the same version already exists to use logger and process exit instead of throwing an error.
|
||||
|
||||
## 2024-10-23 - 1.3.2 - fix(core)
|
||||
Corrected file patterns in dynamically created package.json files.
|
||||
|
||||
- Fixed incorrect file pattern from 'ts_web/**/*' to 'ts_*/**/*' in package.json creation process to include all subdirectories starting with 'ts'.
|
||||
|
||||
## 2024-10-23 - 1.3.1 - fix(classes.publishmodule)
|
||||
Fix template string in createPackageJson method for export path
|
||||
|
||||
- Corrected the syntax for template string in the exports path of created package.json
|
||||
|
||||
## 2024-10-21 - 1.3.0 - feat(core)
|
||||
Add support for multiple registries in the publish process
|
||||
|
||||
- Updated the PublishModule class to handle multiple registries for publishing.
|
||||
- Refactored the handling of tspublish.json by incorporating it into the PublishModule options.
|
||||
- Implemented logic to parse registry access level and apply it during publication.
|
||||
|
||||
## 2024-10-21 - 1.2.4 - fix(publishmodule)
|
||||
Fix syntax errors and improve formatting in classes.publishmodule.ts
|
||||
|
||||
- Fixed missing semicolons in multiple locations for improved syntax correctness.
|
||||
- Improved the formatting for better code readability.
|
||||
- Added --no-git-checks flag to the pnpm publish command.
|
||||
|
||||
## 2024-10-21 - 1.2.3 - fix(logs)
|
||||
Improve logging mechanism with structured logs for publish process
|
||||
|
||||
- Enhanced log messages to provide more clarity during module publishing.
|
||||
- Ensured logging captures steps of publish and init process in TsPublish and PublishModule classes respectively.
|
||||
|
||||
## 2024-10-21 - 1.2.3 - fix(classes.publishmodule)
|
||||
Add missing 'type: module' to dynamically generated package.json
|
||||
|
||||
- Ensure that the 'type: module' field is included in each dynamically generated package.json file for consistent module handling.
|
||||
|
||||
## 2024-10-21 - 1.2.3 - fix(classes.publishmodule)
|
||||
Add missing 'type: module' to dynamically generated package.json
|
||||
|
||||
- Ensure that the 'type: module' field is included in each dynamically generated package.json file for consistent module handling.
|
||||
|
||||
## 2024-10-21 - 1.2.2 - fix(publishmodule)
|
||||
Fix bug in package.json creation for publish module
|
||||
|
||||
- Fixed an issue where `package.json` was not being written to the publish module directory.
|
||||
|
||||
## 2024-10-21 - 1.2.1 - fix(package.json)
|
||||
Ensure bin field is properly restructured
|
||||
|
||||
|
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tspublish",
|
||||
"version": "1.2.1",
|
||||
"version": "1.9.1",
|
||||
"private": false,
|
||||
"description": "A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -14,15 +14,15 @@
|
||||
"buildDocs": "(tsdoc)"
|
||||
},
|
||||
"bin": {
|
||||
"tspublish": "cli.js"
|
||||
"tspublish": "./cli.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.25",
|
||||
"@git.zone/tsbundle": "^2.0.5",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tsbuild": "^2.1.85",
|
||||
"@git.zone/tsbundle": "^2.1.0",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.44",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^22.7.6"
|
||||
"@types/node": "^22.8.7"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -49,10 +49,12 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@push.rocks/smartcli": "^4.0.11",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartfile": "^11.0.21",
|
||||
"@push.rocks/smartlog": "^3.0.7",
|
||||
"@push.rocks/smartnpm": "^2.0.4",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartrequest": "^2.0.23",
|
||||
"@push.rocks/smartshell": "^3.0.6"
|
||||
},
|
||||
"keywords": [
|
||||
|
859
pnpm-lock.yaml
generated
859
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
12
readme.md
12
readme.md
@ -172,11 +172,13 @@ Follow these steps:
|
||||
```typescript
|
||||
import { runCli } from '@git.zone/tspublish';
|
||||
|
||||
runCli().then(() => {
|
||||
console.log('Publishing completed successfully');
|
||||
}).catch((error) => {
|
||||
console.error('Error during publishing:', error);
|
||||
});
|
||||
runCli()
|
||||
.then(() => {
|
||||
console.log('Publishing completed successfully');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during publishing:', error);
|
||||
});
|
||||
```
|
||||
|
||||
3. Execute your CLI script:
|
||||
|
39
test/test.giteaassets.ts
Normal file
39
test/test.giteaassets.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as giteaAssets from '../ts/classes.giteaassets.js';
|
||||
|
||||
let giteaAssetsInstance: giteaAssets.GiteaAssets;
|
||||
|
||||
tap.test('should create a GiteaAssets instance', async () => {
|
||||
giteaAssetsInstance = new giteaAssets.GiteaAssets({
|
||||
giteaBaseUrl: 'https://code.foss.global',
|
||||
});
|
||||
expect(giteaAssetsInstance).toBeInstanceOf(giteaAssets.GiteaAssets);
|
||||
});
|
||||
|
||||
tap.test('should get files from a repository', async () => {
|
||||
const files = await giteaAssetsInstance.getFiles('git.zone', 'cli', 'assets/templates/cli');
|
||||
console.log(files);
|
||||
|
||||
for (const file of files) {
|
||||
if (file.name.endsWith('cli.js')) {
|
||||
console.log(atob(file.base64Content));
|
||||
}
|
||||
}
|
||||
|
||||
expect(files).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.test('should get files from a repository', async () => {
|
||||
const files = await giteaAssetsInstance.getFiles('git.zone', 'cli', 'assets/templates/cli/cli.js');
|
||||
console.log(files);
|
||||
|
||||
for (const file of files) {
|
||||
if (file.name.endsWith('cli.js')) {
|
||||
console.log(atob(file.base64Content));
|
||||
}
|
||||
}
|
||||
|
||||
expect(files).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.start();
|
@ -5,4 +5,9 @@ tap.test('first test', async () => {
|
||||
console.log(tspublish);
|
||||
});
|
||||
|
||||
tap.test('should create a TsPublish instance', async () => {
|
||||
const tspublishInstance = new tspublish.TsPublish();
|
||||
expect(tspublishInstance).toBeTruthy();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tspublish',
|
||||
version: '1.2.1',
|
||||
version: '1.9.1',
|
||||
description: 'A tool to publish multiple, concise, and small packages from monorepos, specifically for TypeScript projects within a git environment.'
|
||||
}
|
||||
|
103
ts/classes.giteaassets.ts
Normal file
103
ts/classes.giteaassets.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
interface IRepoFile {
|
||||
name: string;
|
||||
path: string;
|
||||
type: 'file' | 'dir';
|
||||
download_url: string | null;
|
||||
base64Content: string | null;
|
||||
encoding: string | null;
|
||||
}
|
||||
|
||||
interface IGiteaAssetsOptions {
|
||||
giteaBaseUrl: string; // Base URL of your Gitea instance
|
||||
token?: string; // Optional token for private repositories
|
||||
}
|
||||
|
||||
export class GiteaAssets {
|
||||
private baseUrl: string;
|
||||
private headers: {[key: string]: string} = {};
|
||||
|
||||
constructor(options: IGiteaAssetsOptions) {
|
||||
this.baseUrl = options.giteaBaseUrl
|
||||
if (this.baseUrl.endsWith('/')) {
|
||||
this.baseUrl = this.baseUrl.slice(0, -1);
|
||||
}
|
||||
this.baseUrl += '/api/v1';
|
||||
this.headers = options.token
|
||||
? { ...this.headers, 'Authorization': `token ${options.token}` }
|
||||
: this.headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all files in a directory of a repository
|
||||
* @param owner - Repository owner
|
||||
* @param repo - Repository name
|
||||
* @param directory - Directory path ('' for root)
|
||||
* @param branch - Branch name (optional)
|
||||
* @returns A list of files in the directory
|
||||
*/
|
||||
async getFiles(
|
||||
owner: string,
|
||||
repo: string,
|
||||
directory: string,
|
||||
branch?: string
|
||||
): Promise<IRepoFile[]> {
|
||||
try {
|
||||
const response = await plugins.smartrequest.request(
|
||||
this.baseUrl + `/repos/${owner}/${repo}/contents/${directory}`,
|
||||
{
|
||||
headers: this.headers,
|
||||
method: 'GET',
|
||||
queryParams: branch ? { ref: branch } : {},
|
||||
}
|
||||
)
|
||||
if (!Array.isArray(response.body) && typeof response.body === 'object') {
|
||||
response.body = [response.body];
|
||||
} else if (Array.isArray(response.body)) {
|
||||
for (const entry of response.body) {
|
||||
if (entry.type === 'dir') {
|
||||
continue;
|
||||
} else if (entry.type === 'file') {
|
||||
const response2 = await plugins.smartrequest.request(
|
||||
this.baseUrl + `/repos/${owner}/${repo}/contents/${entry.path}`,
|
||||
{
|
||||
headers: this.headers,
|
||||
method: 'GET',
|
||||
queryParams: branch ? { ref: branch } : {},
|
||||
}
|
||||
);
|
||||
entry.encoding = response2.body.encoding;
|
||||
entry.content = response2.body.content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lets map to the IRepoFile interface
|
||||
response.body = response.body.map((entry: any) => {
|
||||
return {
|
||||
name: entry.name,
|
||||
path: entry.path,
|
||||
type: entry.type,
|
||||
download_url: entry.download_url,
|
||||
base64Content: entry.content,
|
||||
encoding: entry.encoding,
|
||||
};
|
||||
});
|
||||
|
||||
return response.body;
|
||||
} catch (error) {
|
||||
console.error('Error fetching repository files:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the current cli entry file from the code.foss.global/git.zone/cli repository
|
||||
* @returns
|
||||
*/
|
||||
public async getBinCliEntryFile() {
|
||||
const files = await this.getFiles('git.zone', 'cli', 'assets/templates/cli/cli.js');
|
||||
return files[0];
|
||||
}
|
||||
}
|
@ -2,10 +2,14 @@ import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
import { logger } from './logging.js';
|
||||
|
||||
import { type ITsPublishJson } from './interfaces/index.js';
|
||||
import type { TsPublish } from './classes.tspublish.js';
|
||||
|
||||
export interface IPublishModuleOptions {
|
||||
monoRepoDir: string;
|
||||
packageSubFolder: string;
|
||||
packageSubFolderFullPath?: string;
|
||||
tsPublishJson?: ITsPublishJson;
|
||||
publishModDirFullPath?: string;
|
||||
name?: string;
|
||||
version?: string;
|
||||
@ -13,8 +17,10 @@ export interface IPublishModuleOptions {
|
||||
}
|
||||
|
||||
export class PublishModule {
|
||||
tsPublishRef: TsPublish;
|
||||
public options: IPublishModuleOptions;
|
||||
constructor(options: IPublishModuleOptions) {
|
||||
constructor(tsPublishRef: TsPublish, options: IPublishModuleOptions) {
|
||||
this.tsPublishRef = tsPublishRef;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@ -28,35 +34,50 @@ export class PublishModule {
|
||||
if (!this.options.packageSubFolder.startsWith('ts')) {
|
||||
throw new Error('subFolder must start with "ts"');
|
||||
}
|
||||
const jsonData = plugins.smartfile.fs.toObjectSync(
|
||||
this.options.tsPublishJson = plugins.smartfile.fs.toObjectSync(
|
||||
plugins.path.join(this.options.packageSubFolderFullPath, 'tspublish.json')
|
||||
);
|
||||
|
||||
// the package.json of the parent mono repo
|
||||
const monoRepoPackageJson = JSON.parse(
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(this.options.monoRepoDir, 'package.json'))
|
||||
)
|
||||
);
|
||||
|
||||
this.options.dependencies = {
|
||||
...this.options.dependencies,
|
||||
...(() => {
|
||||
const resultDependencies = {};
|
||||
for (const dependency of jsonData.dependencies) {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.dependencies[dependency];
|
||||
for (const dependency of this.options.tsPublishJson.dependencies) {
|
||||
if (monoRepoPackageJson.dependencies[dependency]) {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.dependencies[dependency];
|
||||
} else {
|
||||
resultDependencies[dependency] = monoRepoPackageJson.version;
|
||||
}
|
||||
}
|
||||
return resultDependencies;
|
||||
})()
|
||||
})(),
|
||||
};
|
||||
this.options.name = this.options.name || jsonData.name;
|
||||
this.options.name = this.options.name || this.options.tsPublishJson.name;
|
||||
this.options.version = monoRepoPackageJson.version;
|
||||
|
||||
// now that we have a name and version, lets check if there is already a package under the same name and version.
|
||||
const smartnpmInstance = new plugins.smartnpm.NpmRegistry({}); // TODO: pass in options
|
||||
const packageInfo = await smartnpmInstance.getPackageInfo(this.options.name);
|
||||
let packageInfo: plugins.smartnpm.NpmPackage;
|
||||
try {
|
||||
packageInfo = await smartnpmInstance.getPackageInfo(this.options.name);
|
||||
} catch (error) {
|
||||
logger.log('warn', `package does not yet seem to exist. Proceeding in 10 seconds...`);
|
||||
await plugins.smartdelay.delayFor(10000);
|
||||
}
|
||||
if (packageInfo) {
|
||||
const availableVersions = packageInfo.allVersions.map((versionArg) => versionArg.version);
|
||||
logger.log('info', `available versions are: ${availableVersions.toString()}`);
|
||||
if (availableVersions.includes(this.options.version)) {
|
||||
throw new Error(
|
||||
logger.log(
|
||||
'error',
|
||||
`package ${this.options.name} already exists with version ${this.options.version}`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,14 +91,42 @@ export class PublishModule {
|
||||
return packageInfo.allVersions[0].version;
|
||||
}
|
||||
|
||||
public async createTsconfigJson() {
|
||||
const originalTsConfig = plugins.smartfile.fs.toObjectSync(
|
||||
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]}`;
|
||||
}
|
||||
}
|
||||
const tsconfigJson = {
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
useDefineForClassFields: false,
|
||||
target: 'ES2022',
|
||||
module: 'NodeNext',
|
||||
moduleResolution: 'NodeNext',
|
||||
esModuleInterop: true,
|
||||
verbatimModuleSyntax: true,
|
||||
paths: originalTsConfig?.compilerOptions?.paths,
|
||||
},
|
||||
exclude: ['dist_*/**/*.d.ts'],
|
||||
};
|
||||
return JSON.stringify(tsconfigJson, null, 2);
|
||||
}
|
||||
|
||||
public async createPackageJson() {
|
||||
const packageJson = {
|
||||
name: this.options.name,
|
||||
version: this.options.version,
|
||||
type: 'module',
|
||||
description: '',
|
||||
exports: {
|
||||
'.': {
|
||||
import: './dist_${this.options.packageSubFolder}/index.js',
|
||||
import: `./dist_${this.options.packageSubFolder}/index.js`,
|
||||
},
|
||||
},
|
||||
scripts: {
|
||||
@ -87,6 +136,27 @@ export class PublishModule {
|
||||
devDependencies: {
|
||||
'@git.zone/tsbuild': await this.getLatestVersionOfPackage('@git.zone/tsbuild'),
|
||||
},
|
||||
files: [
|
||||
'ts/**/*',
|
||||
'ts_*/**/*',
|
||||
'dist/**/*',
|
||||
'dist_*/**/*',
|
||||
'dist_ts/**/*',
|
||||
'dist_ts_web/**/*',
|
||||
'assets/**/*',
|
||||
'cli.js',
|
||||
'npmextra.json',
|
||||
'readme.md',
|
||||
],
|
||||
...this.options.tsPublishJson.bin ? {
|
||||
bin: (() => {
|
||||
const binObject: {[key: string]: string} = {};
|
||||
for (const bin of this.options.tsPublishJson.bin) {
|
||||
binObject[bin] = `./cli.js`;
|
||||
}
|
||||
return binObject;
|
||||
})()
|
||||
} : {},
|
||||
};
|
||||
return JSON.stringify(packageJson, null, 2);
|
||||
}
|
||||
@ -96,30 +166,81 @@ export class PublishModule {
|
||||
this.options.monoRepoDir,
|
||||
`dist_publish_${this.options.packageSubFolder}`
|
||||
);
|
||||
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
|
||||
|
||||
// package.json
|
||||
await plugins.smartfile.fs.ensureEmptyDir(this.options.publishModDirFullPath);
|
||||
const packageJson = await plugins.smartfile.SmartFile.fromString(
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'package.json'),
|
||||
await this.createPackageJson(),
|
||||
'utf8'
|
||||
);
|
||||
await packageJson.write();
|
||||
|
||||
// ts folder
|
||||
await plugins.smartfile.fs.copy(this.options.packageSubFolderFullPath, plugins.path.join(this.options.publishModDirFullPath, this.options.packageSubFolder))
|
||||
// tsconfig.json
|
||||
const tsconfigJson = await plugins.smartfile.SmartFile.fromString(
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'tsconfig.json'),
|
||||
await this.createTsconfigJson(),
|
||||
'utf8'
|
||||
);
|
||||
await tsconfigJson.write();
|
||||
|
||||
// ts subfolder, the folder that contains the source code and is being transpiled
|
||||
await plugins.smartfile.fs.copy(
|
||||
this.options.packageSubFolderFullPath,
|
||||
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')
|
||||
);
|
||||
|
||||
// license
|
||||
await plugins.smartfile.fs.copy(
|
||||
plugins.path.join(this.options.monoRepoDir, 'license'),
|
||||
plugins.path.join(this.options.publishModDirFullPath, 'license')
|
||||
);
|
||||
|
||||
// cli stuff
|
||||
this.createBinCliSetup();
|
||||
}
|
||||
|
||||
public async build() {
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
})
|
||||
});
|
||||
await smartshellInstance.exec(`cd ${this.options.publishModDirFullPath} && pnpm run build`);
|
||||
}
|
||||
|
||||
public async createBinCliSetup() {
|
||||
const binSetupApplies: boolean =
|
||||
this.options.tsPublishJson.bin &&
|
||||
Array.isArray(this.options.tsPublishJson.bin) &&
|
||||
this.options.tsPublishJson.bin.length > 0;
|
||||
const files = await this.tsPublishRef.giteaAssetsInstance.getFiles(
|
||||
'git.zone',
|
||||
'cli',
|
||||
'assets/templates/cli/cli.js'
|
||||
);
|
||||
const indexPath = `./dist_${this.options.packageSubFolder}/index.js`;
|
||||
const fileContent = atob(files[0].base64Content).replace('./dist_ts/index.js', indexPath);
|
||||
await plugins.smartfile.memory.toFs(fileContent, plugins.path.join(this.options.publishModDirFullPath, 'cli.js'));
|
||||
}
|
||||
|
||||
public async publish() {
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
})
|
||||
await smartshellInstance.exec(`cd ${this.options.publishModDirFullPath} && pnpm publish`);
|
||||
});
|
||||
for (const registry of this.options.tsPublishJson.registries) {
|
||||
const registryArray = registry.split(':');
|
||||
const registryUrl = registryArray[0];
|
||||
const registryAccessLevel = registryArray[1];
|
||||
await smartshellInstance.exec(
|
||||
`cd ${this.options.publishModDirFullPath} && pnpm publish ${
|
||||
registryAccessLevel === 'public' ? '--access public' : ''
|
||||
} --no-git-checks --registry https://${registryUrl}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,35 @@
|
||||
import { logger } from './logging.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
import { PublishModule } from './classes.publishmodule.js';
|
||||
import { GiteaAssets } from './classes.giteaassets.js';
|
||||
|
||||
export class TsPublish {
|
||||
constructor() {}
|
||||
public giteaAssetsInstance: GiteaAssets;
|
||||
|
||||
public async publish (monorepoDirArg: string) {
|
||||
const publishModules = await this.readDirectory(monorepoDirArg);
|
||||
for (const publishModule of publishModules) {
|
||||
const publishModuleInstance = new PublishModule({
|
||||
constructor() {
|
||||
this.giteaAssetsInstance = new GiteaAssets({
|
||||
giteaBaseUrl: 'https://code.foss.global',
|
||||
});
|
||||
}
|
||||
|
||||
public async publish(monorepoDirArg: string) {
|
||||
const publishModules = await this.getModuleSubDirs(monorepoDirArg);
|
||||
logger.log('info', `Found ${Object.keys(publishModules).length} publish modules:`);
|
||||
for (const publishModule of Object.keys(publishModules)) {
|
||||
logger.log(
|
||||
'info',
|
||||
`Publishing module: ${publishModule} -> ${publishModules[publishModule].name}`
|
||||
);
|
||||
}
|
||||
for (const publishModule of Object.keys(publishModules)) {
|
||||
// lets check wether there is a name
|
||||
if (!publishModules[publishModule].name) {
|
||||
logger.log('warn', `no name found in tspublish.json for ${publishModule}. Skipping...`);
|
||||
continue;
|
||||
}
|
||||
const publishModuleInstance = new PublishModule(this, {
|
||||
monoRepoDir: monorepoDirArg,
|
||||
packageSubFolder: publishModule,
|
||||
});
|
||||
@ -20,9 +40,9 @@ export class TsPublish {
|
||||
}
|
||||
}
|
||||
|
||||
public async readDirectory (dirArg: string) {
|
||||
public async getModuleSubDirs(dirArg: string) {
|
||||
const subDirs = await plugins.smartfile.fs.listFolders(dirArg);
|
||||
const publishModules: string[] = [];
|
||||
const publishModules: { [key: string]: interfaces.ITsPublishJson } = {};
|
||||
for (const subDir of subDirs) {
|
||||
if (!subDir.startsWith('ts')) {
|
||||
continue;
|
||||
@ -32,10 +52,15 @@ export class TsPublish {
|
||||
if (!hasPublishJson) {
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.log('info', `found publish module: ${subDir}`);
|
||||
publishModules.push(subDir);
|
||||
publishModules[subDir] = JSON.parse(
|
||||
plugins.smartfile.fs.toStringSync(plugins.path.join(subDir, 'tspublish.json'))
|
||||
);
|
||||
}
|
||||
logger.log('ok', `found ${publishModules.length} publish modules`);
|
||||
logger.log('ok', `found ${Object.keys(publishModules).length} publish modules`);
|
||||
logger.log('info', `Ordering publish modules...`);
|
||||
|
||||
return publishModules;
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import * as paths from './paths.js';
|
||||
import { TsPublish } from './classes.tspublish.js';
|
||||
|
||||
export * from './classes.tspublish.js'
|
||||
export * from './classes.tspublish.js';
|
||||
|
||||
export const runCli = async () => {
|
||||
console.log('Starting tspublish...');
|
||||
const tspublish = new TsPublish();
|
||||
await tspublish.publish(paths.cwd);
|
||||
}
|
||||
};
|
||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './tspublish.js';
|
13
ts/interfaces/tspublish.ts
Normal file
13
ts/interfaces/tspublish.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export interface ITsPublishJson {
|
||||
/**
|
||||
* the order assures that a project is compiled before another project
|
||||
*/
|
||||
order: number;
|
||||
name: string;
|
||||
dependencies: string[];
|
||||
registries: string[];
|
||||
/**
|
||||
* allows the sepcification of bin names that invoke cli scripts
|
||||
*/
|
||||
bin: string[];
|
||||
}
|
@ -2,3 +2,4 @@ import * as plugins from './plugins.js';
|
||||
import * as commitinfo from './00_commitinfo_data.js';
|
||||
|
||||
export const logger = plugins.smartlog.Smartlog.createForCommitinfo(commitinfo.commitinfo);
|
||||
logger.enableConsole();
|
||||
|
@ -2,6 +2,8 @@ import * as plugins from './plugins.js';
|
||||
|
||||
export const cwd = process.cwd();
|
||||
|
||||
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '..');
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'..',
|
||||
);
|
||||
export const nogitDir = plugins.path.join(packageDir, '.nogit');
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
export {
|
||||
path,
|
||||
}
|
||||
export { path };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartcli from '@push.rocks/smartcli';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as smartnpm from '@push.rocks/smartnpm';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { smartfile, smartcli, smartlog, smartnpm, smartpath, smartshell };
|
||||
export { smartfile, smartcli, smartdelay, smartlog, smartnpm, smartpath, smartrequest, smartshell };
|
||||
|
@ -6,7 +6,9 @@
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
|
Loading…
x
Reference in New Issue
Block a user