wjec-one 4.0.0-alpha.9 → 4.0.0

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 (51) hide show
  1. package/auth/index.d.ts +130 -41
  2. package/auth/index.js +1 -1
  3. package/config/babel.config.js +62 -0
  4. package/config/eslint-config.js +224 -0
  5. package/config/jest.config.js +77 -0
  6. package/config/tsconfig.json +52 -0
  7. package/config/webpack.config.js +237 -0
  8. package/index.d.ts +383 -233
  9. package/index.js +1 -1
  10. package/localization/index.d.ts +32 -30
  11. package/localization/index.js +1 -1
  12. package/package.json +65 -75
  13. package/portal/index.d.ts +270 -0
  14. package/portal/index.js +1 -0
  15. package/scripts/bin/wjec-one-scripts.js +44 -0
  16. package/scripts/build.js +54 -0
  17. package/scripts/check-config.js +46 -0
  18. package/scripts/check-tests.js +93 -0
  19. package/scripts/config/babel.config.js +29 -0
  20. package/scripts/config/webpack.standalone.config.js +119 -0
  21. package/scripts/init.js +91 -0
  22. package/scripts/standalone.js +28 -0
  23. package/scripts/start.js +25 -0
  24. package/scripts/test.js +78 -0
  25. package/services/index.d.ts +14 -14
  26. package/services/index.js +1 -1
  27. package/store/index.d.ts +9 -9
  28. package/store/index.js +1 -1
  29. package/store/utils/index.d.ts +2 -23
  30. package/test/assetsTransformer.ts +7 -0
  31. package/test/index.d.ts +106 -0
  32. package/test/index.js +1 -0
  33. package/test/index.ts +182 -0
  34. package/test/setupTests.ts +76 -0
  35. package/test/setupTestsAfterEnv.ts +47 -0
  36. package/test/svgTransformer.tsx +3 -0
  37. package/test/wjecOneMocks.ts +247 -0
  38. package/theme/index.d.ts +23 -24
  39. package/theme/index.js +1 -1
  40. package/umd/auth/index.js +1 -1
  41. package/umd/index.js +1 -1
  42. package/umd/localization/index.js +1 -1
  43. package/umd/portal/index.js +1 -0
  44. package/umd/services/index.js +1 -1
  45. package/umd/store/index.js +1 -1
  46. package/umd/test/index.js +1 -0
  47. package/umd/theme/index.js +1 -1
  48. package/umd/utils/index.js +1 -1
  49. package/utils/index.d.ts +49 -53
  50. package/utils/index.js +1 -1
  51. package/wjec-one-project.d.ts +74 -0
@@ -0,0 +1,77 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const appPath = fs.realpathSync(process.cwd());
5
+ const scriptsPath = path.resolve(__dirname, '..');
6
+
7
+ const { overrides = {} } = require(path.join(appPath, 'package.json'));
8
+ const coverageThreshold = overrides.coverageThreshold === undefined ? 100 : overrides.coverageThreshold;
9
+
10
+ module.exports = {
11
+ collectCoverageFrom: [
12
+ 'auth/**/*.{ts,tsx}',
13
+ 'localization/**/*.{ts,tsx}',
14
+ 'portal/**/*.{ts,tsx}',
15
+ 'services/**/*.{ts,tsx}',
16
+ 'src/**/*.{ts,tsx}',
17
+ 'store/**/*.{ts,tsx}',
18
+ 'theme/**/*.{ts,tsx}',
19
+ 'utils/**/*.{ts,tsx}',
20
+
21
+ '!**/*.d.ts',
22
+ '!localization/index.ts',
23
+ '!portal/index.ts',
24
+ '!portal/**/store/state.{ts,tsx}',
25
+ '!services/index.ts',
26
+ '!src/ColorPalette*.ts',
27
+ '!src/components/**/styles.{ts,tsx}',
28
+ '!src/StylePalette.ts',
29
+ '!src/styles',
30
+ '!test/**/*',
31
+ '!theme/index.ts',
32
+ '!theme/ThemeContext.ts',
33
+ '!theme/ThemeState.ts',
34
+ '!theme/utils.ts',
35
+ '!**/types',
36
+ '!types.ts',
37
+ '!utils/index.ts',
38
+ '!utils/ConfigUtils.ts'
39
+ ],
40
+ coverageReporters: ['cobertura', 'json', 'text'],
41
+ coverageThreshold: {
42
+ global: {
43
+ branches: coverageThreshold,
44
+ functions: coverageThreshold,
45
+ lines: coverageThreshold,
46
+ statements: coverageThreshold
47
+ }
48
+ },
49
+ coverageDirectory: '../test-coverage',
50
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
51
+ moduleNameMapper: {
52
+ '\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': overrides.setupTests ? path.join(scriptsPath, 'test/assetsTransformer.ts') : '<rootDir>/test/assetsTransformer.ts',
53
+ '\\.svg': overrides.setupTests ? path.join(scriptsPath, 'test/svgTransformer.tsx') : '<rootDir>/test/svgTransformer.tsx',
54
+ '^src/(.&)$': '<rootDir>/src/$1'
55
+ },
56
+ modulePaths: [overrides.setupTests ? './' : '<rootDir>'],
57
+ modulePathIgnorePatterns: ['./lib', 'dist'],
58
+ roots: [
59
+ '<rootDir>'
60
+ ],
61
+ rootDir: overrides.setupTests ? appPath : '../',
62
+ setupFiles: [
63
+ overrides.setupTests ? path.join(scriptsPath, 'test/setupTests.ts') : '<rootDir>/test/setupTests.ts'
64
+ ],
65
+ setupFilesAfterEnv: overrides.setupTests ? [path.join(scriptsPath, 'test/setupTestsAfterEnv.ts')] : [],
66
+ snapshotSerializers: overrides.setupTests ? [] : ['@emotion/jest/serializer'],
67
+ testEnvironment: 'jsdom',
68
+ testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
69
+ transform: {
70
+ '^.+\\.tsx?$|wjec-one': 'ts-jest'
71
+ },
72
+ transformIgnorePatterns: ['/node_modules/(?!(wjec-one/*)/)'],
73
+ reporters: [
74
+ 'default',
75
+ ['jest-junit', { outputDirectory: './test-results' }]
76
+ ]
77
+ };
@@ -0,0 +1,52 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "baseUrl": "../",
5
+ "declaration": true,
6
+ "declarationDir": "../temp/dts",
7
+ "downlevelIteration": true,
8
+ "esModuleInterop": true,
9
+ "jsx": "react",
10
+ "lib": ["es5", "es6", "es2019", "es2022", "dom"],
11
+ "module": "ESNext",
12
+ "moduleResolution": "node",
13
+ "noImplicitAny": true,
14
+ "outDir": "../temp",
15
+ "paths": {
16
+ "auth": ["auth"],
17
+ "localization": ["localization"],
18
+ "portal": ["portal"],
19
+ "root": [""],
20
+ "services": ["services"],
21
+ "src/*": ["src/*"],
22
+ "store": ["store"],
23
+ "test": ["test"],
24
+ "theme": ["theme"],
25
+ "utils": ["utils"],
26
+
27
+ "wjec-one": [""],
28
+ "wjec-one/auth": ["auth"],
29
+ "wjec-one/localization": ["localization"],
30
+ "wjec-one/portal": ["portal"],
31
+ "wjec-one/services": ["services"],
32
+ "wjec-one/store": ["store"],
33
+ "wjec-one/test": ["test"],
34
+ "wjec-one/theme": ["theme"],
35
+ "wjec-one/utils": ["utils"]
36
+ },
37
+ "plugins": [
38
+ { "transform": "typescript-transform-paths", },
39
+ {
40
+ "transform": "typescript-transform-paths",
41
+ "afterDeclarations": true
42
+ }
43
+ ],
44
+ "resolveJsonModule": true,
45
+ "skipLibCheck": true,
46
+ "sourceMap": true,
47
+ "target": "ESNext",
48
+ "types": ["jest", "node", "resize-observer-browser"]
49
+ },
50
+ "include": ["../global-types/*.d.ts", "../src/**/*", "../portal/**/*", "../utils/*", "../store/**/*", "../services/*", "../localization/*", "../theme/*", "../auth/*", "../"],
51
+ "exclude": ["../node_modules", "../dist", "../temp", "../scripts"]
52
+ }
@@ -0,0 +1,237 @@
1
+ const path = require('path');
2
+ const babelConfig = require('./babel.config');
3
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
5
+ const CopyWebpackPlugin = require('copy-webpack-plugin');
6
+ const fs = require('fs');
7
+ const webpack = require('webpack');
8
+
9
+ const isProjectEnv = /node_modules[\\/]wjec-one[\\/]?$/.test(path.join(fs.realpathSync(__dirname), '../'));
10
+
11
+ const appPath = path.join(fs.realpathSync(__dirname), isProjectEnv ? '../../../' : '../');
12
+ const scriptsPath = path.resolve(__dirname, '..');
13
+
14
+ const config = isProjectEnv ? require(path.join(appPath, 'config/config.json')) : null;
15
+ const { overrides = {}, version } = isProjectEnv ? require(path.join(appPath, 'package.json')) : {};
16
+ const devServerHost = overrides.devServerHost || 'localhost';
17
+ const devServerPort = overrides.devServerPort === undefined ? 9001 : overrides.devServerPort;
18
+
19
+ const currentTimestamp = Date.now();
20
+
21
+ const generateFilename = () => {
22
+ let suffix = overrides.filenameSuffix;
23
+
24
+ switch (suffix) {
25
+ case 'buildId':
26
+ suffix = process.env.BITBUCKET_BUILD_NUMBER;
27
+ break;
28
+ case 'currentTimestamp':
29
+ suffix = currentTimestamp;
30
+ break;
31
+ case 'version':
32
+ suffix = getVersionNumber();
33
+ break;
34
+ }
35
+
36
+ return suffix
37
+ ? `[name].${suffix}.js`
38
+ : '[name].js';
39
+ };
40
+
41
+ const getVersionNumber = () => {
42
+ const { property, source } = overrides.versionNumberSource || { property: 'version', source: 'package' };
43
+
44
+ switch (source) {
45
+ case 'env':
46
+ return process.env[property];
47
+ case 'config':
48
+ return config[property];
49
+ default:
50
+ return version;
51
+ }
52
+ };
53
+
54
+ const projectEnvPlugins = [
55
+ new CopyWebpackPlugin({
56
+ patterns: [
57
+ ...fs.readdirSync(path.join(appPath, 'config')).map((fileName) => ({
58
+ from: path.join(appPath, 'config', fileName),
59
+ to: 'config'
60
+ }))
61
+ ].filter((e) => e)}),
62
+ new webpack.DefinePlugin({
63
+ 'process.env.NODE_DEBUG': JSON.stringify(process.env.NODE_DEBUG),
64
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
65
+ }),
66
+ new ForkTsCheckerWebpackPlugin({
67
+ typescript: {
68
+ configFile: path.join(scriptsPath, 'config/tsconfig.json')
69
+ }
70
+ }),
71
+ new HtmlWebpackPlugin({
72
+ template: path.join(appPath, 'index.html'),
73
+ filename: './index.html',
74
+ tsconfig: path.join(scriptsPath, 'config/tsconfig.json')
75
+ })
76
+ ];
77
+
78
+ const projectEnvAliases = {
79
+ config: path.join(appPath, 'config'),
80
+ src: path.join(appPath, 'src'),
81
+ test: path.join(appPath, 'test')
82
+ };
83
+
84
+ const wjecOnePlugins = [
85
+ new ForkTsCheckerWebpackPlugin({
86
+ typescript: {
87
+ configFile: `${__dirname}/tsconfig.json`
88
+ }
89
+ }),
90
+ new HtmlWebpackPlugin({
91
+ template: 'scratchpad/index.html',
92
+ tsconfig: `${__dirname}/tsconfig.json`
93
+ })
94
+ // new webpack.HotModuleReplacementPlugin()
95
+ ];
96
+
97
+ const wjecOneAliases = {
98
+ auth: path.resolve(__dirname, '../auth'),
99
+ demo: path.resolve(__dirname, '../demo'),
100
+ localization: path.resolve(__dirname, '../localization'),
101
+ portal: path.resolve(__dirname, '../portal'),
102
+ root: path.resolve(__dirname, '../'),
103
+ services: path.resolve(__dirname, '../services'),
104
+ src: path.resolve(__dirname, '../src'),
105
+ store: path.resolve(__dirname, '../store'),
106
+ test: path.resolve(__dirname, '../test'),
107
+ theme: path.resolve(__dirname, '../theme'),
108
+ utils: path.resolve(__dirname, '../utils'),
109
+
110
+ 'wjec-one': path.resolve(__dirname, '../'),
111
+ 'wjec-one/auth': path.resolve(__dirname, '../auth'),
112
+ 'wjec-one/localization': path.resolve(__dirname, '../localization'),
113
+ 'wjec-one/portal': path.resolve(__dirname, '../portal'),
114
+ 'wjec-one/services': path.resolve(__dirname, '../services'),
115
+ 'wjec-one/store': path.resolve(__dirname, '../store'),
116
+ 'wjec-one/test': path.resolve(__dirname, '../test'),
117
+ 'wjec-one/theme': path.resolve(__dirname, '../theme'),
118
+ 'wjec-one/utils': path.resolve(__dirname, '../utils')
119
+ }
120
+
121
+ const getDevConfig = (mode) => ({
122
+ context: scriptsPath,
123
+ devServer: {
124
+ host: devServerHost === 'localIp' ? '0.0.0.0' : devServerHost,
125
+ port: devServerPort,
126
+ https: false,
127
+ historyApiFallback: true,
128
+ static: {
129
+ directory: path.join(__dirname, './'),
130
+ staticOptions: { redirect: false }
131
+ }
132
+ },
133
+ devtool: mode === 'production' ? undefined : 'inline-source-map',
134
+ entry: isProjectEnv ? { index: `${appPath}/index.tsx`} : `${__dirname}/../scratchpad/scratchpad.tsx`,
135
+ mode,
136
+ module: {
137
+ rules: [{
138
+ exclude: /node_modules/,
139
+ loader: 'babel-loader',
140
+ options: babelConfig,
141
+ test: /\.(js|jsx|ts|tsx)$/
142
+ },
143
+ {
144
+ test: /\.mjs$/,
145
+ include: /node_modules/,
146
+ type: 'javascript/auto'
147
+ },
148
+ {
149
+ test: /\.(png|jp(e*)g)$/,
150
+ use: [{
151
+ loader: 'url-loader',
152
+ options: {
153
+ limit: 5000000,
154
+ name: 'images/[name].[ext]'
155
+ }
156
+ }]
157
+ },
158
+ {
159
+ test: /\.svg$/,
160
+ use: [{
161
+ loader: '@svgr/webpack',
162
+ options: {
163
+ dimensions: false,
164
+ ref: true,
165
+ replaceAttrValues: {
166
+ '#000': 'currentColor',
167
+ '#2D3538': 'currentColor',
168
+ '#2E3638': 'currentColor'
169
+ },
170
+ svgoConfig: {
171
+ plugins: [{
172
+ name: 'preset-default',
173
+ params: {
174
+ overrides: {
175
+ removeViewBox: false
176
+ }
177
+ }
178
+ }]
179
+ },
180
+ svgProps: {
181
+ xmlns: 'http://www.w3.org/2000/svg'
182
+ }
183
+ }
184
+ }]
185
+ },
186
+ {
187
+ type: 'javascript/auto',
188
+ test: /config\/*\.json$/,
189
+ exclude: /node_modules/,
190
+ use: {
191
+ loader: 'file-loader',
192
+ options: {
193
+ name: './config/[name].json',
194
+ publicPath: '../'
195
+ }
196
+ }
197
+ },
198
+ {
199
+ test: /\.(ttf|eot|woff|woff2)$/,
200
+ use: {
201
+ loader: 'file-loader',
202
+ options: {
203
+ name: './fonts/[name].[ext]',
204
+ publicPath: '../'
205
+ }
206
+ }
207
+ }
208
+ ]
209
+ },
210
+ optimization: {
211
+ usedExports: true
212
+ },
213
+ output: isProjectEnv ? {
214
+ chunkFilename: generateFilename(),
215
+ filename: generateFilename(),
216
+ path: path.join(appPath, 'dist'),
217
+ publicPath: '/'
218
+ } : {
219
+ filename: 'scratchpad.js',
220
+ path: path.resolve(__dirname, './'),
221
+ publicPath: '/'
222
+ },
223
+ plugins: isProjectEnv ? projectEnvPlugins : wjecOnePlugins,
224
+ resolve: {
225
+ fallback: {
226
+ 'stream': require.resolve('stream-browserify'),
227
+ 'process': require.resolve('process')
228
+ },
229
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.json'],
230
+ alias: isProjectEnv ? projectEnvAliases : wjecOneAliases
231
+ }
232
+ });
233
+
234
+
235
+ module.exports = (_env, { mode }) => {
236
+ return getDevConfig(mode);
237
+ };