@scratch/scratch-gui 11.0.0-beta.1

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/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "include": ["src"],
3
+ "compilerOptions": {
4
+ /* Visit https://aka.ms/tsconfig to read more about this file */
5
+
6
+ /* Language and Environment */
7
+ "target": "ESNext",
8
+ "jsx": "react",
9
+
10
+ /* Modules */
11
+ "module": "commonjs",
12
+ "types": ["./src/types.d.ts"],
13
+
14
+ /* Emit */
15
+ "declaration": true,
16
+ "sourceMap": true,
17
+ "outDir": "./dist/types/",
18
+
19
+ /* Interop Constraints */
20
+ "esModuleInterop": true,
21
+ "forceConsistentCasingInFileNames": true,
22
+
23
+ /* Type Checking */
24
+ "strict": true,
25
+ "noImplicitAny": false,
26
+
27
+ /* Completeness */
28
+ "skipLibCheck": true
29
+ }
30
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "include": ["src"],
3
+ "extends": ["./tsconfig.json"],
4
+ "compilerOptions": {
5
+ /* Visit https://aka.ms/tsconfig to read more about this file */
6
+
7
+ /* Modules */
8
+ "module": "CommonJS",
9
+ "types": ["jest", "./src/types.d.ts"],
10
+ }
11
+ }
@@ -0,0 +1,211 @@
1
+ const path = require('path');
2
+ const webpack = require('webpack');
3
+
4
+ // Plugins
5
+ const CopyWebpackPlugin = require('copy-webpack-plugin');
6
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
7
+
8
+ const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
9
+
10
+ // const STATIC_PATH = process.env.STATIC_PATH || '/static';
11
+
12
+ const commonHtmlWebpackPluginOptions = {
13
+ // Google Tag Manager ID
14
+ // Looks like 'GTM-XXXXXXX'
15
+ gtm_id: process.env.GTM_ID || '',
16
+
17
+ // Google Tag Manager env & auth info for alterative GTM environments
18
+ // Looks like '&gtm_auth=0123456789abcdefghijklm&gtm_preview=env-00&gtm_cookies_win=x'
19
+ // Taken from the middle of: GTM -> Admin -> Environments -> (environment) -> Get Snippet
20
+ // Blank for production
21
+ gtm_env_auth: process.env.GTM_ENV_AUTH || ''
22
+ };
23
+
24
+ const baseConfig = new ScratchWebpackConfigBuilder(
25
+ {
26
+ rootPath: path.resolve(__dirname),
27
+ enableReact: true,
28
+ enableTs: true,
29
+ shouldSplitChunks: false
30
+ })
31
+ .setTarget('browserslist')
32
+ .merge({
33
+ output: {
34
+ assetModuleFilename: 'static/assets/[name].[hash][ext][query]',
35
+ library: {
36
+ name: 'GUI',
37
+ type: 'umd2'
38
+ },
39
+ // Do not clean the JS files before building as we have two outputs to the same
40
+ // dist directory (the regular and the standalone version)
41
+ clean: false
42
+ },
43
+ resolve: {
44
+ fallback: {
45
+ Buffer: require.resolve('buffer/'),
46
+ stream: require.resolve('stream-browserify')
47
+ }
48
+ }
49
+ })
50
+ .addModuleRule({
51
+ test: /\.(svg|png|wav|mp3|gif|jpg)$/,
52
+ resourceQuery: /^$/, // reject any query string
53
+ type: 'asset' // let webpack decide on the best type of asset
54
+ })
55
+ .addPlugin(new webpack.DefinePlugin({
56
+ 'process.env.DEBUG': Boolean(process.env.DEBUG),
57
+ 'process.env.GA_ID': `"${process.env.GA_ID || 'UA-000000-01'}"`,
58
+ 'process.env.GTM_ENV_AUTH': `"${process.env.GTM_ENV_AUTH || ''}"`,
59
+ 'process.env.GTM_ID': process.env.GTM_ID ? `"${process.env.GTM_ID}"` : null
60
+ }))
61
+ .addPlugin(new CopyWebpackPlugin({
62
+ patterns: [
63
+ {
64
+ from: '../../node_modules/scratch-blocks/media',
65
+ to: 'static/blocks-media/default'
66
+ },
67
+ {
68
+ from: '../../node_modules/scratch-blocks/media',
69
+ to: 'static/blocks-media/high-contrast'
70
+ },
71
+ {
72
+ // overwrite some of the default block media with high-contrast versions
73
+ // this entry must come after copying scratch-blocks/media into the high-contrast directory
74
+ from: 'src/lib/themes/high-contrast/blocks-media',
75
+ to: 'static/blocks-media/high-contrast',
76
+ force: true
77
+ },
78
+ {
79
+ context: '../../node_modules/@scratch/scratch-vm/dist/web',
80
+ from: 'extension-worker.{js,js.map}',
81
+ noErrorOnMissing: true
82
+ },
83
+ {
84
+ context: '../../node_modules/scratch-storage/dist/web',
85
+ from: 'chunks/fetch-worker.*.{js,js.map}',
86
+ noErrorOnMissing: true
87
+ }
88
+ ]
89
+ }));
90
+
91
+ if (!process.env.CI) {
92
+ baseConfig.addPlugin(new webpack.ProgressPlugin());
93
+ }
94
+
95
+ // build the shipping library in `dist/`
96
+ const distConfig = baseConfig.clone()
97
+ .merge({
98
+ entry: {
99
+ 'scratch-gui': path.join(__dirname, 'src/index.ts')
100
+ },
101
+ output: {
102
+ path: path.resolve(__dirname, 'dist')
103
+ }
104
+ })
105
+ .addExternals(['react', 'react-dom', 'redux', 'react-redux'])
106
+ .addPlugin(
107
+ new CopyWebpackPlugin({
108
+ patterns: [
109
+ {
110
+ from: 'src/lib/libraries/*.json',
111
+ to: 'libraries',
112
+ flatten: true
113
+ }
114
+ ]
115
+ })
116
+ );
117
+
118
+ // build the shipping library in `dist/` bundled with react, react-dom, redux, etc.
119
+ const distStandaloneConfig = baseConfig.clone()
120
+ .merge({
121
+ entry: {
122
+ 'scratch-gui-standalone': path.join(__dirname, 'src/index-standalone.tsx')
123
+ },
124
+ output: {
125
+ path: path.resolve(__dirname, 'dist')
126
+ }
127
+ });
128
+
129
+ // build the examples and debugging tools in `build/`
130
+ const buildConfig = baseConfig.clone()
131
+ .enableDevServer(process.env.PORT || 8601)
132
+ .merge({
133
+ entry: {
134
+ gui: './src/playground/index.jsx',
135
+ guistandalone: './src/playground/standalone.jsx',
136
+ blocksonly: './src/playground/blocks-only.jsx',
137
+ compatibilitytesting: './src/playground/compatibility-testing.jsx',
138
+ player: './src/playground/player.jsx'
139
+ },
140
+ output: {
141
+ path: path.resolve(__dirname, 'build'),
142
+
143
+ // This output is loaded using a file:// scheme from the local file system.
144
+ // Having `publicPath: '/'` (the default) means the `gui.js` file in `build/index.html`
145
+ // would be looked for at the root of the filesystem, which is incorrect.
146
+ // Hence, we're resetting the public path to be relative.
147
+ publicPath: ''
148
+ }
149
+ })
150
+ .addPlugin(new HtmlWebpackPlugin({
151
+ ...commonHtmlWebpackPluginOptions,
152
+ chunks: ['gui'],
153
+ template: 'src/playground/index.ejs',
154
+ title: 'Scratch 3.0 GUI'
155
+ }))
156
+ .addPlugin(new HtmlWebpackPlugin({
157
+ ...commonHtmlWebpackPluginOptions,
158
+ chunks: ['guistandalone'],
159
+ filename: 'standalone.html',
160
+ template: 'src/playground/index.ejs',
161
+ title: 'Scratch 3.0 GUI: Standalone Mode'
162
+ }))
163
+ .addPlugin(new HtmlWebpackPlugin({
164
+ ...commonHtmlWebpackPluginOptions,
165
+ chunks: ['blocksonly'],
166
+ filename: 'blocks-only.html',
167
+ template: 'src/playground/index.ejs',
168
+ title: 'Scratch 3.0 GUI: Blocks Only Example'
169
+ }))
170
+ .addPlugin(new HtmlWebpackPlugin({
171
+ ...commonHtmlWebpackPluginOptions,
172
+ chunks: ['compatibilitytesting'],
173
+ filename: 'compatibility-testing.html',
174
+ template: 'src/playground/index.ejs',
175
+ title: 'Scratch 3.0 GUI: Compatibility Testing'
176
+ }))
177
+ .addPlugin(new HtmlWebpackPlugin({
178
+ ...commonHtmlWebpackPluginOptions,
179
+ chunks: ['player'],
180
+ filename: 'player.html',
181
+ template: 'src/playground/index.ejs',
182
+ title: 'Scratch 3.0 GUI: Player Example'
183
+ }))
184
+ .addPlugin(new CopyWebpackPlugin({
185
+ patterns: [
186
+ {
187
+ from: 'static',
188
+ to: 'static'
189
+ },
190
+ {
191
+ from: 'extensions/**',
192
+ to: 'static',
193
+ context: 'src/examples'
194
+ }
195
+ ]
196
+ }));
197
+
198
+ // Skip building `dist/` unless explicitly requested
199
+ // It roughly doubles build time and isn't needed for `scratch-gui` development
200
+ // If you need non-production `dist/` for local dev, such as for `scratch-www` work, you can run something like:
201
+ // `BUILD_MODE=dist npm run build`
202
+ const buildDist = process.env.NODE_ENV === 'production' || process.env.BUILD_MODE === 'dist';
203
+
204
+ let config;
205
+ switch (process.env.BUILD_TYPE) {
206
+ case 'dist': config = distConfig.get(); break;
207
+ case 'dist-standalone': config = distStandaloneConfig.get(); break;
208
+ default: config = buildConfig.get(); break;
209
+ }
210
+
211
+ module.exports = buildDist ? config : buildConfig.get();