<commit_before>const {buildApi} = require("@typedproject/ts-doc");
const execa = require("execa");
const path = require("path");
const fs = require("fs");
const sourcemaps = require("gulp-sourcemaps");
const gulp = require("gulp");
const clean = require("gulp-clean");
const ts = require("gulp-typescript");
const gflow = require("gflow");

const {tsdoc, packagesDir} = require("../../repo.config");
const {branch} = require("../../release.config");

/**
 *
 * @param stream
 * @returns {Promise<any>}
 */
const toPromise = stream =>
  new Promise((resolve, reject) =>
    stream
      .on("end", resolve)
      .on("finish", resolve)
      .on("error", reject)
  );

module.exports = {
  async clean(g = gulp) {
    const stream = g.src(path.join(process.cwd(), "docs", "api"), {read: false, allowEmpty: true}).pipe(clean());

    return toPromise(stream);
  },

  async buildApi() {
    await module.exports.compile();
    await module.exports.clean();
    await buildApi(tsdoc);
  },

  async build() {
    await module.exports.buildApi();
    await execa("vuepress", ["build", "docs"], {stdio: "inherit"});
  },

  async compile() {
    const tsProject = ts.createProject("./tsconfig.compile.json", {
      "declaration": true,
      "noResolve": false,
      "preserveConstEnums": true
    });

    const stream = tsProject.src()
      .pipe(sourcemaps.init())
      .pipe(tsProject())
      .once("error", function() {
        this.once("finish", () => {
          throw new Error("fails with errors");
        });
      })
      .pipe(sourcemaps.write(".", {sourceRoot: "./"}))
      .pipe(gulp.dest(packagesDir));

    return toPromise(stream);
  },

  async serve() {
    await module.exports.buildApi();
    await execa("vuepress", ["dev", "docs"], {stdio: "inherit"});
  },

  async publish() {
    const currentBranch = gflow.git.currentBranchName();

    if (currentBranch !== branch) {
      console.log(
        `This test run was triggered on the branch ${currentBranch}, while docs is configured to only publish from ${
          branch
          }, therefore a new docs version won’t be published.`
      );
      return;
    }

    const pkg = JSON.parse(fs.readFileSync("./package.json", {encoding: "utf8"}));<commit_msg>docs: Update pipeline documentation<commit_after>const {buildApi} = require("@typedproject/ts-doc");
const execa = require("execa");
const path = require("path");
const fs = require("fs");
const sourcemaps = require("gulp-sourcemaps");
const gulp = require("gulp");
const clean = require("gulp-clean");
const ts = require("gulp-typescript");
const gflow = require("gflow");

const {tsdoc, packagesDir} = require("../../repo.config");
const {branch} = require("../../release.config");

/**
 *
 * @param stream
 * @returns {Promise<any>}
 */
const toPromise = stream =>
  new Promise((resolve, reject) =>
    stream
      .on("end", resolve)
      .on("finish", resolve)
      .on("error", reject)
  );

module.exports = {
  async clean(g = gulp) {
    const stream = g.src(path.join(process.cwd(), "docs", "api"), {read: false, allowEmpty: true}).pipe(clean());

    return toPromise(stream);
  },

  async buildApi() {
    await module.exports.compile();
    await module.exports.clean();
    await buildApi(tsdoc);
  },

  async build() {
    await module.exports.buildApi();
    await execa("vuepress", ["build", "docs"], {stdio: "inherit"});
  },

  async compile() {
    const tsProject = ts.createProject("./tsconfig.compile.json", {
      "declaration": true,
      "noResolve": false,
      "preserveConstEnums": true
    });

    const stream = tsProject.src()
      .pipe(sourcemaps.init())
      .pipe(tsProject())
      .once("error", function() {
        this.once("finish", () => {
          throw new Error("fails with errors");
        });
      })
      .pipe(sourcemaps.write(".", {sourceRoot: "./"}))
      .pipe(gulp.dest(packagesDir));

    return toPromise(stream);
  },

  async serve() {
    await module.exports.buildApi();
    await execa("vuepress", ["dev", "docs"], {stdio: "inherit"});
  },

  async publish() {
    const currentBranch = process.env.BRANCH;

    if (currentBranch !== branch) {
      console.log(
        `This test run was triggered on the branch ${currentBranch}, while docs is configured to only publish from ${
          branch
          }, therefore a new docs version won’t be published.`
      );
      return;
    }

    const pkg = JSON.parse(fs.readFileSync("./package.json", {encoding: "utf8"}));
{'fraction_non_alphanumeric': 0.1809481415535277, 'fraction_numerical': 0.0004451368795904741, 'mean_word_length': 3.1457564575645756, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1633949', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1372, 'n_words': 330}