-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create plugin/hook for a Typescript (npm) version of Maven Artifact Zip Directory Structure and upload to npm registry #111
Comments
See here for npm hooks: https://docs.npmjs.com/cli/v10/using-npm/scripts For option 2, ChatGPT gives a hint: Creating a Custom npm Plugin for Secondary Package TarballTo create a solution that operates like a Maven plugin for npm, allowing the automatic generation and publishing of a secondary package tarball (with the Steps to Create a Custom npm Plugin for Your Use Case
Example ImplementationStep 1: Create the Plugin Package
Step 2: Implement the HookIn your const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const tar = require('tar');
// Function to create and publish the reqstool package
const createAndPublishReqstoolPackage = () => {
const packageJson = require(path.resolve(process.cwd(), 'package.json'));
const packageName = packageJson.name;
const version = packageJson.version;
// Define the reqstool package name
const reqstoolPackageName = \`\${packageName}-reqstool\`;
const reqstoolOutputFile = \`\${reqstoolPackageName}-\${version}.tgz\`;
const reqstoolDir = path.join(process.cwd(), 'dist'); // Change to your actual path where reqstool.zip is located
console.log(\`Creating \${reqstoolOutputFile}...\`);
// Ensure reqstool.zip exists
if (!fs.existsSync(path.join(reqstoolDir, 'reqstool.zip'))) {
console.error('Error: reqstool.zip not found in dist directory.');
process.exit(1);
}
// Create the tarball
tar.create(
{
gzip: true,
file: reqstoolOutputFile,
cwd: reqstoolDir,
},
['reqstool.zip']
);
console.log(\`Successfully created \${reqstoolOutputFile}\`);
// Publish the secondary package
execSync(\`npm publish \${reqstoolOutputFile}\`, { stdio: 'inherit' });
};
// Hook into the prepublish lifecycle
module.exports = {
hooks: {
prepublishOnly: createAndPublishReqstoolPackage,
},
}; Step 3: Publish the Plugin
Step 4: Configure the Main ProjectIn your main project, specify the plugin as a dependency in your {
"dependencies": {
"npm-reqstool-plugin": "^1.0.0"
}
} How It Works
Considerations
SummaryThis approach provides a clean and reusable way to automate the generation and publishing of a secondary package tarball within the npm ecosystem, similar to how Maven plugins work. It keeps the implementation within a dependency, ensuring ease of use and integration in different projects. |
@lfvdavid Reminder for us to update the requirements.yml with support of pypi locations. |
In addition to providing decorators for Typescript and creating the file
annotations.yml
the Typescript (npm) ecosystem also needs to create a package similar to Maven Artifact Zip Directory Structure but for npm repositories.The file structure is laid out in the documentation, but it has to be investigated on how this can be adapted to npm.
Potential options are (option 2 is the way we do with Java/Maven and seems a lot easier to implement):
Option 1. Include the Zip Archive Inside the npm Package
Here the ideal would be for a reqstool.zip to be included in the npm package but excluded from being placed in node_modules during
npm nstall
. Whether this can be done is unclear to me as of now and something that has to be tested.Can you for example use: and npm install will only install files under dist?
Option 2. Publish as a Separate npm Package (i.e. your-package-reqstool)
The text was updated successfully, but these errors were encountered: