<commit_before>const del = require('del');
const { execSync } = require('child_process');
const osenv = require('osenv');
const path = require('path');

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const threshold = require('gulp-eslint-threshold');
const jsonEditor = require('gulp-json-editor');
const shell = require('gulp-shell');
const zip = require('gulp-zip');

const metadata = require('./src/metadata.json');

const paths = {
  src: [
    'src/**/*',
    '!src/**/*~',
    '!src/schemas{,/**/*}',
    '!src/metadata.json',
    '!src/.eslintrc',
  ],
  lib: ['lib/**/*'],
  metadata: ['src/metadata.json'],
  schemas: ['src/schemas/**/*'],
  install: path.join(
    osenv.home(),
    '.local/share/gnome-shell/extensions',
    metadata.uuid,
  ),
};

function getVersion(rawTag) {
  const sha1 = execSync('git rev-parse --short HEAD').toString().replace(/\n$/, '');
  let tag;
  try {
    tag = execSync(`git describe --tags --exact-match ${sha1} 2>/dev/null`).toString().replace(/\n$/, '');
  } catch (e) {
    return sha1;
  }

  if (rawTag) {
    return tag;
  }

  const v = parseInt(tag.replace(/^v/, ''), 10);
  if (Number.isNaN(v)) {
    throw new Error(`Unable to parse version from tag: ${tag}`);
  }
  return v;
}

gulp.task('lint', () => {
  const thresholdWarnings = 1;
  const thresholdErrors = 1;
  return gulp.src(['**/*.js'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(threshold.afterErrors(thresholdErrors, (numberOfErrors) => {
      throw new Error(`ESLint errors (${numberOfErrors}) equal to or greater than the threshold (${thresholdErrors})`);
    }))
    .pipe(threshold.afterWarnings(thresholdWarnings, (numberOfWarnings) => {
      throw new Error(`ESLint warnings (${numberOfWarnings}) equal to or greater than the threshold (${thresholdWarnings})`);
    }));
});

gulp.task('clean', cb => del(['build/'], cb));

gulp.task('copy', () => gulp.src(paths.src).pipe(gulp.dest('build')));

gulp.task('copy-lib', () => gulp.src(paths.lib).pipe(gulp.dest('build/lib')));

gulp.task('copy-license', () => gulp.src(['LICENSE']).pipe(gulp.dest('build')));

gulp.task('metadata', () => gulp.src(paths.metadata).pipe(jsonEditor(json => Object.assign(json, { version: getVersion() }), { end_with_newline: true })).pipe(gulp.dest('build')));

gulp.task('schemas', shell.task([
  'mkdir -p build/schemas',
  'glib-compile-schemas --strict --targetdir build/schemas src/schemas/',
]));

gulp.task('build', gulp.series('clean', gulp.parallel(
  'metadata',
  'schemas',
  'copy',
  'copy-lib',
  'copy-license',
)));

gulp.task('watch', gulp.series('build', () => {
  gulp.watch(paths.src, gulp.series('copy'));
  gulp.watch(paths.lib, gulp.series('copy-lib'));
  gulp.watch(paths.metadata, gulp.series('metadata'));
  gulp.watch(paths.schemas, gulp.series('schemas'));
}));

gulp.task('reset-prefs', shell.task([
  'dconf reset -f /org/gnome/shell/extensions/gravatar/',
]));

gulp.task('uninstall', cb => del([paths.install], { force: true }, cb));

gulp.task('install-link', gulp.series('uninstall', 'build', () => gulp.src(['build/']).pipe(gulp.symlink(paths.install))));

gulp.task('install', gulp.series('uninstall', 'build', () => gulp.src(['build/**/*']).pipe(gulp.dest(paths.install))));

gulp.task('require-clean-wd', (cb) => {
  const count = execSync('git status --porcelain | wc -l').toString().replace(/\n$/, '');
  if (parseInt(count, 10) !== 0) {<commit_msg>Add old install location to unistall task<commit_after>const del = require('del');
const { execSync } = require('child_process');
const osenv = require('osenv');
const path = require('path');

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const threshold = require('gulp-eslint-threshold');
const jsonEditor = require('gulp-json-editor');
const shell = require('gulp-shell');
const zip = require('gulp-zip');

const metadata = require('./src/metadata.json');

const paths = {
  src: [
    'src/**/*',
    '!src/**/*~',
    '!src/schemas{,/**/*}',
    '!src/metadata.json',
    '!src/.eslintrc',
  ],
  lib: ['lib/**/*'],
  metadata: ['src/metadata.json'],
  schemas: ['src/schemas/**/*'],
  install: path.join(
    osenv.home(),
    '.local/share/gnome-shell/extensions',
    metadata.uuid,
  ),
  oldInstall: path.join(
    osenv.home(),
    '.local/share/gnome-shell/extensions',
    '<EMAIL>',
  ),
};

function getVersion(rawTag) {
  const sha1 = execSync('git rev-parse --short HEAD').toString().replace(/\n$/, '');
  let tag;
  try {
    tag = execSync(`git describe --tags --exact-match ${sha1} 2>/dev/null`).toString().replace(/\n$/, '');
  } catch (e) {
    return sha1;
  }

  if (rawTag) {
    return tag;
  }

  const v = parseInt(tag.replace(/^v/, ''), 10);
  if (Number.isNaN(v)) {
    throw new Error(`Unable to parse version from tag: ${tag}`);
  }
  return v;
}

gulp.task('lint', () => {
  const thresholdWarnings = 1;
  const thresholdErrors = 1;
  return gulp.src(['**/*.js'])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(threshold.afterErrors(thresholdErrors, (numberOfErrors) => {
      throw new Error(`ESLint errors (${numberOfErrors}) equal to or greater than the threshold (${thresholdErrors})`);
    }))
    .pipe(threshold.afterWarnings(thresholdWarnings, (numberOfWarnings) => {
      throw new Error(`ESLint warnings (${numberOfWarnings}) equal to or greater than the threshold (${thresholdWarnings})`);
    }));
});

gulp.task('clean', cb => del(['build/'], cb));

gulp.task('copy', () => gulp.src(paths.src).pipe(gulp.dest('build')));

gulp.task('copy-lib', () => gulp.src(paths.lib).pipe(gulp.dest('build/lib')));

gulp.task('copy-license', () => gulp.src(['LICENSE']).pipe(gulp.dest('build')));

gulp.task('metadata', () => gulp.src(paths.metadata).pipe(jsonEditor(json => Object.assign(json, { version: getVersion() }), { end_with_newline: true })).pipe(gulp.dest('build')));

gulp.task('schemas', shell.task([
  'mkdir -p build/schemas',
  'glib-compile-schemas --strict --targetdir build/schemas src/schemas/',
]));

gulp.task('build', gulp.series('clean', gulp.parallel(
  'metadata',
  'schemas',
  'copy',
  'copy-lib',
  'copy-license',
)));

gulp.task('watch', gulp.series('build', () => {
  gulp.watch(paths.src, gulp.series('copy'));
  gulp.watch(paths.lib, gulp.series('copy-lib'));
  gulp.watch(paths.metadata, gulp.series('metadata'));
  gulp.watch(paths.schemas, gulp.series('schemas'));
}));

gulp.task('reset-prefs', shell.task([
  'dconf reset -f /org/gnome/shell/extensions/gravatar/',
]));

gulp.task('uninstall', cb => del([paths.oldInstall, paths.install], { force: true }, cb));

gulp.task('install-link', gulp.series('uninstall', 'build', () => gulp.src(['build/']).pipe(gulp.symlink(paths.install))));

gulp.task('install', gulp.series('uninstall', 'build', () => gulp.src(['build/**/*']).pipe(gulp.dest(paths.install))));

gulp.task('require-clean-wd', (cb) => {
  const count = execSync('git status --porcelain | wc -l').toString().replace(/\n$/, '');
  if (parseInt(count, 10) !== 0) {
{'fraction_non_alphanumeric': 0.23223965763195434, 'fraction_numerical': 0.003138373751783167, 'mean_word_length': 4.327507598784194, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 34, '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': '2788802', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2457, 'n_words': 442}