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.
Files changed (36) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bundle.js +1 -1
  3. package/dist/cjs/src/rendering/lib.d.ts +1 -1
  4. package/dist/cjs/src/rendering/lib.js +2 -1
  5. package/dist/mjs/src/rendering/lib.d.ts +1 -1
  6. package/dist/mjs/src/rendering/lib.mjs +1 -1
  7. package/package.json +3 -2
  8. package/src/rendering/lib.ts +1 -1
  9. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -34
  10. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  11. package/.github/ISSUE_TEMPLATE/translation.yml +0 -902
  12. package/.github/pull_request_template.md +0 -15
  13. package/.github/workflows/firebase-hosting-merge.yml +0 -34
  14. package/.github/workflows/firebase-hosting-pull-request.yml +0 -34
  15. package/.github/workflows/github-pages.yml +0 -58
  16. package/.husky/pre-commit +0 -4
  17. package/build_tools/BundledFile.ts +0 -167
  18. package/build_tools/buildTranslationTemplate.ts +0 -121
  19. package/build_tools/bundle.ts +0 -11
  20. package/build_tools/postDist.ts +0 -71
  21. package/dist/cjs/build_tools/BundledFile.d.ts +0 -13
  22. package/dist/cjs/build_tools/BundledFile.js +0 -163
  23. package/dist/cjs/build_tools/buildTranslationTemplate.d.ts +0 -1
  24. package/dist/cjs/build_tools/buildTranslationTemplate.js +0 -119
  25. package/dist/cjs/build_tools/bundle.d.ts +0 -1
  26. package/dist/cjs/build_tools/bundle.js +0 -10
  27. package/dist/cjs/build_tools/postDist.d.ts +0 -1
  28. package/dist/cjs/build_tools/postDist.js +0 -72
  29. package/dist/mjs/build_tools/BundledFile.d.ts +0 -13
  30. package/dist/mjs/build_tools/BundledFile.mjs +0 -157
  31. package/dist/mjs/build_tools/buildTranslationTemplate.d.ts +0 -1
  32. package/dist/mjs/build_tools/buildTranslationTemplate.mjs +0 -94
  33. package/dist/mjs/build_tools/bundle.d.ts +0 -1
  34. package/dist/mjs/build_tools/bundle.mjs +0 -5
  35. package/dist/mjs/build_tools/postDist.d.ts +0 -1
  36. package/dist/mjs/build_tools/postDist.mjs +0 -67
@@ -1,15 +0,0 @@
1
- # Summary
2
- <!-- A description of the changes made by this PR. -->
3
-
4
- # Testing <!-- (if applicable) -->
5
- <!--
6
- Describe what changes have automated tests and what changes don't. If changes lack automated tests, please describe how it can be verified that changes made by this pull request work as expected.
7
- -->
8
-
9
- # Screenshots/other information
10
- <!--
11
- If applicable, please include screenshots/screen recordings/other information that may help contributors review this pull request.
12
- -->
13
-
14
-
15
- Resolves #[issue number here].
@@ -1,34 +0,0 @@
1
- # This file was auto-generated by the Firebase CLI
2
- # https://github.com/firebase/firebase-tools
3
-
4
- name: Deploy to Firebase Hosting on merge
5
- 'on':
6
- push:
7
- branches:
8
- - 'main'
9
-
10
- # See https://github.com/FirebaseExtended/action-hosting-deploy/issues/198
11
- permissions:
12
- contents: read
13
-
14
- jobs:
15
- build_and_deploy:
16
- runs-on: ubuntu-latest
17
- steps:
18
- - uses: actions/checkout@v3
19
- - name: Install dependencies
20
- run: yarn install
21
- - name: Test imports
22
- run: yarn dist-test
23
- - name: Run tests
24
- run: yarn test
25
- - name: Lint
26
- run: yarn lint-ci
27
- - name: Build
28
- run: cd docs/example && yarn install && yarn build
29
- - uses: FirebaseExtended/action-hosting-deploy@v0
30
- with:
31
- repoToken: '${{ secrets.GITHUB_TOKEN }}'
32
- firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JS_DRAW }}'
33
- channelId: live
34
- projectId: js-draw
@@ -1,34 +0,0 @@
1
- # This file was auto-generated by the Firebase CLI
2
- # https://github.com/firebase/firebase-tools
3
-
4
- name: Deploy to Firebase Hosting on PR
5
- 'on': pull_request
6
-
7
- # See https://github.com/FirebaseExtended/action-hosting-deploy/issues/198
8
- # and https://github.com/FirebaseExtended/action-hosting-deploy/issues/108#issuecomment-1036024111
9
- permissions:
10
- contents: read
11
- pull-requests: write
12
- checks: write
13
-
14
- jobs:
15
- build_and_preview:
16
- if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v3
20
- - name: Install dependencies
21
- run: yarn install
22
- - name: Test imports
23
- run: yarn dist-test
24
- - name: Run tests
25
- run: yarn test
26
- - name: Lint
27
- run: yarn lint-ci
28
- - name: Build
29
- run: cd docs/example && yarn install && yarn build
30
- - uses: FirebaseExtended/action-hosting-deploy@v0
31
- with:
32
- repoToken: '${{ secrets.GITHUB_TOKEN }}'
33
- firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JS_DRAW }}'
34
- projectId: js-draw
@@ -1,58 +0,0 @@
1
- # Created on GitHub
2
-
3
- # Simple workflow for deploying static content to GitHub Pages
4
- name: Deploy static content to Pages
5
-
6
- on:
7
- # Runs on pushes targeting the default branch
8
- push:
9
- branches: ["main"]
10
-
11
- # Allows you to run this workflow manually from the Actions tab
12
- workflow_dispatch:
13
-
14
- # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15
- permissions:
16
- contents: read
17
- pages: write
18
- id-token: write
19
-
20
- # Allow one concurrent deployment
21
- concurrency:
22
- group: "pages"
23
- cancel-in-progress: true
24
-
25
- jobs:
26
- # Single deploy job since we're just deploying
27
- deploy:
28
- environment:
29
- name: github-pages
30
- url: ${{ steps.deployment.outputs.page_url }}
31
- runs-on: ubuntu-latest
32
- steps:
33
- - name: Checkout
34
- uses: actions/checkout@v3
35
- - name: Install dependencies
36
- run: yarn install
37
- - name: Test imports
38
- run: yarn dist-test
39
- - name: Run tests
40
- run: yarn test
41
- - name: Lint
42
- run: yarn lint-ci
43
- - name: Build documentation
44
- run: yarn doc
45
- - name: Build
46
- run: cd docs/example && yarn install && yarn build
47
- - name: Remove flies that don't need to be uploaded
48
- run: cd docs/ && rm -rf example*/node_modules/
49
- - name: Setup Pages
50
- uses: actions/configure-pages@v2
51
- - name: Upload artifact
52
- uses: actions/upload-pages-artifact@v1
53
- with:
54
- # Upload just the docs folder
55
- path: './docs/'
56
- - name: Deploy to GitHub Pages
57
- id: deployment
58
- uses: actions/deploy-pages@v1
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- yarn lint-staged
@@ -1,167 +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
-
5
- import { dirname, extname, basename } from 'path';
6
- import TerserPlugin from 'terser-webpack-plugin';
7
-
8
- import webpack from 'webpack';
9
-
10
- export default class BundledFile {
11
- private readonly bundleBaseName: string;
12
- private readonly rootFileDirectory: string;
13
- private readonly outputDirectory: string;
14
- private readonly outputFilename: string;
15
-
16
- public constructor(
17
- public readonly bundleName: string,
18
- private readonly sourceFilePath: string,
19
- outputFilepath?: string,
20
- ) {
21
- this.rootFileDirectory = dirname(sourceFilePath);
22
- this.bundleBaseName = basename(sourceFilePath, extname(sourceFilePath));
23
-
24
- if (outputFilepath) {
25
- this.outputDirectory = dirname(outputFilepath);
26
- this.outputFilename = basename(outputFilepath);
27
- } else {
28
- this.outputDirectory = this.rootFileDirectory;
29
- this.outputFilename = `${this.bundleBaseName}.bundle.js`;
30
- }
31
- }
32
-
33
- private getWebpackOptions(mode: 'production' | 'development'): webpack.Configuration {
34
- const config: webpack.Configuration = {
35
- mode,
36
- entry: this.sourceFilePath,
37
- output: {
38
- path: this.outputDirectory,
39
- filename: this.outputFilename,
40
-
41
- library: {
42
- type: 'window',
43
- name: this.bundleName,
44
- },
45
- },
46
- // See https://webpack.js.org/guides/typescript/
47
- module: {
48
- rules: [
49
- {
50
- // Include .tsx to include react components
51
- test: /\.tsx?$/i,
52
- use: 'ts-loader',
53
- exclude: /node_modules/,
54
- },
55
- {
56
- test: /\.css$/i,
57
- use: ['style-loader', 'css-loader'],
58
- },
59
- ],
60
- },
61
- optimization: {
62
- minimizer: [
63
- // Don't create separate files for comments.
64
- // See https://stackoverflow.com/a/65650316/17055750
65
- new TerserPlugin({
66
- extractComments: false,
67
- }),
68
- ],
69
- },
70
- // Increase the minimum size required
71
- // to trigger warnings.
72
- // See https://stackoverflow.com/a/53517149/17055750
73
- performance: {
74
- maxAssetSize: 2_000_000, // 2-ish MiB
75
- maxEntrypointSize: 2_000_000,
76
- },
77
- resolve: {
78
- extensions: ['.tsx', '.ts', '.js'],
79
- },
80
- };
81
-
82
- return config;
83
- }
84
-
85
- private handleErrors(err: Error | undefined | null, stats: webpack.Stats | undefined): boolean {
86
- let failed = false;
87
-
88
- if (err) {
89
- console.error(`Error: ${err.name}`, err.message, err.stack);
90
- failed = true;
91
- } else if (stats?.hasErrors() || stats?.hasWarnings()) {
92
- const data = stats.toJson();
93
-
94
- if (data.warnings && data.warningsCount) {
95
- console.warn('Warnings: ', data.warningsCount);
96
- for (const warning of data.warnings) {
97
- // Stack contains the message
98
- if (warning.stack) {
99
- console.warn(warning.stack);
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
- } else {
111
- console.error(error.message);
112
- }
113
- console.error();
114
- }
115
-
116
- failed = true;
117
- }
118
- }
119
-
120
- return failed;
121
- }
122
-
123
- // Create a minified JS file in the same directory as `this.sourceFilePath` with
124
- // the same name.
125
- public build() {
126
- const compiler = webpack(this.getWebpackOptions('production'));
127
- return new Promise<void>((resolve, reject) => {
128
- console.info(`Building bundle: ${this.bundleName}...`);
129
-
130
- compiler.run((err, stats) => {
131
- let failed = this.handleErrors(err, stats);
132
-
133
- // Clean up.
134
- compiler.close(async (error) => {
135
- if (error) {
136
- console.error('Error cleaning up:', error);
137
- failed = true;
138
- }
139
- if (!failed) {
140
- console.log('☑ Done building! ☑');
141
- resolve();
142
- } else {
143
- reject();
144
- }
145
- });
146
- });
147
- });
148
- }
149
-
150
- public startWatching() {
151
- const compiler = webpack(this.getWebpackOptions('development'));
152
- const watchOptions = {
153
- ignored: [
154
- '**/node_modules',
155
- '**/dist',
156
- ],
157
- };
158
-
159
- console.info('Watching bundle: ', this.bundleName);
160
- compiler.watch(watchOptions, async (err, stats) => {
161
- const failed = this.handleErrors(err, stats);
162
- if (!failed) {
163
- console.log('☑ Built! ☑');
164
- }
165
- });
166
- }
167
- }
@@ -1,121 +0,0 @@
1
-
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
-
5
- import { defaultEditorLocalization } from '../src/localization';
6
-
7
- // Adds markdown formatting to format text like code.
8
- const codeFormat = (text: string) => {
9
- let maxConsecutiveBackticks = 0;
10
-
11
- // Find the longest number of consecutive backticks — we need to have more
12
- // than that for the delimiters.
13
- const backtickRuns = text.matchAll(/[`]+/g);
14
- for (const backticks of backtickRuns) {
15
- if (backticks.length > maxConsecutiveBackticks) {
16
- maxConsecutiveBackticks = backticks.length;
17
- }
18
- }
19
-
20
- let codeStartEnd = '';
21
- for (let i = 0; i < maxConsecutiveBackticks + 1; i++) {
22
- codeStartEnd += '`';
23
- }
24
-
25
- // If the text already starts with a `, add a space to prevent the
26
- // markdown parser from treating it as part of the delimiter.
27
- if (text.startsWith('`')) {
28
- text = ' ' + text;
29
- }
30
-
31
- if (text.endsWith('`')) {
32
- text = text + ' ';
33
- }
34
-
35
- return `${codeStartEnd}${text}${codeStartEnd}`;
36
- };
37
-
38
- const collapseSpaces = (text: string) => text.replace(/\s+/g, ' ');
39
-
40
- const generateTranslationTemplate = () => {
41
- const bodyContentLines: string[] = [];
42
-
43
- const addInput = (
44
- type: string, id: string, attrs: Record<string, string>, required: boolean = false
45
- ) => {
46
- const lines: string[] = [];
47
- lines.push(` - type: ${type}`);
48
- lines.push(` id: ${id}`);
49
- lines.push(' attributes:');
50
-
51
- for (const key in attrs) {
52
- const value = `${attrs[key]}`;
53
-
54
- const escapedValue = value.replace(/[\\]/g, '\\\\').replace(/"/g, '\\"');
55
- lines.push(` ${key}: "${escapedValue}"`);
56
- }
57
-
58
- lines.push(' validations:');
59
- lines.push(` required: ${required}`);
60
-
61
- bodyContentLines.push(...lines);
62
- };
63
-
64
- const addLabel = (text: string) => {
65
- bodyContentLines.push(' - type: markdown');
66
- bodyContentLines.push(' attributes:');
67
- bodyContentLines.push(' value: |');
68
- bodyContentLines.push(' ' + text);
69
- };
70
-
71
- addLabel(collapseSpaces(`
72
- Thank you for taking the time to translate \`js-draw\`! If you don't have time to translate
73
- all of the strings below, feel free to submit an incomplete translation and edit it later.
74
- Use this template to update an existing translation or to create a new translation.
75
- `));
76
-
77
- addLabel(collapseSpaces(`
78
- (Optional) If you would like to submit a pull request that applies this translation,
79
- note that existing translations are present in
80
- [src/localizations/](https://github.com/personalizedrefrigerator/js-draw/tree/main/src/localizations).
81
- `));
82
-
83
- addInput('input', 'language-name', {
84
- label: 'Language',
85
- description: 'The name of the language to translate to in English (e.g. Spanish)',
86
- }, true);
87
-
88
- for (const key in defaultEditorLocalization) {
89
- const englishTranslation = `${(defaultEditorLocalization as any)[key]}`;
90
- addInput('input', `translation-${key}`, {
91
- label: `${key}`,
92
- description: `Translate ${codeFormat(englishTranslation)}.`,
93
- placeholder: englishTranslation,
94
- });
95
- }
96
-
97
- addInput('textarea', 'additional-comments', {
98
- label: 'Additional information',
99
- placeholder: 'Any additional information/comments on the translation can go here.',
100
- });
101
-
102
- return `name: Translation
103
- # This template is auto-generated by build_tools/buildTranslationTemplate.ts
104
- # Do not modify it directly.
105
- description: Translate the editor to a new language!
106
- title: "[Translation]: <language>"
107
- labels: [localization]
108
- assignees: []
109
- body:
110
- ${bodyContentLines.join('\n')}`;
111
- };
112
-
113
- const template = generateTranslationTemplate();
114
-
115
- // According to https://stackoverflow.com/a/13650454, fs should
116
- // be able to handle forward and back slashes (both) on Windows (so extra
117
- // path logic shouldn't be needed here.)
118
- const rootDir = path.dirname(__dirname);
119
- const translationTempaltePath = path.join(rootDir, '.github/ISSUE_TEMPLATE/translation.yml');
120
-
121
- fs.writeFileSync(translationTempaltePath, template);
@@ -1,11 +0,0 @@
1
- import { dirname } from 'path';
2
- import BundledFile from './BundledFile';
3
-
4
- const rootDir = dirname(__dirname);
5
- const mainBundle = new BundledFile(
6
- 'jsdraw',
7
- `${rootDir}/src/bundle/bundled.ts`,
8
- `${rootDir}/dist/bundle.js`,
9
- );
10
-
11
- void mainBundle.build();
@@ -1,71 +0,0 @@
1
-
2
- import { readdir, stat, rename, readFile, writeFile, unlink } from 'fs/promises';
3
- import path from 'path';
4
-
5
- // Script to be run after building JavaScript files from TypeScript.
6
- // TODO: This is very hacky.
7
- // TODO: [Use the TypeScript Compiler API instead.](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API)
8
-
9
- // Iterates over every JavaScript file in [directory].
10
- const forEachFile = async (directory: string, processFile: (filePath: string)=>Promise<void>) => {
11
- const files = await readdir(directory);
12
-
13
- await Promise.all(files.map(async (file) => {
14
- const filePath = path.join(directory, file);
15
- const stats = await stat(filePath);
16
-
17
- if (stats.isDirectory()) {
18
- await forEachFile(filePath, processFile);
19
- } else if (stats.isFile()) {
20
- await processFile(filePath);
21
- } else {
22
- throw new Error('Unknown file type!');
23
- }
24
- }));
25
- };
26
-
27
- const removeFiles = async (directory: string, filePattern: RegExp) => {
28
- await forEachFile(directory, async (filePath: string) => {
29
- if (!filePath.match(filePattern)) {
30
- return;
31
- }
32
-
33
- await unlink(filePath);
34
- });
35
- };
36
-
37
- const main = async () => {
38
- const rootDir = path.dirname(__dirname);
39
- const cjsPath = `${rootDir}/dist/cjs`;
40
- const mjsPath = `${rootDir}/dist/mjs`;
41
-
42
- const testPattern = /\.test\.js$/;
43
- await removeFiles(cjsPath, testPattern);
44
- await removeFiles(mjsPath, testPattern);
45
-
46
- // We need to replace imports in ESM files.
47
- await forEachFile(mjsPath, async (filePath: string) => {
48
- if (!filePath.endsWith('.js')) {
49
- return;
50
- }
51
-
52
- // Rename
53
- const newPath = filePath.replace(/\.js$/, '.mjs');
54
- await rename(filePath, newPath);
55
-
56
- // Change imports from
57
- // import foo from './bar'
58
- // to
59
- // import foo from './bar.mjs'
60
- // and exports similarly.
61
- let contents = await readFile(newPath, { encoding: 'utf-8' });
62
-
63
- // TODO: Switch to using the TypeScript compiler API. This has the danger of changing imports
64
- // in multi-line strings.
65
- contents = contents.replace(/([\n]|^)(import|export)(.*)from\s+(['"])(\.*\/[^\n]+)(['"])/g, '$1$2 $3 from $4$5.mjs$6');
66
-
67
- await writeFile(newPath, contents);
68
- });
69
- };
70
-
71
- 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
- }