@storm-software/git-tools 2.125.5 → 2.127.0

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.
package/bin/git.js CHANGED
@@ -26,16 +26,17 @@ import chalkTemplate from 'chalk-template';
26
26
  import fs, { readFile as readFile$1, writeFile } from 'node:fs/promises';
27
27
  import createBasePreset from 'conventional-changelog-conventionalcommits';
28
28
  import { readCachedProjectGraph, createProjectGraphAsync as createProjectGraphAsync$1, readProjectsConfigurationFromProjectGraph as readProjectsConfigurationFromProjectGraph$1 } from 'nx/src/project-graph/project-graph';
29
- import { existsSync } from 'fs';
29
+ import { existsSync as existsSync$1 } from 'fs';
30
30
  import { readFile } from 'fs/promises';
31
31
  import childProcess, { execSync } from 'node:child_process';
32
32
  import defaultRules from '@commitlint/rules';
33
33
  import 'stream';
34
34
  import util from 'node:util';
35
- import { existsSync as existsSync$1, rmSync, readdirSync, readFileSync, writeFileSync, statSync, promises } from 'node:fs';
35
+ import { existsSync, readFileSync, rmSync, readdirSync, writeFileSync, statSync, promises } from 'node:fs';
36
36
  import wrap from 'word-wrap';
37
37
  import Path, { join as join$1, extname } from 'node:path';
38
38
  import { createProjectGraphAsync, readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph.js';
39
+ import { resolveConfig, format } from 'prettier';
39
40
  import { parse as parse$1, Syntax } from '@textlint/markdown-to-ast';
40
41
  import anchor from 'anchor-markdown-header';
41
42
  import { Parser } from 'htmlparser2';
@@ -50,7 +51,6 @@ import chalk from 'chalk';
50
51
  import { printAndFlushChanges } from 'nx/src/command-line/release/utils/print-changes';
51
52
  import { createGitTagValues, handleDuplicateGitTags, createCommitMessageValues, isPrerelease, shouldPreferDockerVersionForReleaseGroup, ReleaseVersion, noDiffInChangelogMessage } from 'nx/src/command-line/release/utils/shared';
52
53
  import { interpolate } from 'nx/src/tasks-runner/utils';
53
- import { resolveConfig, format } from 'prettier';
54
54
  import { execCommand } from 'nx/src/command-line/release/utils/exec-command.js';
55
55
  import { getCommitHash, getLatestGitTagForPattern, getFirstGitCommit, gitPush, getGitDiff, parseCommits, gitAdd } from 'nx/src/command-line/release/utils/git';
56
56
  import { prerelease, major } from 'semver';
@@ -979,7 +979,7 @@ async function runCommitLint(workspaceConfig, options) {
979
979
  workspaceConfig.workspaceRoot,
980
980
  options.file || options.message || COMMIT_EDITMSG_PATH
981
981
  );
982
- if (existsSync(commitFile)) {
982
+ if (existsSync$1(commitFile)) {
983
983
  commitMessage = (await readFile(commitFile, "utf8"))?.trim();
984
984
  }
985
985
  }
@@ -1233,7 +1233,7 @@ async function createState(workspaceConfig, configPath) {
1233
1233
  if (project) {
1234
1234
  let description = `${project.name} - ${project.root}`;
1235
1235
  const packageJsonPath = joinPaths(project.root, "package.json");
1236
- if (existsSync$1(packageJsonPath)) {
1236
+ if (existsSync(packageJsonPath)) {
1237
1237
  const packageJsonFile = await readFile$1(packageJsonPath, "utf8");
1238
1238
  const packageJson = JSON.parse(packageJsonFile);
1239
1239
  description = packageJson.description || description;
@@ -1278,11 +1278,11 @@ var formatCommitMessage = (state, workspaceConfig) => {
1278
1278
  const scope = workspaceConfig.variant !== "minimal" && typeof answers.scope === "string" && answers.scope ? answers.scope.trim() : "";
1279
1279
  const subject = answers.subject?.trim();
1280
1280
  const type = answers.type;
1281
- const format2 = config5.settings.format || (workspaceConfig.variant !== "minimal" ? "{type}({scope}): {emoji}{subject}" : "{type}: {emoji}{subject}");
1281
+ const format3 = config5.settings.format || (workspaceConfig.variant !== "minimal" ? "{type}({scope}): {emoji}{subject}" : "{type}: {emoji}{subject}");
1282
1282
  const body = answers.body && typeof answers.body === "string" ? wrap(answers.body || "", wrapOptions) : "";
1283
1283
  const breaking = answers.breakingBody && typeof answers.breakingBody === "string" ? wrap(answers.breakingBody || "", wrapOptions) : "";
1284
1284
  const issues = answers.issuesBody && typeof answers.issuesBody === "string" ? wrap(answers.issuesBody || "", wrapOptions) : "";
1285
- const head = format2.replace(/\{emoji\}/g, config5.settings.disableEmoji ? "" : `${emoji} `).replace(/\{scope\}/g, scope).replace(/\{subject\}/g, subject || "").replace(/\{type\}/g, type || "");
1285
+ const head = format3.replace(/\{emoji\}/g, config5.settings.disableEmoji ? "" : `${emoji} `).replace(/\{scope\}/g, scope).replace(/\{subject\}/g, subject || "").replace(/\{type\}/g, type || "");
1286
1286
  let msg = head;
1287
1287
  if (body) {
1288
1288
  msg += `
@@ -1595,45 +1595,53 @@ async function transformAndSave(files, mode = "github.com", maxHeaderLevel = 3,
1595
1595
  "--update-only flag is enabled. Only updating files that already have a TOC."
1596
1596
  );
1597
1597
  }
1598
- console.log("\n==================\n");
1599
- const transformed = files.map((x) => {
1600
- const result = transform(
1601
- readFileSync(x.path, "utf8"),
1602
- mode,
1603
- maxHeaderLevel,
1604
- title,
1605
- noTitle,
1606
- entryPrefix,
1607
- processAll,
1608
- updateOnly
1609
- );
1610
- result.path = x.path;
1611
- return result;
1612
- });
1613
- const changed = transformed.filter((x) => x.transformed);
1614
- const unchanged = transformed.filter((x) => {
1615
- return !x.transformed;
1616
- });
1617
- for (const x of unchanged) {
1618
- console.log('"%s" is up to date', x.path);
1619
- }
1620
- for (const x of changed) {
1621
- console.log('"%s" will be updated', x.path);
1622
- writeFileSync(x.path, x.data, "utf8");
1623
- }
1598
+ return Promise.all(
1599
+ files.map((x) => {
1600
+ const result = transform(
1601
+ readFileSync(x.path, "utf8"),
1602
+ mode,
1603
+ maxHeaderLevel,
1604
+ title,
1605
+ noTitle,
1606
+ entryPrefix,
1607
+ processAll,
1608
+ updateOnly
1609
+ );
1610
+ result.path = x.path;
1611
+ return result;
1612
+ }).filter((file) => file.transformed).map(async (file) => {
1613
+ console.log('Writting changes to "%s"', file.path);
1614
+ const prettierConfig = await resolveConfig(file.path, {
1615
+ useCache: true,
1616
+ editorconfig: true
1617
+ });
1618
+ return writeFile(
1619
+ file.path,
1620
+ await format(
1621
+ file.data,
1622
+ prettierConfig ? { ...prettierConfig, parser: "markdown" } : { parser: "markdown" }
1623
+ ),
1624
+ "utf8"
1625
+ );
1626
+ })
1627
+ );
1624
1628
  }
1625
1629
  var doctoc = (directory, mode = "github.com", maxHeaderLevel = 3, title = "## Table of Contents", noTitle = false, entryPrefix = void 0, processAll = false, updateOnly = false) => {
1626
1630
  let files = [];
1627
1631
  const stat = statSync(directory);
1628
1632
  if (stat.isDirectory()) {
1629
1633
  console.log(
1630
- '\nDocToccing "%s" and its sub directories for %s.',
1634
+ '\nCreating Table of Contents for "%s" and its sub directories for %s.',
1631
1635
  directory,
1632
1636
  mode
1633
1637
  );
1634
1638
  files = findMarkdownFiles(directory);
1635
1639
  } else {
1636
- console.log('\nDocToccing single file "%s" for %s.', directory, mode);
1640
+ console.log(
1641
+ '\nCreating Table of Contents for single file "%s" for %s.',
1642
+ directory,
1643
+ mode
1644
+ );
1637
1645
  files = [{ path: directory }];
1638
1646
  }
1639
1647
  transformAndSave(
@@ -1646,7 +1654,10 @@ var doctoc = (directory, mode = "github.com", maxHeaderLevel = 3, title = "## Ta
1646
1654
  processAll,
1647
1655
  updateOnly
1648
1656
  );
1649
- console.log("\nEverything is OK.");
1657
+ console.log(
1658
+ "\nCompleted generating Table of Contents for %s file(s).",
1659
+ files.length
1660
+ );
1650
1661
  };
1651
1662
  var markdownExts = [".md", ".markdown"];
1652
1663
  var ignoredDirs = [".", "..", ".git", "node_modules"];
@@ -1707,7 +1718,7 @@ var getExecutorMarkdown = (_packageName, executorsJsonFile, executorsJson) => {
1707
1718
  findFilePath(executorsJsonFile),
1708
1719
  executor.schema
1709
1720
  );
1710
- if (existsSync$1(schemaJsonPath)) {
1721
+ if (existsSync(schemaJsonPath)) {
1711
1722
  const schemaJson = JSON.parse(
1712
1723
  readFileSync(schemaJsonPath, "utf8") ?? "{}"
1713
1724
  );
@@ -1805,7 +1816,7 @@ var getGeneratorMarkdown = (packageName, generatorsJsonFile, generatorsJson) =>
1805
1816
  findFilePath(generatorsJsonFile),
1806
1817
  generator.schema
1807
1818
  );
1808
- if (existsSync$1(schemaJsonPath)) {
1819
+ if (existsSync(schemaJsonPath)) {
1809
1820
  const schemaJson = JSON.parse(
1810
1821
  readFileSync(schemaJsonPath, "utf8") ?? "{}"
1811
1822
  );
@@ -1977,14 +1988,38 @@ var runReadme = async ({
1977
1988
  project,
1978
1989
  output: output3,
1979
1990
  clean = true,
1980
- prettier = true
1991
+ prettier = true,
1992
+ workspace = false
1981
1993
  }) => {
1982
1994
  const projectGraph = await createProjectGraphAsync({
1983
1995
  exitOnError: true
1984
1996
  });
1985
1997
  const projectConfigs = readProjectsConfigurationFromProjectGraph(projectGraph);
1986
- if (project) {
1987
- await runProjectReadme(project, {
1998
+ const workspaceRoot = findWorkspaceRootSafe(process.cwd());
1999
+ if (!workspaceRoot) {
2000
+ throw new Error(
2001
+ "Unable to find the workspace root. Please ensure you are running this command from within a workspace."
2002
+ );
2003
+ }
2004
+ let resolvedProject = project;
2005
+ if (workspace) {
2006
+ if (!existsSync(join$1(workspaceRoot, "project.json"))) {
2007
+ throw new Error(
2008
+ `The \`workspace\` flag was provided to the \`storm-git readme\` command-line interface, but a project.json file could not be found at the workspace root (${workspaceRoot}). Please ensure you are running this command from the root of your workspace.`
2009
+ );
2010
+ }
2011
+ const projectJson = JSON.parse(
2012
+ readFileSync(join$1(workspaceRoot, "project.json"), "utf8") ?? "{}"
2013
+ );
2014
+ if (!projectJson?.name) {
2015
+ throw new Error(
2016
+ `The \`workspace\` flag was provided to the \`storm-git readme\` command-line interface, but a name field could not be found in the project.json file at the workspace root (${workspaceRoot}). Please ensure the project.json file at the workspace root contains a name field.`
2017
+ );
2018
+ }
2019
+ resolvedProject = projectJson.name;
2020
+ }
2021
+ if (resolvedProject) {
2022
+ await runProjectReadme(resolvedProject, {
1988
2023
  templates,
1989
2024
  output: output3,
1990
2025
  clean,
@@ -2008,10 +2043,10 @@ var runProjectReadme = async (projectName, { templates, output: output3, clean =
2008
2043
  const projectConfigs = readProjectsConfigurationFromProjectGraph(projectGraph);
2009
2044
  const project = projectConfigs.projects[projectName];
2010
2045
  const inputFile = join$1(project?.root ?? "./", "README.md");
2011
- if (existsSync$1(inputFile)) {
2046
+ if (existsSync(inputFile)) {
2012
2047
  console.info(`Formatting ${projectName}'s README file at "${inputFile}"`);
2013
2048
  const outputFilePath = output3 ? output3.includes("README.md") ? output3 : join$1(findFilePath(output3), "README.md") : inputFile;
2014
- if (clean && existsSync$1(outputFilePath)) {
2049
+ if (clean && existsSync(outputFilePath)) {
2015
2050
  if (outputFilePath === inputFile) {
2016
2051
  console.warn(
2017
2052
  "Skipping cleaning since output directory + file name is the same as input directory + file name."
@@ -2035,7 +2070,7 @@ var runProjectReadme = async (projectName, { templates, output: output3, clean =
2035
2070
  );
2036
2071
  let packageName = projectName;
2037
2072
  const packageJsonPath = join$1(findFilePath(inputFile), "package.json");
2038
- if (existsSync$1(packageJsonPath)) {
2073
+ if (existsSync(packageJsonPath)) {
2039
2074
  const packageJson = JSON.parse(
2040
2075
  readFileSync(packageJsonPath, "utf8") ?? "{}"
2041
2076
  );
@@ -2052,7 +2087,7 @@ var runProjectReadme = async (projectName, { templates, output: output3, clean =
2052
2087
  }
2053
2088
  if (newContent.includes("<!-- START executors -->")) {
2054
2089
  const executorsJsonPath = join$1(findFilePath(inputFile), "executors.json");
2055
- if (existsSync$1(executorsJsonPath)) {
2090
+ if (existsSync(executorsJsonPath)) {
2056
2091
  const executorsJson = JSON.parse(
2057
2092
  readFileSync(executorsJsonPath, "utf8") ?? "{}"
2058
2093
  );
@@ -2071,7 +2106,7 @@ var runProjectReadme = async (projectName, { templates, output: output3, clean =
2071
2106
  findFilePath(inputFile),
2072
2107
  "generators.json"
2073
2108
  );
2074
- if (existsSync$1(generatorsJsonPath)) {
2109
+ if (existsSync(generatorsJsonPath)) {
2075
2110
  const generatorsJson = JSON.parse(
2076
2111
  readFileSync(generatorsJsonPath, "utf8") ?? "{}"
2077
2112
  );
@@ -2563,7 +2598,7 @@ async function generateChangelogForProjects({
2563
2598
  "CHANGELOG.md"
2564
2599
  );
2565
2600
  let currentContent;
2566
- if (existsSync$1(filePath)) {
2601
+ if (existsSync(filePath)) {
2567
2602
  currentContent = await readFile$1(filePath, "utf8");
2568
2603
  }
2569
2604
  writeDebug(
@@ -2900,7 +2935,7 @@ async function resolveTokenData(hostname) {
2900
2935
  "gh",
2901
2936
  "hosts.yml"
2902
2937
  );
2903
- if (existsSync$1(ghCLIPath)) {
2938
+ if (existsSync(ghCLIPath)) {
2904
2939
  const yamlContents = await promises.readFile(ghCLIPath, "utf8");
2905
2940
  const ghCLIConfig = parse(yamlContents);
2906
2941
  if (ghCLIConfig[hostname]) {
@@ -3343,7 +3378,7 @@ var StormReleaseClient = class _StormReleaseClient extends ReleaseClient {
3343
3378
  */
3344
3379
  constructor(projectGraph, releaseConfig, ignoreNxJsonConfig, workspaceConfig) {
3345
3380
  let nxJson;
3346
- if (!ignoreNxJsonConfig && existsSync$1(joinPaths(workspaceConfig.workspaceRoot, "nx.json"))) {
3381
+ if (!ignoreNxJsonConfig && existsSync(joinPaths(workspaceConfig.workspaceRoot, "nx.json"))) {
3347
3382
  nxJson = readNxJson();
3348
3383
  }
3349
3384
  const config5 = defu(
@@ -3834,12 +3869,12 @@ async function updatePackageManifests(projectsVersionData, config5) {
3834
3869
  );
3835
3870
  const packageJsonPath = joinPaths(projectRoot, "package.json");
3836
3871
  const cargoTomlPath = joinPaths(projectRoot, "Cargo.toml");
3837
- if (existsSync$1(packageJsonPath)) {
3872
+ if (existsSync(packageJsonPath)) {
3838
3873
  const packageJsonContent = await readFile$1(packageJsonPath, "utf8");
3839
3874
  const packageJson = JSON.parse(packageJsonContent);
3840
3875
  packageJson.version = versionData.newVersion;
3841
3876
  await writeFile(packageJsonPath, JSON.stringify(packageJson));
3842
- } else if (existsSync$1(cargoTomlPath)) {
3877
+ } else if (existsSync(cargoTomlPath)) {
3843
3878
  const cargoToml = parseCargoToml(
3844
3879
  await readFile$1(cargoTomlPath, "utf8")
3845
3880
  );
@@ -3878,8 +3913,8 @@ function createProgram(config5) {
3878
3913
  "./tools/readme-templates"
3879
3914
  ).option(
3880
3915
  "--project <project>",
3881
- "The specific project to generate a README.md file for"
3882
- ).option("--output <path>", "Where to output the generated README.md file").option(
3916
+ "The specific project to generate a README.md file for. Defaults to the workspace root README.md if not provided."
3917
+ ).option("--workspace", "Run for the workspace root's README.md file").option("--output <path>", "Where to output the generated README.md file").option(
3883
3918
  "--clean",
3884
3919
  "Should the output README.md file be cleaned before generation",
3885
3920
  true