Skip to content

Commit

Permalink
New: add initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed Nov 30, 2023
1 parent 1e579dc commit b1dfdc8
Show file tree
Hide file tree
Showing 77 changed files with 16,080 additions and 8,487 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
!.dangerfile.js
!.dangerfile.js
tests/bundles
2 changes: 1 addition & 1 deletion .fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
cli:
server: https://app.fossa.com
fetcher: custom
project: npm-boilerplate
project: semantic-release-bundle
analyze:
modules:
- name: .
Expand Down
2 changes: 1 addition & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"lines": 95,
"statements": 90,
"functions": 90,
"branches": 85,
"branches": 80,
"check-coverage": true
}
1 change: 1 addition & 0 deletions .package-tester.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"dir": "tmp/package-tests",
"copy": [[ "tests/bundles", "tests/bundles" ]],
"copyDefaultFiles": true
}
122 changes: 89 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# npm-boilerplate
Boilerplate for creating npm packages.
# semantic-release-bundle
A package designed to replace package versions in JavaScript bundles.

[![Version][badge-vers]][npm]
[![Bundle size][npm-size-badge]][npm-size-url]
Expand All @@ -22,13 +22,21 @@ Boilerplate for creating npm packages.


## Table of Contents
- [npm-boilerplate](#npm-boilerplate)
- [semantic-release-bundle](#semantic-release-bundle)
- [Table of Contents](#table-of-contents)
- [Motivation](#motivation)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Preconditions](#preconditions)
- [How it works](#how-it-works)
- [Contribute](#contribute)

## Motivation

Sometimes, using a universal [semantic-release][sr-url] plugin like `@google/semantic-release-replace-plugin` or `@semantic-release/exec` suffices to update versions in arbitrary files. However, for UI bundles, this task becomes challenging. This package provides strategies for comfortable version management, specifically tailored to JS bundles.

## Requirements
[![Platform Status][node-ver-test-badge]][node-ver-test-url]

Expand All @@ -44,57 +52,105 @@ Package is [continuously tested][node-ver-test-url] on darwin, linux and win32 p
To install the library run the following command

```bash
npm i --save npm-boilerplate
npm i --save-dev semantic-release-bundle
```

## Usage

```javascript

Configure the plugin in the semantic-release [configuration file][sr-config]:

```json
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"semantic-release-bundle",
{
"type": "q-manifest"
}
]
]
}
```

### Configuration

Customizable options include:
* `type`: Strategy to use, currently only supports 'q-manifest'
* `packageJSONPath`: Specify the path to the package.json file (default is 'package.json')
* `directory`: Bundle directory (default is 'dist')
* `updatePackageJSON`: Update version in package.json file

Strategy-related options:
* `buildDirectory`: For 'q-manifest', specifies the build directory ('build' by default)

### Preconditions

Before using the package, ensure the following assumptions work for your project:

1. package.json stores the old (unchanged) version during the verifyconditions step.
2. Bundle (with the unchanged version) is already generated at the moment of the verifyconditions step.
3. Version change should occur during the prepare step.

## How it works

The package scans the bundle for the previous version, which is obtained from package.json. It then replaces all occurrences of the matched pattern with the new version.
q-manifest

**q-manifest** is a strategy suitable for bundles generated by the [qwik framework][qwik]. Look for a sample in [tests/bundles/tastoria][bundle-sample] folder. semantic-release-bundle only modifies parts that import the package.json file because it observes the q-manifest file.

If you use [Vite][vite]/[Rollup][rollup] for bundle generation but not the qwik framework, you can generate a similar q-manifest.json file and utilize this strategy.

[sr-url]: https://github.com/semantic-release/semantic-release
[sr-config]: https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration
[bundle-sample]: ./tests/bundles/tastoria_1.2.1
[qwik]: https://qwik.builder.io/
[vite]: https://vitejs.dev/
[rollup]: https://rollupjs.org/

## Contribute

Make the changes to the code and tests. Then commit to your branch. Be sure to follow the commit message conventions. Read [Contributing Guidelines](.github/CONTRIBUTING.md) for details.

[npm]: https://www.npmjs.com/package/npm-boilerplate
[github]: https://github.com/pustovitDmytro/npm-boilerplate
[coveralls]: https://coveralls.io/github/pustovitDmytro/npm-boilerplate?branch=master
[badge-deps]: https://img.shields.io/librariesio/release/npm/npm-boilerplate.svg
[badge-vers]: https://img.shields.io/npm/v/npm-boilerplate.svg
[badge-lic]: https://img.shields.io/github/license/pustovitDmytro/npm-boilerplate.svg
[badge-coverage]: https://coveralls.io/repos/github/pustovitDmytro/npm-boilerplate/badge.svg?branch=master
[url-coverage]: https://coveralls.io/github/pustovitDmytro/npm-boilerplate?branch=master
[npm]: https://www.npmjs.com/package/semantic-release-bundle
[github]: https://github.com/pustovitDmytro/semantic-release-bundle
[coveralls]: https://coveralls.io/github/pustovitDmytro/semantic-release-bundle?branch=master
[badge-deps]: https://img.shields.io/librariesio/release/npm/semantic-release-bundle.svg
[badge-vers]: https://img.shields.io/npm/v/semantic-release-bundle.svg
[badge-lic]: https://img.shields.io/github/license/pustovitDmytro/semantic-release-bundle.svg
[badge-coverage]: https://coveralls.io/repos/github/pustovitDmytro/semantic-release-bundle/badge.svg?branch=master
[url-coverage]: https://coveralls.io/github/pustovitDmytro/semantic-release-bundle?branch=master

[snyk-badge]: https://snyk-widget.herokuapp.com/badge/npm/npm-boilerplate/badge.svg
[snyk-url]: https://snyk.io/advisor/npm-package/npm-boilerplate
[snyk-badge]: https://snyk-widget.herokuapp.com/badge/npm/semantic-release-bundle/badge.svg
[snyk-url]: https://snyk.io/advisor/npm-package/semantic-release-bundle

[tests-badge]: https://img.shields.io/circleci/build/github/pustovitDmytro/npm-boilerplate
[tests-url]: https://app.circleci.com/pipelines/github/pustovitDmytro/npm-boilerplate
[tests-badge]: https://img.shields.io/circleci/build/github/pustovitDmytro/semantic-release-bundle
[tests-url]: https://app.circleci.com/pipelines/github/pustovitDmytro/semantic-release-bundle

[codefactor-badge]: https://www.codefactor.io/repository/github/pustovitdmytro/npm-boilerplate/badge
[codefactor-url]: https://www.codefactor.io/repository/github/pustovitdmytro/npm-boilerplate
[codefactor-badge]: https://www.codefactor.io/repository/github/pustovitdmytro/semantic-release-bundle/badge
[codefactor-url]: https://www.codefactor.io/repository/github/pustovitdmytro/semantic-release-bundle

[commit-activity-badge]: https://img.shields.io/github/commit-activity/m/pustovitDmytro/npm-boilerplate
[commit-activity-badge]: https://img.shields.io/github/commit-activity/m/pustovitDmytro/semantic-release-bundle

[scrutinizer-badge]: https://scrutinizer-ci.com/g/pustovitDmytro/npm-boilerplate/badges/quality-score.png?b=master
[scrutinizer-url]: https://scrutinizer-ci.com/g/pustovitDmytro/npm-boilerplate/?branch=master
[scrutinizer-badge]: https://scrutinizer-ci.com/g/pustovitDmytro/semantic-release-bundle/badges/quality-score.png?b=master
[scrutinizer-url]: https://scrutinizer-ci.com/g/pustovitDmytro/semantic-release-bundle/?branch=master

[codacy-badge]: https://app.codacy.com/project/badge/Grade/8667aa23afaa4725854f098c4b5e8890
[codacy-url]: https://www.codacy.com/gh/pustovitDmytro/npm-boilerplate/dashboard?utm_source=github.com&utm_medium=referral&utm_content=pustovitDmytro/npm-boilerplate&utm_campaign=Badge_Grade
[codacy-url]: https://www.codacy.com/gh/pustovitDmytro/semantic-release-bundle/dashboard?utm_source=github.com&utm_medium=referral&utm_content=pustovitDmytro/semantic-release-bundle&utm_campaign=Badge_Grade

[sonarcloud-badge]: https://sonarcloud.io/api/project_badges/measure?project=pustovitDmytro_npm-boilerplate&metric=alert_status
[sonarcloud-url]: https://sonarcloud.io/dashboard?id=pustovitDmytro_npm-boilerplate
[sonarcloud-badge]: https://sonarcloud.io/api/project_badges/measure?project=pustovitDmytro_semantic-release-bundle&metric=alert_status
[sonarcloud-url]: https://sonarcloud.io/dashboard?id=pustovitDmytro_semantic-release-bundle

[npm-downloads-badge]: https://img.shields.io/npm/dw/npm-boilerplate
[npm-size-badge]: https://img.shields.io/bundlephobia/min/npm-boilerplate
[npm-size-url]: https://bundlephobia.com/result?p=npm-boilerplate
[npm-downloads-badge]: https://img.shields.io/npm/dw/semantic-release-bundle
[npm-size-badge]: https://img.shields.io/bundlephobia/min/semantic-release-bundle
[npm-size-url]: https://bundlephobia.com/result?p=semantic-release-bundle

[node-ver-test-badge]: https://github.com/pustovitDmytro/npm-boilerplate/actions/workflows/npt.yml/badge.svg?branch=master
[node-ver-test-url]: https://github.com/pustovitDmytro/npm-boilerplate/actions?query=workflow%3A%22Node.js+versions%22
[node-ver-test-badge]: https://github.com/pustovitDmytro/semantic-release-bundle/actions/workflows/npt.yml/badge.svg?branch=master
[node-ver-test-url]: https://github.com/pustovitDmytro/semantic-release-bundle/actions?query=workflow%3A%22Node.js+versions%22

[fossa-badge]: https://app.fossa.com/api/projects/custom%2B24828%2Fnpm-boilerplate.svg?type=shield
[fossa-url]: https://app.fossa.com/projects/custom%2B24828%2Fnpm-boilerplate?ref=badge_shield
[fossa-badge]: https://app.fossa.com/api/projects/custom%2B24828%2Fsemantic-release-bundle.svg?type=shield
[fossa-url]: https://app.fossa.com/projects/custom%2B24828%2Fsemantic-release-bundle?ref=badge_shield

[ukr-badge]: https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7
[ukr-link]: https://war.ukraine.ua
68 changes: 68 additions & 0 deletions bin/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!./node_modules/.bin/babel-node
/* eslint-disable import/no-extraneous-dependencies */

import path from 'path';
import { docopt } from 'docopt';
import verifyConditions from '../src/verifyConditions';

const doc =
`Usage:
test.js success --chats=<chats> [<rootDir>]
test.js fail --chats=<chats> [<rootDir>]
test.js verifyConditions [<rootDir>]
test.js -h | --help
Options:
-h --help Run test with real credentials.
`;

const testBundles = path.resolve('tests/bundles');
const tastoriaDist = path.resolve(testBundles, 'tastoria_1.2.1/dist');
const tastoriaPackage = path.resolve(testBundles, 'tastoria_1.2.1/package.json');

const options = {
repositoryUrl : 'https://github.com/pustovitDmytro/semantic-release-telegram.git',
'telegra.ph' : {
title : '{name} v.{version}',
message : '<a href=\'{telegraph_url}\'>Release Notes</a>',
content : '{release_notes}'
},
assets : [
{ path: 'README.md' },
{ glob: [ '.docs/*' ], name: 'Docs.zip' }
]
};
const branch = { name: 'master' };

async function main(opts) {
try {
const rootDir = opts['<rootDir>'] || process.cwd();

if (opts.verifyConditions) {
await verifyConditions.call(
{},
{
type : 'q-manifest',
directory : tastoriaDist,
'package.json' : tastoriaPackage
},
{
logger : console,
env : { ...process.env },
cwd : path.resolve(rootDir),
options,
branch
}
);
}

process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
}


// eslint-disable-next-line unicorn/prefer-top-level-await
main(docopt(doc));

0 comments on commit b1dfdc8

Please sign in to comment.