Przeglądaj źródła

Spaces -> tabs

main
Eric Amodio 5 lat temu
rodzic
commit
8576957549
2 zmienionych plików z 312 dodań i 312 usunięć
  1. +68
    -68
      generateEmojiShortcodeMap.js
  2. +244
    -244
      webpack.config.js

+ 68
- 68
generateEmojiShortcodeMap.js Wyświetl plik

@ -4,89 +4,89 @@ const https = require('https');
const path = require('path');
async function generate() {
/**
* @type {{ [code: string]: string }}
*/
let map = Object.create(null);
/**
* @type {{ [code: string]: string }}
*/
let map = Object.create(null);
// Get emoji data from https://github.com/milesj/emojibase
// https://github.com/milesj/emojibase/blob/master/packages/data/en/raw.json
await download('https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/raw.json', 'raw.json');
// Get emoji data from https://github.com/milesj/emojibase
// https://github.com/milesj/emojibase/blob/master/packages/data/en/raw.json
await download('https://raw.githubusercontent.com/milesj/emojibase/master/packages/data/en/raw.json', 'raw.json');
/**
* @type {({ emoji: string; shortcodes: string[] })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const emojis = require(path.join(process.cwd(), 'raw.json'));
for (const emoji of emojis) {
if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
/**
* @type {({ emoji: string; shortcodes: string[] })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const emojis = require(path.join(process.cwd(), 'raw.json'));
for (const emoji of emojis) {
if (emoji.shortcodes == null || emoji.shortcodes.length === 0) continue;
for (let code of emoji.shortcodes) {
if (code[0] === ':' && code[code.length - 1] === ':') {
code = code.substring(1, code.length - 2);
}
for (let code of emoji.shortcodes) {
if (code[0] === ':' && code[code.length - 1] === ':') {
code = code.substring(1, code.length - 2);
}
if (map[code] !== undefined) {
console.warn(code);
}
map[code] = emoji.emoji;
}
}
if (map[code] !== undefined) {
console.warn(code);
}
map[code] = emoji.emoji;
}
}
fs.unlink('raw.json', () => {});
fs.unlink('raw.json', () => {});
// Get gitmoji data from https://github.com/carloscuesta/gitmoji
// https://github.com/carloscuesta/gitmoji/blob/master/src/data/gitmojis.json
await download(
'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json',
'gitmojis.json'
);
// Get gitmoji data from https://github.com/carloscuesta/gitmoji
// https://github.com/carloscuesta/gitmoji/blob/master/src/data/gitmojis.json
await download(
'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json',
'gitmojis.json'
);
/**
* @type {({ code: string; emoji: string })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const gitmojis = require(path.join(process.cwd(), 'gitmojis.json')).gitmojis;
for (const emoji of gitmojis) {
if (emoji.code[0] === ':' && emoji.code[emoji.code.length - 1] === ':') {
emoji.code = emoji.code.substring(1, emoji.code.length - 2);
}
/**
* @type {({ code: string; emoji: string })[]}
*/
// eslint-disable-next-line import/no-dynamic-require
const gitmojis = require(path.join(process.cwd(), 'gitmojis.json')).gitmojis;
for (const emoji of gitmojis) {
if (emoji.code[0] === ':' && emoji.code[emoji.code.length - 1] === ':') {
emoji.code = emoji.code.substring(1, emoji.code.length - 2);
}
if (map[emoji.code] !== undefined) {
console.warn(emoji.code);
continue;
}
map[emoji.code] = emoji.emoji;
}
if (map[emoji.code] !== undefined) {
console.warn(emoji.code);
continue;
}
map[emoji.code] = emoji.emoji;
}
fs.unlink('gitmojis.json', () => {});
fs.unlink('gitmojis.json', () => {});
// Sort the emojis for easier diff checking
/**
* @type { [string, string][] }}
*/
const list = Object.entries(map);
list.sort();
// Sort the emojis for easier diff checking
/**
* @type { [string, string][] }}
*/
const list = Object.entries(map);
list.sort();
map = list.reduce((m, [key, value]) => {
m[key] = value;
return m;
}, Object.create(null));
map = list.reduce((m, [key, value]) => {
m[key] = value;
return m;
}, Object.create(null));
fs.writeFileSync(path.join(process.cwd(), 'src/emojis.json'), JSON.stringify(map), 'utf8');
fs.writeFileSync(path.join(process.cwd(), 'src/emojis.json'), JSON.stringify(map), 'utf8');
}
function download(url, destination) {
return new Promise((resolve, reject) => {
const stream = fs.createWriteStream(destination);
https.get(url, rsp => {
rsp.pipe(stream);
stream.on('finish', () => {
stream.close();
resolve();
});
});
});
return new Promise((resolve, reject) => {
const stream = fs.createWriteStream(destination);
https.get(url, rsp => {
rsp.pipe(stream);
stream.on('finish', () => {
stream.close();
resolve();
});
});
});
}
generate();

+ 244
- 244
webpack.config.js Wyświetl plik

@ -16,262 +16,262 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = function(env, argv) {
env = env || {};
env.analyzeBundle = Boolean(env.analyzeBundle);
env.analyzeDeps = Boolean(env.analyzeDeps);
env.production = env.analyzeBundle || Boolean(env.production);
env.optimizeImages = Boolean(env.optimizeImages) || (env.production && !env.analyzeBundle);
env = env || {};
env.analyzeBundle = Boolean(env.analyzeBundle);
env.analyzeDeps = Boolean(env.analyzeDeps);
env.production = env.analyzeBundle || Boolean(env.production);
env.optimizeImages = Boolean(env.optimizeImages) || (env.production && !env.analyzeBundle);
if (!env.optimizeImages && !fs.existsSync(path.resolve(__dirname, 'images/settings'))) {
env.optimizeImages = true;
}
if (!env.optimizeImages && !fs.existsSync(path.resolve(__dirname, 'images/settings'))) {
env.optimizeImages = true;
}
return [getExtensionConfig(env), getWebviewsConfig(env)];
return [getExtensionConfig(env), getWebviewsConfig(env)];
};
function getExtensionConfig(env) {
/**
* @type any[]
*/
const plugins = [
new CleanPlugin({ cleanOnceBeforeBuildPatterns: ['**/*', '!**/webviews/**'] }),
new ForkTsCheckerPlugin({
async: false,
eslint: true,
useTypescriptIncrementalApi: true
})
];
/**
* @type any[]
*/
const plugins = [
new CleanPlugin({ cleanOnceBeforeBuildPatterns: ['**/*', '!**/webviews/**'] }),
new ForkTsCheckerPlugin({
async: false,
eslint: true,
useTypescriptIncrementalApi: true
})
];
if (env.analyzeDeps) {
plugins.push(
new CircularDependencyPlugin({
cwd: __dirname,
exclude: /node_modules/,
failOnError: false,
onDetected: function({ module: webpackModuleRecord, paths, compilation }) {
if (paths.some(p => /container\.ts/.test(p))) return;
if (env.analyzeDeps) {
plugins.push(
new CircularDependencyPlugin({
cwd: __dirname,
exclude: /node_modules/,
failOnError: false,
onDetected: function({ module: webpackModuleRecord, paths, compilation }) {
if (paths.some(p => /container\.ts/.test(p))) return;
compilation.warnings.push(new Error(paths.join(' -> ')));
}
})
);
}
compilation.warnings.push(new Error(paths.join(' -> ')));
}
})
);
}
if (env.analyzeBundle) {
plugins.push(new BundleAnalyzerPlugin());
}
if (env.analyzeBundle) {
plugins.push(new BundleAnalyzerPlugin());
}
return {
name: 'extension',
entry: './src/extension.ts',
mode: env.production ? 'production' : 'development',
target: 'node',
node: {
__dirname: false
},
devtool: 'source-map',
output: {
libraryTarget: 'commonjs2',
filename: 'extension.js'
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
ecma: 8,
// Keep the class names otherwise @log won't provide a useful name
// eslint-disable-next-line @typescript-eslint/camelcase
keep_classnames: true,
module: true
}
})
]
},
externals: {
vscode: 'commonjs vscode'
},
module: {
rules: [
{
exclude: /node_modules|\.d\.ts$/,
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true
}
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
},
plugins: plugins,
stats: {
all: false,
assets: true,
builtAt: true,
env: true,
errors: true,
timings: true,
warnings: true
}
};
return {
name: 'extension',
entry: './src/extension.ts',
mode: env.production ? 'production' : 'development',
target: 'node',
node: {
__dirname: false
},
devtool: 'source-map',
output: {
libraryTarget: 'commonjs2',
filename: 'extension.js'
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
ecma: 8,
// Keep the class names otherwise @log won't provide a useful name
// eslint-disable-next-line @typescript-eslint/camelcase
keep_classnames: true,
module: true
}
})
]
},
externals: {
vscode: 'commonjs vscode'
},
module: {
rules: [
{
exclude: /node_modules|\.d\.ts$/,
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true
}
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
},
plugins: plugins,
stats: {
all: false,
assets: true,
builtAt: true,
env: true,
errors: true,
timings: true,
warnings: true
}
};
}
function getWebviewsConfig(env) {
const clean = ['**/*'];
if (env.optimizeImages) {
console.log('Optimizing images (src/webviews/apps/images/settings/*.png)...');
clean.push(path.resolve(__dirname, 'images/settings/*'));
}
const clean = ['**/*'];
if (env.optimizeImages) {
console.log('Optimizing images (src/webviews/apps/images/settings/*.png)...');
clean.push(path.resolve(__dirname, 'images/settings/*'));
}
/**
* @type any[]
*/
const plugins = [
new CleanPlugin({ cleanOnceBeforeBuildPatterns: clean }),
new ForkTsCheckerPlugin({
tsconfig: path.resolve(__dirname, 'tsconfig.webviews.json'),
async: false,
eslint: true,
useTypescriptIncrementalApi: true
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new HtmlPlugin({
excludeAssets: [/.+-styles\.js/],
excludeChunks: ['welcome'],
template: 'settings/index.html',
filename: path.resolve(__dirname, 'dist/webviews/settings.html'),
inject: true,
// inlineSource: env.production ? '.(js|css)$' : undefined,
minify: env.production
? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyCSS: true
}
: false
}),
new HtmlPlugin({
excludeAssets: [/.+-styles\.js/],
excludeChunks: ['settings'],
template: 'welcome/index.html',
filename: path.resolve(__dirname, 'dist/webviews/welcome.html'),
inject: true,
// inlineSource: env.production ? '.(js|css)$' : undefined,
minify: env.production
? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyCSS: true
}
: false
}),
new HtmlExcludeAssetsPlugin(),
new HtmlInlineSourcePlugin(),
new ImageminPlugin({
disable: !env.optimizeImages,
externalImages: {
context: path.resolve(__dirname, 'src/webviews/apps/images'),
sources: glob.sync('src/webviews/apps/images/settings/*.png'),
destination: path.resolve(__dirname, 'images')
},
cacheFolder: path.resolve(__dirname, 'node_modules', '.cache', 'imagemin-webpack-plugin'),
gifsicle: null,
jpegtran: null,
optipng: null,
pngquant: {
quality: '85-100',
speed: env.production ? 1 : 10
},
svgo: null
})
];
/**
* @type any[]
*/
const plugins = [
new CleanPlugin({ cleanOnceBeforeBuildPatterns: clean }),
new ForkTsCheckerPlugin({
tsconfig: path.resolve(__dirname, 'tsconfig.webviews.json'),
async: false,
eslint: true,
useTypescriptIncrementalApi: true
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new HtmlPlugin({
excludeAssets: [/.+-styles\.js/],
excludeChunks: ['welcome'],
template: 'settings/index.html',
filename: path.resolve(__dirname, 'dist/webviews/settings.html'),
inject: true,
// inlineSource: env.production ? '.(js|css)$' : undefined,
minify: env.production
? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyCSS: true
}
: false
}),
new HtmlPlugin({
excludeAssets: [/.+-styles\.js/],
excludeChunks: ['settings'],
template: 'welcome/index.html',
filename: path.resolve(__dirname, 'dist/webviews/welcome.html'),
inject: true,
// inlineSource: env.production ? '.(js|css)$' : undefined,
minify: env.production
? {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyCSS: true
}
: false
}),
new HtmlExcludeAssetsPlugin(),
new HtmlInlineSourcePlugin(),
new ImageminPlugin({
disable: !env.optimizeImages,
externalImages: {
context: path.resolve(__dirname, 'src/webviews/apps/images'),
sources: glob.sync('src/webviews/apps/images/settings/*.png'),
destination: path.resolve(__dirname, 'images')
},
cacheFolder: path.resolve(__dirname, 'node_modules', '.cache', 'imagemin-webpack-plugin'),
gifsicle: null,
jpegtran: null,
optipng: null,
pngquant: {
quality: '85-100',
speed: env.production ? 1 : 10
},
svgo: null
})
];
return {
name: 'webviews',
context: path.resolve(__dirname, 'src/webviews/apps'),
entry: {
'main-styles': ['./scss/main.scss'],
settings: ['./settings/index.ts'],
welcome: ['./welcome/index.ts']
},
mode: env.production ? 'production' : 'development',
devtool: env.production ? undefined : 'eval-source-map',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist/webviews'),
publicPath: '#{root}/dist/webviews/'
},
module: {
rules: [
{
exclude: /node_modules|\.d\.ts$/,
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.webviews.json',
transpileOnly: true,
experimentalWatchApi: true
}
}
},
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: true,
url: false
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
modules: [path.resolve(__dirname, 'src/webviews/apps'), 'node_modules']
},
plugins: plugins,
stats: {
all: false,
assets: true,
builtAt: true,
env: true,
errors: true,
timings: true,
warnings: true
}
};
return {
name: 'webviews',
context: path.resolve(__dirname, 'src/webviews/apps'),
entry: {
'main-styles': ['./scss/main.scss'],
settings: ['./settings/index.ts'],
welcome: ['./welcome/index.ts']
},
mode: env.production ? 'production' : 'development',
devtool: env.production ? undefined : 'eval-source-map',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist/webviews'),
publicPath: '#{root}/dist/webviews/'
},
module: {
rules: [
{
exclude: /node_modules|\.d\.ts$/,
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig.webviews.json',
transpileOnly: true,
experimentalWatchApi: true
}
}
},
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: true,
url: false
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
modules: [path.resolve(__dirname, 'src/webviews/apps'), 'node_modules']
},
plugins: plugins,
stats: {
all: false,
assets: true,
builtAt: true,
env: true,
errors: true,
timings: true,
warnings: true
}
};
}

Ładowanie…
Anuluj
Zapisz