Remove Grunt in favor of ts/scripts

This commit is contained in:
Scott Nonnenberg 2021-12-14 08:43:46 -08:00 committed by GitHub
parent 4e947211b2
commit e74376b997
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 1137 additions and 1661 deletions

16
ts/scripts/.eslintrc.js Normal file
View file

@ -0,0 +1,16 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
module.exports = {
rules: {
'no-console': 'off',
// We still get the value of this rule, it just allows for dev deps
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
},
],
},
};

View file

@ -0,0 +1,54 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { basename, join } from 'path';
import { copyFileSync, readFileSync, writeFileSync } from 'fs';
// Concat
console.log('Concatenating...');
const BASE_BOWER = join(__dirname, '../../components');
const BASE_NODE = join(__dirname, '../../node_modules');
const CONCAT_TARGET = join(__dirname, '../../js/components.js');
const CONCAT_SOURCES = [
join(BASE_NODE, 'jquery/dist/jquery.js'),
join(BASE_NODE, 'mustache/mustache.js'),
join(BASE_NODE, 'underscore/underscore.js'),
join(BASE_BOWER, 'qrcode/qrcode.js'),
join(BASE_BOWER, 'webaudiorecorder/lib/WebAudioRecorder.js'),
];
let concat = '// concatenated components.js';
CONCAT_SOURCES.forEach(source => {
const contents = readFileSync(source, 'utf8');
const name = basename(source);
console.log(`Concatenating ${source}`);
concat += `\n\n// ${name}\n${contents}`;
});
console.log(`Writing to ${CONCAT_TARGET}`);
writeFileSync(CONCAT_TARGET, concat);
// Copy
console.log();
console.log('Copying...');
const BASE_JS = join(__dirname, '../../js');
const COPY_SOURCES = [
{
src: join(BASE_BOWER, 'mp3lameencoder/lib/Mp3LameEncoder.js'),
dest: join(BASE_JS, 'Mp3LameEncoder.min.js'),
},
{
src: join(BASE_BOWER, 'webaudiorecorder/lib/WebAudioRecorderMp3.js'),
dest: join(BASE_JS, 'WebAudioRecorderMp3.js'),
},
];
for (const { src, dest } of COPY_SOURCES) {
console.log(`Copying ${src} to ${dest}`);
copyFileSync(src, dest);
}

View file

@ -0,0 +1,26 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join } from 'path';
import { execSync } from 'child_process';
import { writeFileSync } from 'fs';
import { DAY } from '../util/durations';
const unixTimestamp = parseInt(
execSync('git show -s --format=%ct').toString('utf8'),
10
);
const buildCreation = unixTimestamp * 1000;
const buildExpiration = buildCreation + DAY * 90;
const localProductionPath = join(
__dirname,
'../../config/local-production.json'
);
const localProductionConfig = { buildCreation, buildExpiration };
writeFileSync(
localProductionPath,
`${JSON.stringify(localProductionConfig)}\n`
);

53
ts/scripts/get-strings.ts Normal file
View file

@ -0,0 +1,53 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join, resolve } from 'path';
import { existsSync, readdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { readJsonSync } from 'fs-extra';
import type { LocaleMessagesType } from '../types/I18N';
console.log('Getting latest strings!');
console.log();
console.log('Getting strings, allow for new ones over 80% translated');
execSync('tx pull --all --use-git-timestamps --minimum-perc=80', {
stdio: [null, process.stdout, process.stderr],
});
console.log();
console.log('Getting strings, updating everything previously missed');
execSync('tx pull --use-git-timestamps', {
stdio: [null, process.stdout, process.stderr],
});
const BASE_DIR = join(__dirname, '../../_locales');
const en: LocaleMessagesType = readJsonSync(
join(BASE_DIR, '/en/messages.json')
);
const locales = readdirSync(join(BASE_DIR, ''));
console.log();
console.log('Re-adding placeholders to non-en locales');
locales.forEach((locale: string) => {
if (locale === 'en') {
return;
}
const target = resolve(join(BASE_DIR, locale, 'messages.json'));
if (!existsSync(target)) {
throw new Error(`File not found for ${locale}: ${target}`);
}
const messages: LocaleMessagesType = readJsonSync(target);
Object.keys(messages).forEach(key => {
if (!en[key]) {
return;
}
messages[key].placeholders = en[key].placeholders;
});
console.log(`Writing ${target}`);
writeFileSync(target, `${JSON.stringify(messages, null, 4)}\n`);
});

View file

@ -1,8 +1,6 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable no-console */
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';