Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Do away with Gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Aug 13, 2019
1 parent ee2085c commit fcaa7f8
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 1,856 deletions.
38 changes: 0 additions & 38 deletions gulpfile.ts

This file was deleted.

17 changes: 11 additions & 6 deletions package.json
Expand Up @@ -45,7 +45,8 @@
"db:up": "docker-compose up -d",
"db:stop": "docker-compose stop",
"db:down": "docker-compose down",
"prepublishOnly": "yarn build && yarn docs"
"prepublishOnly": "yarn build && yarn docs",
"reload": "ts-node scripts/reloader.ts"
},
"keywords": [
"bot",
Expand Down Expand Up @@ -110,7 +111,8 @@
"@types/common-tags": "^1.8.0",
"@types/dotenv": "^6.1.1",
"@types/fast-levenshtein": "^0.0.1",
"@types/gulp": "^4.0.6",
"@types/glob": "^7.1.1",
"@types/jsonfile": "^5.0.0",
"@types/libsodium-wrappers": "^0.7.5",
"@types/module-alias": "^2.0.0",
"@types/moment-duration-format": "^2.2.2",
Expand All @@ -119,22 +121,25 @@
"@types/qrcode": "^1.3.3",
"@types/sqlite3": "^3.1.5",
"@types/table": "^4.0.6",
"@types/terser": "^3.12.0",
"@types/turndown": "^5.0.0",
"@types/ws": "^6.0.2",
"@types/yargs": "^13.0.2",
"@types/yargs-interactive": "^2.1.0",
"chalk": "^2.4.2",
"concurrently": "^4.1.1",
"copyfiles": "^2.1.1",
"cross-env": "^5.2.0",
"eslint": "^6.1.0",
"gulp": "^4.0.2",
"gulp-typescript": "^5.0.1",
"glob": "^7.1.4",
"jsdoc-to-markdown": "^5.0.0",
"jsonfile": "^5.0.0",
"replace": "^1.1.0",
"rimraf": "^2.6.3",
"terser": "^4.1.4",
"ts-node": "^8.3.0",
"tslib": "^1.10.0",
"typescript": "^3.5.3",
"utility-types": "^3.7.0",
"yargs": "^13.3.0"
"yargs-interactive": "^2.1.0"
}
}
74 changes: 74 additions & 0 deletions scripts/reloader.ts
@@ -0,0 +1,74 @@
import { sync as globby } from 'glob';
import yargsInteractive, { Option as YargOptions } from 'yargs-interactive';
import { join, resolve } from 'path';
import { stripIndent } from 'common-tags';
import chalk from 'chalk';
import { readFileSync as readFile, writeFileSync as writeFile } from 'fs';
import { TranspileOutput, CompilerOptions, transpileModule } from 'typescript';
import { readFileSync as readJson } from 'jsonfile';
import { minify as terser } from 'terser';

(async () => {
type YargResult = {
help: boolean;
version: boolean;
interactive: boolean;
command: string | string[];
};

type BaseTSConfig = {
compilerOptions: CompilerOptions;
include: string[];
exclude: string[];
};

const srcDir = join(__dirname, '../src');
const commandDir = join(srcDir, 'commands');
const ribbonCommands = globby(`${commandDir}/**/*.ts`).map(file => file.split('/')[6].slice(0, -3));
const baseTSConfig = readJson(resolve(srcDir, '..', 'tsconfig.json')) as BaseTSConfig;

const compile = (fileContent: string, options?: CompilerOptions): TranspileOutput => {
const compilerOptions: typeof options = {
...baseTSConfig.compilerOptions,
...options,
};

return transpileModule(fileContent, { compilerOptions });
};

try {
const yargOptions: YargOptions = {
interactive: { default: true },
command: {
type: 'checkbox',
describe: 'Which commands should be reloaded?',
prompt: 'if-empty',
choices: ribbonCommands,
},
};

const results = await yargsInteractive()
.usage((stripIndent`
${chalk.yellow('Ribbon Reloader')}
${chalk.cyan('Usage:')}
${chalk.green('yarn reload')}
${chalk.green('yarn reload')} --command <command>
${chalk.green('yarn reload')} --help`
))
.interactive(yargOptions) as YargResult;

const commandsResult: string[] = Array.isArray(results.command) ? results.command : [ results.command ];

for (const result of commandsResult) {
const filePath = globby(`${commandDir}/**/${result}.ts`)[0];
const fileContent = readFile(filePath, { encoding: 'utf8' });
const transpiledModule = compile(fileContent).outputText;
const minfiedModule = terser(transpiledModule, { compress: true, ecma: 6, mangle: true }).code;
const distPath = filePath.replace(/\/src\//, '/dist/').replace(/\.ts$/, '.js');

writeFile(distPath, minfiedModule, { encoding: 'utf8' });
}
} catch (err) {
throw new Error(err);
}
})();
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -26,7 +26,7 @@
"@pokedex/*": ["data/dex/*"],
"@i18n/*": ["data/i18n/*"]
},
"typeRoots": ["typings","./node_modules/@types"],
"typeRoots": ["typings","./node_modules/@types"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules","dist","src/**/*.js","typings"]
Expand Down

0 comments on commit fcaa7f8

Please sign in to comment.