js-draw 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/bundle.js +1 -1
- package/dist/cjs/src/rendering/lib.d.ts +1 -1
- package/dist/cjs/src/rendering/lib.js +2 -1
- package/dist/mjs/src/rendering/lib.d.ts +1 -1
- package/dist/mjs/src/rendering/lib.mjs +1 -1
- package/package.json +3 -2
- package/src/rendering/lib.ts +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -34
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/ISSUE_TEMPLATE/translation.yml +0 -902
- package/.github/pull_request_template.md +0 -15
- package/.github/workflows/firebase-hosting-merge.yml +0 -34
- package/.github/workflows/firebase-hosting-pull-request.yml +0 -34
- package/.github/workflows/github-pages.yml +0 -58
- package/.husky/pre-commit +0 -4
- package/build_tools/BundledFile.ts +0 -167
- package/build_tools/buildTranslationTemplate.ts +0 -121
- package/build_tools/bundle.ts +0 -11
- package/build_tools/postDist.ts +0 -71
- package/dist/cjs/build_tools/BundledFile.d.ts +0 -13
- package/dist/cjs/build_tools/BundledFile.js +0 -163
- package/dist/cjs/build_tools/buildTranslationTemplate.d.ts +0 -1
- package/dist/cjs/build_tools/buildTranslationTemplate.js +0 -119
- package/dist/cjs/build_tools/bundle.d.ts +0 -1
- package/dist/cjs/build_tools/bundle.js +0 -10
- package/dist/cjs/build_tools/postDist.d.ts +0 -1
- package/dist/cjs/build_tools/postDist.js +0 -72
- package/dist/mjs/build_tools/BundledFile.d.ts +0 -13
- package/dist/mjs/build_tools/BundledFile.mjs +0 -157
- package/dist/mjs/build_tools/buildTranslationTemplate.d.ts +0 -1
- package/dist/mjs/build_tools/buildTranslationTemplate.mjs +0 -94
- package/dist/mjs/build_tools/bundle.d.ts +0 -1
- package/dist/mjs/build_tools/bundle.mjs +0 -5
- package/dist/mjs/build_tools/postDist.d.ts +0 -1
- package/dist/mjs/build_tools/postDist.mjs +0 -67
@@ -1,163 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// This file is taken from Joplin: https://github.com/laurent22/joplin
|
3
|
-
// js-draw was originally created as a part of a pull request for joplin. This
|
4
|
-
// is part of the functionality from Joplin it requires.
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
12
|
-
});
|
13
|
-
};
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
16
|
-
};
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
const path_1 = require("path");
|
19
|
-
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
|
20
|
-
const webpack_1 = __importDefault(require("webpack"));
|
21
|
-
class BundledFile {
|
22
|
-
constructor(bundleName, sourceFilePath, outputFilepath) {
|
23
|
-
this.bundleName = bundleName;
|
24
|
-
this.sourceFilePath = sourceFilePath;
|
25
|
-
this.rootFileDirectory = (0, path_1.dirname)(sourceFilePath);
|
26
|
-
this.bundleBaseName = (0, path_1.basename)(sourceFilePath, (0, path_1.extname)(sourceFilePath));
|
27
|
-
if (outputFilepath) {
|
28
|
-
this.outputDirectory = (0, path_1.dirname)(outputFilepath);
|
29
|
-
this.outputFilename = (0, path_1.basename)(outputFilepath);
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
this.outputDirectory = this.rootFileDirectory;
|
33
|
-
this.outputFilename = `${this.bundleBaseName}.bundle.js`;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
getWebpackOptions(mode) {
|
37
|
-
const config = {
|
38
|
-
mode,
|
39
|
-
entry: this.sourceFilePath,
|
40
|
-
output: {
|
41
|
-
path: this.outputDirectory,
|
42
|
-
filename: this.outputFilename,
|
43
|
-
library: {
|
44
|
-
type: 'window',
|
45
|
-
name: this.bundleName,
|
46
|
-
},
|
47
|
-
},
|
48
|
-
// See https://webpack.js.org/guides/typescript/
|
49
|
-
module: {
|
50
|
-
rules: [
|
51
|
-
{
|
52
|
-
// Include .tsx to include react components
|
53
|
-
test: /\.tsx?$/i,
|
54
|
-
use: 'ts-loader',
|
55
|
-
exclude: /node_modules/,
|
56
|
-
},
|
57
|
-
{
|
58
|
-
test: /\.css$/i,
|
59
|
-
use: ['style-loader', 'css-loader'],
|
60
|
-
},
|
61
|
-
],
|
62
|
-
},
|
63
|
-
optimization: {
|
64
|
-
minimizer: [
|
65
|
-
// Don't create separate files for comments.
|
66
|
-
// See https://stackoverflow.com/a/65650316/17055750
|
67
|
-
new terser_webpack_plugin_1.default({
|
68
|
-
extractComments: false,
|
69
|
-
}),
|
70
|
-
],
|
71
|
-
},
|
72
|
-
// Increase the minimum size required
|
73
|
-
// to trigger warnings.
|
74
|
-
// See https://stackoverflow.com/a/53517149/17055750
|
75
|
-
performance: {
|
76
|
-
maxAssetSize: 2000000,
|
77
|
-
maxEntrypointSize: 2000000,
|
78
|
-
},
|
79
|
-
resolve: {
|
80
|
-
extensions: ['.tsx', '.ts', '.js'],
|
81
|
-
},
|
82
|
-
};
|
83
|
-
return config;
|
84
|
-
}
|
85
|
-
handleErrors(err, stats) {
|
86
|
-
let failed = false;
|
87
|
-
if (err) {
|
88
|
-
console.error(`Error: ${err.name}`, err.message, err.stack);
|
89
|
-
failed = true;
|
90
|
-
}
|
91
|
-
else if ((stats === null || stats === void 0 ? void 0 : stats.hasErrors()) || (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
|
92
|
-
const data = stats.toJson();
|
93
|
-
if (data.warnings && data.warningsCount) {
|
94
|
-
console.warn('Warnings: ', data.warningsCount);
|
95
|
-
for (const warning of data.warnings) {
|
96
|
-
// Stack contains the message
|
97
|
-
if (warning.stack) {
|
98
|
-
console.warn(warning.stack);
|
99
|
-
}
|
100
|
-
else {
|
101
|
-
console.warn(warning.message);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
if (data.errors && data.errorsCount) {
|
106
|
-
console.error('Errors: ', data.errorsCount);
|
107
|
-
for (const error of data.errors) {
|
108
|
-
if (error.stack) {
|
109
|
-
console.error(error.stack);
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
console.error(error.message);
|
113
|
-
}
|
114
|
-
console.error();
|
115
|
-
}
|
116
|
-
failed = true;
|
117
|
-
}
|
118
|
-
}
|
119
|
-
return failed;
|
120
|
-
}
|
121
|
-
// Create a minified JS file in the same directory as `this.sourceFilePath` with
|
122
|
-
// the same name.
|
123
|
-
build() {
|
124
|
-
const compiler = (0, webpack_1.default)(this.getWebpackOptions('production'));
|
125
|
-
return new Promise((resolve, reject) => {
|
126
|
-
console.info(`Building bundle: ${this.bundleName}...`);
|
127
|
-
compiler.run((err, stats) => {
|
128
|
-
let failed = this.handleErrors(err, stats);
|
129
|
-
// Clean up.
|
130
|
-
compiler.close((error) => __awaiter(this, void 0, void 0, function* () {
|
131
|
-
if (error) {
|
132
|
-
console.error('Error cleaning up:', error);
|
133
|
-
failed = true;
|
134
|
-
}
|
135
|
-
if (!failed) {
|
136
|
-
console.log('☑ Done building! ☑');
|
137
|
-
resolve();
|
138
|
-
}
|
139
|
-
else {
|
140
|
-
reject();
|
141
|
-
}
|
142
|
-
}));
|
143
|
-
});
|
144
|
-
});
|
145
|
-
}
|
146
|
-
startWatching() {
|
147
|
-
const compiler = (0, webpack_1.default)(this.getWebpackOptions('development'));
|
148
|
-
const watchOptions = {
|
149
|
-
ignored: [
|
150
|
-
'**/node_modules',
|
151
|
-
'**/dist',
|
152
|
-
],
|
153
|
-
};
|
154
|
-
console.info('Watching bundle: ', this.bundleName);
|
155
|
-
compiler.watch(watchOptions, (err, stats) => __awaiter(this, void 0, void 0, function* () {
|
156
|
-
const failed = this.handleErrors(err, stats);
|
157
|
-
if (!failed) {
|
158
|
-
console.log('☑ Built! ☑');
|
159
|
-
}
|
160
|
-
}));
|
161
|
-
}
|
162
|
-
}
|
163
|
-
exports.default = BundledFile;
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,119 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
const fs = __importStar(require("fs"));
|
27
|
-
const path = __importStar(require("path"));
|
28
|
-
const localization_1 = require("../src/localization");
|
29
|
-
// Adds markdown formatting to format text like code.
|
30
|
-
const codeFormat = (text) => {
|
31
|
-
let maxConsecutiveBackticks = 0;
|
32
|
-
// Find the longest number of consecutive backticks — we need to have more
|
33
|
-
// than that for the delimiters.
|
34
|
-
const backtickRuns = text.matchAll(/[`]+/g);
|
35
|
-
for (const backticks of backtickRuns) {
|
36
|
-
if (backticks.length > maxConsecutiveBackticks) {
|
37
|
-
maxConsecutiveBackticks = backticks.length;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
let codeStartEnd = '';
|
41
|
-
for (let i = 0; i < maxConsecutiveBackticks + 1; i++) {
|
42
|
-
codeStartEnd += '`';
|
43
|
-
}
|
44
|
-
// If the text already starts with a `, add a space to prevent the
|
45
|
-
// markdown parser from treating it as part of the delimiter.
|
46
|
-
if (text.startsWith('`')) {
|
47
|
-
text = ' ' + text;
|
48
|
-
}
|
49
|
-
if (text.endsWith('`')) {
|
50
|
-
text = text + ' ';
|
51
|
-
}
|
52
|
-
return `${codeStartEnd}${text}${codeStartEnd}`;
|
53
|
-
};
|
54
|
-
const collapseSpaces = (text) => text.replace(/\s+/g, ' ');
|
55
|
-
const generateTranslationTemplate = () => {
|
56
|
-
const bodyContentLines = [];
|
57
|
-
const addInput = (type, id, attrs, required = false) => {
|
58
|
-
const lines = [];
|
59
|
-
lines.push(` - type: ${type}`);
|
60
|
-
lines.push(` id: ${id}`);
|
61
|
-
lines.push(' attributes:');
|
62
|
-
for (const key in attrs) {
|
63
|
-
const value = `${attrs[key]}`;
|
64
|
-
const escapedValue = value.replace(/[\\]/g, '\\\\').replace(/"/g, '\\"');
|
65
|
-
lines.push(` ${key}: "${escapedValue}"`);
|
66
|
-
}
|
67
|
-
lines.push(' validations:');
|
68
|
-
lines.push(` required: ${required}`);
|
69
|
-
bodyContentLines.push(...lines);
|
70
|
-
};
|
71
|
-
const addLabel = (text) => {
|
72
|
-
bodyContentLines.push(' - type: markdown');
|
73
|
-
bodyContentLines.push(' attributes:');
|
74
|
-
bodyContentLines.push(' value: |');
|
75
|
-
bodyContentLines.push(' ' + text);
|
76
|
-
};
|
77
|
-
addLabel(collapseSpaces(`
|
78
|
-
Thank you for taking the time to translate \`js-draw\`! If you don't have time to translate
|
79
|
-
all of the strings below, feel free to submit an incomplete translation and edit it later.
|
80
|
-
Use this template to update an existing translation or to create a new translation.
|
81
|
-
`));
|
82
|
-
addLabel(collapseSpaces(`
|
83
|
-
(Optional) If you would like to submit a pull request that applies this translation,
|
84
|
-
note that existing translations are present in
|
85
|
-
[src/localizations/](https://github.com/personalizedrefrigerator/js-draw/tree/main/src/localizations).
|
86
|
-
`));
|
87
|
-
addInput('input', 'language-name', {
|
88
|
-
label: 'Language',
|
89
|
-
description: 'The name of the language to translate to in English (e.g. Spanish)',
|
90
|
-
}, true);
|
91
|
-
for (const key in localization_1.defaultEditorLocalization) {
|
92
|
-
const englishTranslation = `${localization_1.defaultEditorLocalization[key]}`;
|
93
|
-
addInput('input', `translation-${key}`, {
|
94
|
-
label: `${key}`,
|
95
|
-
description: `Translate ${codeFormat(englishTranslation)}.`,
|
96
|
-
placeholder: englishTranslation,
|
97
|
-
});
|
98
|
-
}
|
99
|
-
addInput('textarea', 'additional-comments', {
|
100
|
-
label: 'Additional information',
|
101
|
-
placeholder: 'Any additional information/comments on the translation can go here.',
|
102
|
-
});
|
103
|
-
return `name: Translation
|
104
|
-
# This template is auto-generated by build_tools/buildTranslationTemplate.ts
|
105
|
-
# Do not modify it directly.
|
106
|
-
description: Translate the editor to a new language!
|
107
|
-
title: "[Translation]: <language>"
|
108
|
-
labels: [localization]
|
109
|
-
assignees: []
|
110
|
-
body:
|
111
|
-
${bodyContentLines.join('\n')}`;
|
112
|
-
};
|
113
|
-
const template = generateTranslationTemplate();
|
114
|
-
// According to https://stackoverflow.com/a/13650454, fs should
|
115
|
-
// be able to handle forward and back slashes (both) on Windows (so extra
|
116
|
-
// path logic shouldn't be needed here.)
|
117
|
-
const rootDir = path.dirname(__dirname);
|
118
|
-
const translationTempaltePath = path.join(rootDir, '.github/ISSUE_TEMPLATE/translation.yml');
|
119
|
-
fs.writeFileSync(translationTempaltePath, template);
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const path_1 = require("path");
|
7
|
-
const BundledFile_1 = __importDefault(require("./BundledFile"));
|
8
|
-
const rootDir = (0, path_1.dirname)(__dirname);
|
9
|
-
const mainBundle = new BundledFile_1.default('jsdraw', `${rootDir}/src/bundle/bundled.ts`, `${rootDir}/dist/bundle.js`);
|
10
|
-
void mainBundle.build();
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,72 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const promises_1 = require("fs/promises");
|
16
|
-
const path_1 = __importDefault(require("path"));
|
17
|
-
// Script to be run after building JavaScript files from TypeScript.
|
18
|
-
// TODO: This is very hacky.
|
19
|
-
// TODO: [Use the TypeScript Compiler API instead.](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API)
|
20
|
-
// Iterates over every JavaScript file in [directory].
|
21
|
-
const forEachFile = (directory, processFile) => __awaiter(void 0, void 0, void 0, function* () {
|
22
|
-
const files = yield (0, promises_1.readdir)(directory);
|
23
|
-
yield Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
24
|
-
const filePath = path_1.default.join(directory, file);
|
25
|
-
const stats = yield (0, promises_1.stat)(filePath);
|
26
|
-
if (stats.isDirectory()) {
|
27
|
-
yield forEachFile(filePath, processFile);
|
28
|
-
}
|
29
|
-
else if (stats.isFile()) {
|
30
|
-
yield processFile(filePath);
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
throw new Error('Unknown file type!');
|
34
|
-
}
|
35
|
-
})));
|
36
|
-
});
|
37
|
-
const removeFiles = (directory, filePattern) => __awaiter(void 0, void 0, void 0, function* () {
|
38
|
-
yield forEachFile(directory, (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
39
|
-
if (!filePath.match(filePattern)) {
|
40
|
-
return;
|
41
|
-
}
|
42
|
-
yield (0, promises_1.unlink)(filePath);
|
43
|
-
}));
|
44
|
-
});
|
45
|
-
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
46
|
-
const rootDir = path_1.default.dirname(__dirname);
|
47
|
-
const cjsPath = `${rootDir}/dist/cjs`;
|
48
|
-
const mjsPath = `${rootDir}/dist/mjs`;
|
49
|
-
const testPattern = /\.test\.js$/;
|
50
|
-
yield removeFiles(cjsPath, testPattern);
|
51
|
-
yield removeFiles(mjsPath, testPattern);
|
52
|
-
// We need to replace imports in ESM files.
|
53
|
-
yield forEachFile(mjsPath, (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
54
|
-
if (!filePath.endsWith('.js')) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
// Rename
|
58
|
-
const newPath = filePath.replace(/\.js$/, '.mjs');
|
59
|
-
yield (0, promises_1.rename)(filePath, newPath);
|
60
|
-
// Change imports from
|
61
|
-
// import foo from './bar'
|
62
|
-
// to
|
63
|
-
// import foo from './bar.mjs'
|
64
|
-
// and exports similarly.
|
65
|
-
let contents = yield (0, promises_1.readFile)(newPath, { encoding: 'utf-8' });
|
66
|
-
// TODO: Switch to using the TypeScript compiler API. This has the danger of changing imports
|
67
|
-
// in multi-line strings.
|
68
|
-
contents = contents.replace(/([\n]|^)(import|export)(.*)from\s+(['"])(\.*\/[^\n]+)(['"])/g, '$1$2 $3 from $4$5.mjs$6');
|
69
|
-
yield (0, promises_1.writeFile)(newPath, contents);
|
70
|
-
}));
|
71
|
-
});
|
72
|
-
main();
|
@@ -1,13 +0,0 @@
|
|
1
|
-
export default class BundledFile {
|
2
|
-
readonly bundleName: string;
|
3
|
-
private readonly sourceFilePath;
|
4
|
-
private readonly bundleBaseName;
|
5
|
-
private readonly rootFileDirectory;
|
6
|
-
private readonly outputDirectory;
|
7
|
-
private readonly outputFilename;
|
8
|
-
constructor(bundleName: string, sourceFilePath: string, outputFilepath?: string);
|
9
|
-
private getWebpackOptions;
|
10
|
-
private handleErrors;
|
11
|
-
build(): Promise<void>;
|
12
|
-
startWatching(): void;
|
13
|
-
}
|
@@ -1,157 +0,0 @@
|
|
1
|
-
// This file is taken from Joplin: https://github.com/laurent22/joplin
|
2
|
-
// js-draw was originally created as a part of a pull request for joplin. This
|
3
|
-
// is part of the functionality from Joplin it requires.
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
11
|
-
});
|
12
|
-
};
|
13
|
-
import { dirname, extname, basename } from 'path';
|
14
|
-
import TerserPlugin from 'terser-webpack-plugin';
|
15
|
-
import webpack from 'webpack';
|
16
|
-
export default class BundledFile {
|
17
|
-
constructor(bundleName, sourceFilePath, outputFilepath) {
|
18
|
-
this.bundleName = bundleName;
|
19
|
-
this.sourceFilePath = sourceFilePath;
|
20
|
-
this.rootFileDirectory = dirname(sourceFilePath);
|
21
|
-
this.bundleBaseName = basename(sourceFilePath, extname(sourceFilePath));
|
22
|
-
if (outputFilepath) {
|
23
|
-
this.outputDirectory = dirname(outputFilepath);
|
24
|
-
this.outputFilename = basename(outputFilepath);
|
25
|
-
}
|
26
|
-
else {
|
27
|
-
this.outputDirectory = this.rootFileDirectory;
|
28
|
-
this.outputFilename = `${this.bundleBaseName}.bundle.js`;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
getWebpackOptions(mode) {
|
32
|
-
const config = {
|
33
|
-
mode,
|
34
|
-
entry: this.sourceFilePath,
|
35
|
-
output: {
|
36
|
-
path: this.outputDirectory,
|
37
|
-
filename: this.outputFilename,
|
38
|
-
library: {
|
39
|
-
type: 'window',
|
40
|
-
name: this.bundleName,
|
41
|
-
},
|
42
|
-
},
|
43
|
-
// See https://webpack.js.org/guides/typescript/
|
44
|
-
module: {
|
45
|
-
rules: [
|
46
|
-
{
|
47
|
-
// Include .tsx to include react components
|
48
|
-
test: /\.tsx?$/i,
|
49
|
-
use: 'ts-loader',
|
50
|
-
exclude: /node_modules/,
|
51
|
-
},
|
52
|
-
{
|
53
|
-
test: /\.css$/i,
|
54
|
-
use: ['style-loader', 'css-loader'],
|
55
|
-
},
|
56
|
-
],
|
57
|
-
},
|
58
|
-
optimization: {
|
59
|
-
minimizer: [
|
60
|
-
// Don't create separate files for comments.
|
61
|
-
// See https://stackoverflow.com/a/65650316/17055750
|
62
|
-
new TerserPlugin({
|
63
|
-
extractComments: false,
|
64
|
-
}),
|
65
|
-
],
|
66
|
-
},
|
67
|
-
// Increase the minimum size required
|
68
|
-
// to trigger warnings.
|
69
|
-
// See https://stackoverflow.com/a/53517149/17055750
|
70
|
-
performance: {
|
71
|
-
maxAssetSize: 2000000,
|
72
|
-
maxEntrypointSize: 2000000,
|
73
|
-
},
|
74
|
-
resolve: {
|
75
|
-
extensions: ['.tsx', '.ts', '.js'],
|
76
|
-
},
|
77
|
-
};
|
78
|
-
return config;
|
79
|
-
}
|
80
|
-
handleErrors(err, stats) {
|
81
|
-
let failed = false;
|
82
|
-
if (err) {
|
83
|
-
console.error(`Error: ${err.name}`, err.message, err.stack);
|
84
|
-
failed = true;
|
85
|
-
}
|
86
|
-
else if ((stats === null || stats === void 0 ? void 0 : stats.hasErrors()) || (stats === null || stats === void 0 ? void 0 : stats.hasWarnings())) {
|
87
|
-
const data = stats.toJson();
|
88
|
-
if (data.warnings && data.warningsCount) {
|
89
|
-
console.warn('Warnings: ', data.warningsCount);
|
90
|
-
for (const warning of data.warnings) {
|
91
|
-
// Stack contains the message
|
92
|
-
if (warning.stack) {
|
93
|
-
console.warn(warning.stack);
|
94
|
-
}
|
95
|
-
else {
|
96
|
-
console.warn(warning.message);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
if (data.errors && data.errorsCount) {
|
101
|
-
console.error('Errors: ', data.errorsCount);
|
102
|
-
for (const error of data.errors) {
|
103
|
-
if (error.stack) {
|
104
|
-
console.error(error.stack);
|
105
|
-
}
|
106
|
-
else {
|
107
|
-
console.error(error.message);
|
108
|
-
}
|
109
|
-
console.error();
|
110
|
-
}
|
111
|
-
failed = true;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
return failed;
|
115
|
-
}
|
116
|
-
// Create a minified JS file in the same directory as `this.sourceFilePath` with
|
117
|
-
// the same name.
|
118
|
-
build() {
|
119
|
-
const compiler = webpack(this.getWebpackOptions('production'));
|
120
|
-
return new Promise((resolve, reject) => {
|
121
|
-
console.info(`Building bundle: ${this.bundleName}...`);
|
122
|
-
compiler.run((err, stats) => {
|
123
|
-
let failed = this.handleErrors(err, stats);
|
124
|
-
// Clean up.
|
125
|
-
compiler.close((error) => __awaiter(this, void 0, void 0, function* () {
|
126
|
-
if (error) {
|
127
|
-
console.error('Error cleaning up:', error);
|
128
|
-
failed = true;
|
129
|
-
}
|
130
|
-
if (!failed) {
|
131
|
-
console.log('☑ Done building! ☑');
|
132
|
-
resolve();
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
reject();
|
136
|
-
}
|
137
|
-
}));
|
138
|
-
});
|
139
|
-
});
|
140
|
-
}
|
141
|
-
startWatching() {
|
142
|
-
const compiler = webpack(this.getWebpackOptions('development'));
|
143
|
-
const watchOptions = {
|
144
|
-
ignored: [
|
145
|
-
'**/node_modules',
|
146
|
-
'**/dist',
|
147
|
-
],
|
148
|
-
};
|
149
|
-
console.info('Watching bundle: ', this.bundleName);
|
150
|
-
compiler.watch(watchOptions, (err, stats) => __awaiter(this, void 0, void 0, function* () {
|
151
|
-
const failed = this.handleErrors(err, stats);
|
152
|
-
if (!failed) {
|
153
|
-
console.log('☑ Built! ☑');
|
154
|
-
}
|
155
|
-
}));
|
156
|
-
}
|
157
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,94 +0,0 @@
|
|
1
|
-
import * as fs from 'fs';
|
2
|
-
import * as path from 'path';
|
3
|
-
import { defaultEditorLocalization } from '../src/localization.mjs';
|
4
|
-
// Adds markdown formatting to format text like code.
|
5
|
-
const codeFormat = (text) => {
|
6
|
-
let maxConsecutiveBackticks = 0;
|
7
|
-
// Find the longest number of consecutive backticks — we need to have more
|
8
|
-
// than that for the delimiters.
|
9
|
-
const backtickRuns = text.matchAll(/[`]+/g);
|
10
|
-
for (const backticks of backtickRuns) {
|
11
|
-
if (backticks.length > maxConsecutiveBackticks) {
|
12
|
-
maxConsecutiveBackticks = backticks.length;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
let codeStartEnd = '';
|
16
|
-
for (let i = 0; i < maxConsecutiveBackticks + 1; i++) {
|
17
|
-
codeStartEnd += '`';
|
18
|
-
}
|
19
|
-
// If the text already starts with a `, add a space to prevent the
|
20
|
-
// markdown parser from treating it as part of the delimiter.
|
21
|
-
if (text.startsWith('`')) {
|
22
|
-
text = ' ' + text;
|
23
|
-
}
|
24
|
-
if (text.endsWith('`')) {
|
25
|
-
text = text + ' ';
|
26
|
-
}
|
27
|
-
return `${codeStartEnd}${text}${codeStartEnd}`;
|
28
|
-
};
|
29
|
-
const collapseSpaces = (text) => text.replace(/\s+/g, ' ');
|
30
|
-
const generateTranslationTemplate = () => {
|
31
|
-
const bodyContentLines = [];
|
32
|
-
const addInput = (type, id, attrs, required = false) => {
|
33
|
-
const lines = [];
|
34
|
-
lines.push(` - type: ${type}`);
|
35
|
-
lines.push(` id: ${id}`);
|
36
|
-
lines.push(' attributes:');
|
37
|
-
for (const key in attrs) {
|
38
|
-
const value = `${attrs[key]}`;
|
39
|
-
const escapedValue = value.replace(/[\\]/g, '\\\\').replace(/"/g, '\\"');
|
40
|
-
lines.push(` ${key}: "${escapedValue}"`);
|
41
|
-
}
|
42
|
-
lines.push(' validations:');
|
43
|
-
lines.push(` required: ${required}`);
|
44
|
-
bodyContentLines.push(...lines);
|
45
|
-
};
|
46
|
-
const addLabel = (text) => {
|
47
|
-
bodyContentLines.push(' - type: markdown');
|
48
|
-
bodyContentLines.push(' attributes:');
|
49
|
-
bodyContentLines.push(' value: |');
|
50
|
-
bodyContentLines.push(' ' + text);
|
51
|
-
};
|
52
|
-
addLabel(collapseSpaces(`
|
53
|
-
Thank you for taking the time to translate \`js-draw\`! If you don't have time to translate
|
54
|
-
all of the strings below, feel free to submit an incomplete translation and edit it later.
|
55
|
-
Use this template to update an existing translation or to create a new translation.
|
56
|
-
`));
|
57
|
-
addLabel(collapseSpaces(`
|
58
|
-
(Optional) If you would like to submit a pull request that applies this translation,
|
59
|
-
note that existing translations are present in
|
60
|
-
[src/localizations/](https://github.com/personalizedrefrigerator/js-draw/tree/main/src/localizations).
|
61
|
-
`));
|
62
|
-
addInput('input', 'language-name', {
|
63
|
-
label: 'Language',
|
64
|
-
description: 'The name of the language to translate to in English (e.g. Spanish)',
|
65
|
-
}, true);
|
66
|
-
for (const key in defaultEditorLocalization) {
|
67
|
-
const englishTranslation = `${defaultEditorLocalization[key]}`;
|
68
|
-
addInput('input', `translation-${key}`, {
|
69
|
-
label: `${key}`,
|
70
|
-
description: `Translate ${codeFormat(englishTranslation)}.`,
|
71
|
-
placeholder: englishTranslation,
|
72
|
-
});
|
73
|
-
}
|
74
|
-
addInput('textarea', 'additional-comments', {
|
75
|
-
label: 'Additional information',
|
76
|
-
placeholder: 'Any additional information/comments on the translation can go here.',
|
77
|
-
});
|
78
|
-
return `name: Translation
|
79
|
-
# This template is auto-generated by build_tools/buildTranslationTemplate.ts
|
80
|
-
# Do not modify it directly.
|
81
|
-
description: Translate the editor to a new language!
|
82
|
-
title: "[Translation]: <language>"
|
83
|
-
labels: [localization]
|
84
|
-
assignees: []
|
85
|
-
body:
|
86
|
-
${bodyContentLines.join('\n')}`;
|
87
|
-
};
|
88
|
-
const template = generateTranslationTemplate();
|
89
|
-
// According to https://stackoverflow.com/a/13650454, fs should
|
90
|
-
// be able to handle forward and back slashes (both) on Windows (so extra
|
91
|
-
// path logic shouldn't be needed here.)
|
92
|
-
const rootDir = path.dirname(__dirname);
|
93
|
-
const translationTempaltePath = path.join(rootDir, '.github/ISSUE_TEMPLATE/translation.yml');
|
94
|
-
fs.writeFileSync(translationTempaltePath, template);
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|