@thisismanta/semantic-version 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const execa_1 = require("execa");
4
4
  const index_1 = require("./index");
5
+ const debug_1 = require("./debug");
5
6
  main();
6
7
  async function main() {
7
8
  const message = await run('git log -1 HEAD --format=%s');
8
- console.log('message »', message);
9
- const { type, breaking } = (0, index_1.checkConventionalMessage)(message, console);
9
+ (0, debug_1.debug)('message »', JSON.stringify(message));
10
+ const { type, breaking } = (0, index_1.checkConventionalMessage)(message, { debug: debug_1.debug });
10
11
  const releaseType = (() => {
11
12
  if (breaking) {
12
13
  return 'major';
@@ -18,18 +19,18 @@ async function main() {
18
19
  return 'patch';
19
20
  }
20
21
  // Indicate no version bump
21
- return '';
22
+ return null;
22
23
  })();
23
- console.log('releaseType »', releaseType);
24
+ (0, debug_1.debug)('releaseType »', JSON.stringify(releaseType));
24
25
  if (!releaseType) {
26
+ console.log('semantic-version: no version bump.');
25
27
  return;
26
28
  }
29
+ console.log(`semantic-version: creating ${releaseType} version.`);
27
30
  const newVersion = await run(`npm version --json --no-commit-hooks ${releaseType}`);
28
31
  await run(`git push origin refs/tags/${newVersion}`);
29
32
  }
30
33
  async function run(command) {
31
- console.log(command);
32
34
  const { stdout } = await (0, execa_1.execaCommand)(command);
33
- console.log(stdout);
34
35
  return stdout;
35
36
  }
package/lib/debug.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function debug(...args: Array<any>): void;
package/lib/debug.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.debug = void 0;
7
+ const yn_1 = __importDefault(require("yn"));
8
+ function debug(...args) {
9
+ if ((0, yn_1.default)(process.env.DEBUG)) {
10
+ console.log(...args);
11
+ }
12
+ }
13
+ exports.debug = debug;
package/lib/index.js CHANGED
@@ -5,8 +5,11 @@ const titlePattern = /^(?<type>\w+)(?<scope>\(.*?\))?(?<breaking>\!)?:(?<subject
5
5
  exports.allowedTypes = ['feat', 'fix', 'test', 'refactor', 'chore'];
6
6
  function checkConventionalMessage(message, { debug }) {
7
7
  const pattern = (message.match(titlePattern)?.groups || {});
8
- debug(JSON.stringify(pattern, null, 2));
9
8
  const { type, scope, breaking, subject } = pattern;
9
+ debug('type »', type);
10
+ debug('scope »', scope);
11
+ debug('breaking »', breaking);
12
+ debug('subject »', subject);
10
13
  const errors = [
11
14
  !type &&
12
15
  'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/',
@@ -26,26 +26,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const fs = __importStar(require("fs/promises"));
27
27
  const fp = __importStar(require("path"));
28
28
  const execa_1 = require("execa");
29
+ const debug_1 = require("./debug");
29
30
  main();
31
+ const packageName = require('../package.json').name;
30
32
  async function main() {
31
33
  const currentDirectoryPath = process.cwd();
32
- console.debug('currentDirectoryPath »', currentDirectoryPath);
34
+ (0, debug_1.debug)('currentDirectoryPath »', currentDirectoryPath);
33
35
  const gitDirectoryPath = await findGitDirectoryPath(currentDirectoryPath);
34
- console.debug('gitDirectoryPath »', gitDirectoryPath);
36
+ (0, debug_1.debug)('gitDirectoryPath »', gitDirectoryPath);
35
37
  if (!gitDirectoryPath) {
36
38
  throw new Error('Could not find a Git directory.');
37
39
  }
38
40
  const packageJSON = JSON.parse(await fs.readFile(fp.join(gitDirectoryPath, 'package.json'), 'utf-8'));
39
- if (packageJSON.name === '@thisismanta/semantic-version') {
41
+ if (packageJSON.name === packageName) {
40
42
  console.warn('Skip installing Git hooks as it is supposed to be done on a consumer repository.');
41
43
  return;
42
44
  }
43
45
  console.log('Installing Husky');
44
46
  await (0, execa_1.execaCommand)('npx husky install', { cwd: gitDirectoryPath });
45
- // Up 3 levels because of `node_modules/@thisismanta/semantic-version`
46
- const huskyDirectoryPath = fp.resolve(currentDirectoryPath, '../../..', '.husky');
47
+ const huskyDirectoryPath = fp.resolve(gitDirectoryPath, '.husky');
48
+ (0, debug_1.debug)('huskyDirectoryPath »', huskyDirectoryPath);
47
49
  await fs.access(huskyDirectoryPath);
48
- console.log('Found', huskyDirectoryPath);
49
50
  await upsert(fp.join(huskyDirectoryPath, 'commit-msg'), 'npx lint-commit-message ${1}');
50
51
  await upsert(fp.join(huskyDirectoryPath, 'post-commit'), 'npx auto-npm-version');
51
52
  console.log('Done adding Git hooks.');
@@ -71,11 +72,12 @@ async function findGitDirectoryPath(path) {
71
72
  async function upsert(filePath, text) {
72
73
  try {
73
74
  await fs.access(filePath);
75
+ console.log('Found', filePath);
74
76
  }
75
77
  catch (error) {
76
- console.log('Created', filePath);
77
78
  await fs.writeFile(filePath, '#!/usr/bin/env sh' + '\n' +
78
79
  '. "$(dirname -- "$0")/_/husky.sh"' + '\n', 'utf-8');
80
+ console.log('Created', filePath);
79
81
  }
80
82
  const fileText = await fs.readFile(filePath, 'utf-8');
81
83
  const lines = fileText.trim().split('\n');
@@ -25,12 +25,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const fs = __importStar(require("fs/promises"));
27
27
  const index_1 = require("./index");
28
+ const debug_1 = require("./debug");
28
29
  main();
29
30
  async function main() {
30
31
  const [messageFilePath] = process.argv.slice(2);
32
+ (0, debug_1.debug)('messageFilePath »', messageFilePath);
31
33
  const message = (await fs.readFile(messageFilePath, 'utf-8')).trim();
32
- const { errors } = (0, index_1.checkConventionalMessage)(message, console);
34
+ (0, debug_1.debug)('message »', message);
35
+ const { errors } = (0, index_1.checkConventionalMessage)(message, { debug: debug_1.debug });
33
36
  if (errors.length > 0) {
34
- throw new Error(errors[0]);
37
+ for (const error of errors) {
38
+ console.error(error);
39
+ }
40
+ process.exit(1);
35
41
  }
36
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisismanta/semantic-version",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "author": "Anantachai Saothong <thisismanta@gmail.com>",
5
5
  "license": "ISC",
6
6
  "engines": {
@@ -29,7 +29,8 @@
29
29
  "@types/node": "^16.0.0",
30
30
  "jest": "^29.4.3",
31
31
  "ts-jest": "^29.0.5",
32
- "typescript": "^4.9.5"
32
+ "typescript": "^4.9.5",
33
+ "yn": "^5.0.0"
33
34
  },
34
35
  "dependencies": {
35
36
  "execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",