You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: esm/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ If you are using Yarn, NPM, or a similar package manager, the files should have
7
7
Otherwise, after changing directory to the one containing this file:
8
8
9
9
- If you have Node.js installed, run `node generate.mjs`.
10
-
- If you don't have Node.js installed but are on a POSIX-like system with `bash`/`zsh`, run `sh ./generate.sh`.
10
+
- If you don't have Node.js installed but are on a POSIX-like system with `bash`/`zsh`, run `sh ./generate.sh`. (This uses features like `grep -o`, so won't work on *absolutely all* POSIX systems. It works on many computers though, so try it out first!) **Security-wise, we don't prevent JavaScript**
11
11
- If neither of the above are true, install Node.js or (slightly harder; look online) a POSIX/"Linux" compatible shell.
copyingCode=true;// After is code to copy - this line missed out
234
261
}
235
262
}
263
+
if(className===null)thrownewError(`ESM-SUPPORT-START-PLUGIN-${pluginName} section of code-input.d.ts does not contain a line matching /^ *class ([A-Za-z]+)/, but it should!`);
264
+
265
+
// 2. Edit the lines
266
+
forawait(letlineoflines){
267
+
if(copyingCode){
268
+
awaitpluginDMts.writeFile(line
269
+
.replaceAll("codeInput.Plugin","Plugin")
270
+
.replaceAll("codeInput.CodeInput","CodeInput")
271
+
.replaceAll(`class ${className}`,`declare class ${className}`)
echo "import { Template, Plugin } from \"../code-input.d.mts\";" >> templates/$0.d.mts
89
+
echo "import type { Template, Plugin } from \"../code-input.d.mts\";" >> templates/$0.d.mts
63
90
# Code after start and before end of this template, making use of the imported Template, not codeInput.Template, and the imported Plugin, not codeInput.Plugin, exporting the class as default
64
91
# export default class replacement should work but won"t leave indentation as JS version does.
65
-
head -$(($(sed -n "/ESM-SUPPORT-END-TEMPLATE-$0/=" ../code-input.d.ts | head -1) - 1)) ../code-input.d.ts | tail --line=+$(($(sed -n "/ESM-SUPPORT-START-TEMPLATE-$0/=" ../code-input.d.ts | head -1) + 1)) | sed "s/codeInput\.Template/Template/g" | sed "s/codeInput\.Plugin/Plugin/g" | sed -E "s/^[[:space:]]*class /export default class /" >> templates/$0.d.mts
92
+
head -n $(($(sed -n "/ESM-SUPPORT-END-TEMPLATE-$0/=" ../code-input.d.ts | head -n 1) - 1)) ../code-input.d.ts | tail --line=+$(($(sed -n "/ESM-SUPPORT-START-TEMPLATE-$0/=" ../code-input.d.ts | head -n 1) + 1)) | sed "s/codeInput\.Template/Template/g" | sed "s/codeInput\.Plugin/Plugin/g" | sed -E "s/^[[:space:]]*class /export default class /" >> templates/$0.d.mts
66
93
67
94
# $0 is the template name, $1 is the autogenerated notice
68
95
'"%""$AUTOGENERATED_NOTICE"
@@ -77,11 +104,11 @@ mkdir -p plugins
77
104
# Imports
78
105
echo "import { Plugin } from \"../code-input.mjs\";" >> plugins/$0.mjs
79
106
# Plugin syntax is to be stored in an object; do so temporarily.
80
-
echo "let plugins = {};" >> plugins/$0.mjs
107
+
echo "let plugins = {};" >> plugins/$0.mjs;
81
108
# Code from this plugin"s file, making use of the imported Plugin, not codeInput.Plugin, and of the created plugins object, not codeInput.plugins
82
109
cat ../plugins/$0.js | sed "s/codeInput\.Plugin/Plugin/g" | sed "s/codeInput\.plugins/plugins/g" >> plugins/$0.mjs;
83
110
84
-
PLUGIN_CLASS_NAME="$(grep -Eo "codeInput\.plugins\.[a-zA-Z]+" ../plugins/$0.js | head -1 | sed "s/codeInput\.plugins\.//")";
111
+
PLUGIN_CLASS_NAME="$(grep -Eo "codeInput\.plugins\.[a-zA-Z]+" ../plugins/$0.js | head -n 1 | sed "s/codeInput\.plugins\.//")";
echo "import { Plugin, CodeInput } from \"../code-input.d.mts\";" >> plugins/$0.d.mts
124
+
echo "import type { Plugin, CodeInput } from \"../code-input.d.mts\";" >> plugins/$0.d.mts
98
125
# Code after start and before end of this template, making use of the imported Plugin, not codeInput.Plugin and the imported CodeInput, not codeInput.CodeInput, exporting the class as default
99
126
# export default class replacement should work but won"t leave indentation as JS version does.
100
-
head -$(($(sed -n "/ESM-SUPPORT-END-PLUGIN-$0/=" ../code-input.d.ts | head -1) - 1)) ../code-input.d.ts | tail --line=+$(($(sed -n "/ESM-SUPPORT-START-PLUGIN-$0/=" ../code-input.d.ts | head -1) + 1)) | sed "s/codeInput\.Plugin/Plugin/g" | sed "s/codeInput\.CodeInput/CodeInput/g" | sed -E "s/^[[:space:]]*class /export default class /" >> plugins/$0.d.mts
127
+
head -n $(($(sed -n "/ESM-SUPPORT-END-PLUGIN-$0/=" ../code-input.d.ts | head -n 1) - 1)) ../code-input.d.ts | tail --line=+$(($(sed -n "/ESM-SUPPORT-START-PLUGIN-$0/=" ../code-input.d.ts | head -n 1) + 1)) >> plugins/$0.d.mts;
128
+
129
+
# Declare the first class defined in the file and, if a namespace with the same name
130
+
# exists, declare that as well, then export it at the end of the file so the class and
131
+
# namespace are merged if necessary.
132
+
classname=$(grep -Eo "^ *class [A-Za-z]+" plugins/$0.d.mts | head -n 1 | sed "s/^ *class //");
133
+
134
+
cat plugins/$0.d.mts | sed "s/codeInput\.Plugin/Plugin/g" | sed "s/codeInput\.CodeInput/CodeInput/g" | sed "s/class ${classname} /declare class ${classname} /g" | sed "s/namespace ${classname} /declare namespace ${classname} /g" | sed "s/codeInput\.plugins\.${classname}/${classname}/g" >> plugins/$0.new.d.mts;
135
+
# New file in middle so concurrent pipes dont read and write same file
Carries out partially automated user interface tests to check that both the core components and the plugins work in some ways. It doesn't fully cover every scenario so you should test any code you change by hand, but it's good for quickly checking a wide range of functionality works.
4
+
5
+
For each of `prism.html` and `hljs.html`, open the page, answer the browser popups you get, and see the results of testing at the end.
6
+
7
+
The code currently relies on hardcoded wait periods, assuming the interface will respond in time, and meaning that if they don't, tests can fail. If tests fail unexpectedly, free up memory etc. on your computer, reload, and try again.
0 commit comments