@24i/bigscreen-sdk 0.9.9-alpha.2148 → 0.9.9-alpha.2150

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 (80) hide show
  1. package/__mocks__/@24i/bigscreen-sdk/animations.ts +2 -0
  2. package/package.json +1 -1
  3. package/packages/animations/src/__mocks__/JSAnimations.ts +30 -0
  4. package/packages/conviva/src/__mocks__/ConvivaMock.ts +36 -0
  5. package/packages/developer-tools/src/DeveloperConsole/utils/formatTime.ts +13 -0
  6. package/packages/developer-tools/src/DeveloperConsole/utils/index.ts +3 -0
  7. package/packages/developer-tools/src/DeveloperConsole/utils/stringify.ts +10 -0
  8. package/packages/developer-tools/src/DeveloperConsole/utils/styles.ts +24 -0
  9. package/packages/developer-tools/src/EnvironmentSelection/utils/format.ts +4 -0
  10. package/packages/developer-tools/src/TechnicalInfo/__mocks__/Device.ts +51 -0
  11. package/packages/developer-tools/src/TechnicalInfo/__mocks__/Player.ts +7 -0
  12. package/packages/developer-tools/src/TechnicalInfo/__mocks__/Storage.ts +9 -0
  13. package/packages/developer-tools/src/TechnicalInfo/utils/eme01bSupport.ts +58 -0
  14. package/packages/developer-tools/src/TechnicalInfo/utils/emeSupport.ts +80 -0
  15. package/packages/developer-tools/src/TechnicalInfo/utils/formatTimezone.ts +15 -0
  16. package/packages/developer-tools/src/TechnicalInfo/utils/mseSupport.ts +14 -0
  17. package/packages/developer-tools/src/utils/reload.ts +6 -0
  18. package/packages/driver-base/src/__mocks__/DeviceBase.ts +100 -0
  19. package/packages/driver-base/src/__mocks__/keyMap.ts +41 -0
  20. package/packages/driver-entone/src/__mocks__/entone.ts +177 -0
  21. package/packages/driver-hbbtv/src/__mocks__/hbbtv.ts +17 -0
  22. package/packages/driver-kreatv/src/__mocks__/toi2.ts +76 -0
  23. package/packages/driver-kreatv/src/__mocks__/toi3.ts +43 -0
  24. package/packages/driver-saphi/src/__mocks__/SmartTvA_API.ts +11 -0
  25. package/packages/driver-saphi/src/__mocks__/userAgent.ts +4 -0
  26. package/packages/driver-tizen/src/__mocks__/tizen.ts +35 -0
  27. package/packages/driver-webos/src/__mocks__/webos.ts +172 -0
  28. package/packages/driver-xbox/src/__mocks__/Windows.ts +94 -0
  29. package/packages/gallup/src/__mocks__/SpringStreams.js +18 -0
  30. package/packages/input/__mocks__/MockKeyboard.ts +40 -0
  31. package/packages/keyboard/src/utils/caret.ts +48 -0
  32. package/packages/keyboard/src/utils/generateFocusMatrixFromStringMatrix.ts +12 -0
  33. package/packages/keyboard/src/utils/input.ts +40 -0
  34. package/packages/list/utils/index.ts +1 -0
  35. package/packages/logger/src/__mocks__/LoggerBase.ts +13 -0
  36. package/packages/logger/src/utils/deviceInfo.ts +25 -0
  37. package/packages/logger/src/utils/index.ts +1 -0
  38. package/packages/utils/README.md +336 -0
  39. package/packages/utils/src/addClass.ts +9 -0
  40. package/packages/utils/src/counter.ts +47 -0
  41. package/packages/utils/src/debounce.ts +54 -0
  42. package/packages/utils/src/displayToggler.scss +3 -0
  43. package/packages/utils/src/displayToggler.ts +38 -0
  44. package/packages/utils/src/elementUtils.ts +58 -0
  45. package/packages/utils/src/generateUuid.ts +19 -0
  46. package/packages/utils/src/index.ts +35 -0
  47. package/packages/utils/src/memoryInfo.ts +21 -0
  48. package/packages/utils/src/nTimes.ts +9 -0
  49. package/packages/utils/src/noop.ts +1 -0
  50. package/packages/utils/src/offsetPosition.ts +56 -0
  51. package/packages/utils/src/removeClass.ts +9 -0
  52. package/packages/utils/src/scaledImage.ts +21 -0
  53. package/packages/utils/src/stopEvent.ts +10 -0
  54. package/packages/utils/src/timeConstants.ts +11 -0
  55. package/packages/utils/src/timers/createInterval.ts +19 -0
  56. package/packages/utils/src/timers/createTimeout.ts +22 -0
  57. package/packages/utils/src/timers/index.ts +4 -0
  58. package/packages/utils/src/timers/runAsync.ts +3 -0
  59. package/packages/utils/src/timers/types.ts +9 -0
  60. package/packages/utils/src/wait.ts +1 -0
  61. package/packages/utils/src/xhr/__mocks__/xhr.ts +29 -0
  62. package/packages/utils/src/xhr/index.ts +11 -0
  63. package/packages/utils/src/xhr/xhrSend.ts +139 -0
  64. package/packages/utils/src/xhr/xhrSendRetry.ts +77 -0
  65. package/packages/volume-control/src/__mocks__/VolumeControlUIMock.tsx +18 -0
  66. package/utils/create-export-maps/index.ts +3 -0
  67. package/utils/create-export-maps/src/__tests__/createExportMaps.spec.ts +50 -0
  68. package/utils/create-export-maps/src/createExportMaps.ts +61 -0
  69. package/utils/create-package/README.md +40 -0
  70. package/utils/create-package/src/createPackage.ts +72 -0
  71. package/utils/create-package/src/index.ts +3 -0
  72. package/utils/create-package/src/questionnaire/questions.ts +19 -0
  73. package/utils/create-package/src/settings/Settings.ts +5 -0
  74. package/utils/create-package/src/types.ts +4 -0
  75. package/utils/create-package/templates/typescript/README.md +9 -0
  76. package/utils/create-package/templates/typescript/exports.json +6 -0
  77. package/utils/create-package/templates/typescript/src/index.ts +0 -0
  78. package/utils/run-scripts/index.ts +3 -0
  79. package/utils/run-scripts/src/__tests__/runScripts.spec.ts +45 -0
  80. package/utils/run-scripts/src/runScripts.ts +20 -0
@@ -0,0 +1,61 @@
1
+ import { resolve } from 'path';
2
+ import * as fs from 'fs';
3
+ import packageJson from '../../../package.json';
4
+
5
+ const packagesPath = resolve('./packages');
6
+
7
+ const allExports: Record<string, string> = {};
8
+
9
+ type ExportsDefinition = {
10
+ name: string,
11
+ entryPoints: Record<string, string>,
12
+ };
13
+
14
+ const handleExport = ({ name, entryPoints }: ExportsDefinition) => {
15
+ let hasRootExport = false;
16
+ Object.entries(entryPoints).forEach(([exportAlias, exportPath]) => {
17
+ if (exportAlias === '/') {
18
+ hasRootExport = true;
19
+ return;
20
+ }
21
+ const parsedAlias = `/${exportAlias}`;
22
+ allExports[`${name}${parsedAlias}`] = `${name}/${exportPath}`;
23
+ });
24
+ /**
25
+ * Typescript resolves aliases from top. Root export would overtake any other pathed export.
26
+ * Therefore root export has to be last in the generated list.
27
+ */
28
+ if (hasRootExport) {
29
+ allExports[name] = `${name}/${entryPoints['/']}`;
30
+ }
31
+ };
32
+
33
+ const loadAllExports = () => {
34
+ const fileNames = fs.readdirSync(packagesPath);
35
+ fileNames.forEach((fileName) => {
36
+ const packagePath = resolve(packagesPath, fileName);
37
+ const isDirectory = fs.lstatSync(packagePath).isDirectory();
38
+ if (isDirectory) {
39
+ const exportsPath = resolve(packagePath, 'exports.json');
40
+ if (fs.existsSync(exportsPath)) {
41
+ // eslint-disable-next-line import/no-dynamic-require, global-require
42
+ const exports = require(exportsPath);
43
+ handleExport(exports);
44
+ }
45
+ }
46
+ });
47
+ };
48
+
49
+ const createPackageJsonMapping = () => {
50
+ const exports: Record<string, string> = {};
51
+ Object.entries(allExports).forEach(([exportAlias, exportPath]) => {
52
+ exports[`./${exportAlias}`] = `./packages/${exportPath}`;
53
+ });
54
+ (packageJson.exports as Record<string, string>) = exports;
55
+ fs.writeFileSync(resolve('./package.json'), JSON.stringify(packageJson, null, 4));
56
+ };
57
+
58
+ export const createExportMaps = () => {
59
+ loadAllExports();
60
+ createPackageJsonMapping();
61
+ };
@@ -0,0 +1,40 @@
1
+ ---
2
+ id: README
3
+ title: Create Package
4
+ hide_title: true
5
+ sidebar_label: Create Package
6
+ ---
7
+
8
+ # Package Initializer
9
+ An initializer for packages in `SmartApps BIGscreen SDK` monorepo helps to set up
10
+ folder structure with basic config files like eslint, tsconfig etc.
11
+
12
+ ## Usage
13
+ Originally designed as [npm initializer](https://docs.npmjs.com/cli/init#description),
14
+ now degraded to the local script without any ambition to be published.
15
+
16
+ Go to SmartApps BIGscreen SDK monorepo root folder and type:
17
+ ```
18
+ $ npm run create-package -- <my-package-name>
19
+ ```
20
+ You will be prompted for basic package information.
21
+
22
+ ## What it does
23
+ 1. Create folder `./packages/<my-package-name>`
24
+ 2. Guide you through a questionnaire to setup the project
25
+ * e.g. auto-suggested 24i package name in form: `@24i/smartapps-bigscreenen-<my-package-name>`
26
+ 3. Copy the template files (src, tsconfig, eslintrc, jest.config, readme, etc.)
27
+ 4. Generate package.json with all the project details
28
+ 5. Create symlink in docs `./docs/packages/<my-package-name>/README.md`
29
+
30
+ ## Motivation
31
+ Every time that I start a new package inside SmartApps BIGscreen SDK monorepo, I hate
32
+ to go to other project folder, copy files like eslintrc, tsconfig, create folder
33
+ structure, etc.
34
+
35
+ With this in mind, the motivation to build this package started as a DRY (Do not
36
+ repeat yourself) thing.
37
+
38
+ This package is intended to automate the initialization of new packages and with
39
+ this have a new folder with everything ready to work. Behind this, also to ensure
40
+ we are using the unified setup for each package inside SmartApps BIGscreen SDK monorepo.
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as path from 'path';
4
+ import * as fs from 'fs';
5
+ import * as fse from 'fs-extra';
6
+ import chalk from 'chalk';
7
+ import minimist from 'minimist';
8
+ import { promptPackageDetails } from './questionnaire/questions';
9
+ import { Settings } from './settings/Settings';
10
+ import { IPackageOptions } from './types';
11
+
12
+ async function isDirectoryEmpty(dirPath: string) {
13
+ const files = await fs.promises.readdir(dirPath);
14
+ return !files.length;
15
+ }
16
+
17
+ async function copyTemplateFiles(templateDir: string, targetDir: string) {
18
+ return fse.copy(templateDir, targetDir);
19
+ }
20
+
21
+ function updateExportsJsonFile(filePath: string, options: IPackageOptions) {
22
+ let data = fs.readFileSync(filePath, 'utf8');
23
+ data = data.replace(/("name": ")(.*)(")/, `$1${options.name}$3`);
24
+ fs.writeFileSync(filePath, data);
25
+ }
26
+
27
+ function parseArguments(rawArgv: Array<string>) {
28
+ const argv = minimist(rawArgv.slice(2));
29
+ const dirName = argv._[0];
30
+
31
+ if (!dirName) {
32
+ console.error('Error: Missing package name');
33
+ process.exit(1);
34
+ }
35
+
36
+ return {
37
+ dirName,
38
+ };
39
+ }
40
+
41
+ export async function main() {
42
+ const { dirName: destDirName } = parseArguments(process.argv);
43
+ const destDir = path.join(process.cwd(), 'packages/', destDirName);
44
+ if (fs.existsSync(destDir)) {
45
+ console.error(`Error: Target directory "${destDir}" already exists`);
46
+ process.exit(1);
47
+ }
48
+ fs.mkdirSync(destDir, { recursive: true });
49
+
50
+ const isDirEmpty = await isDirectoryEmpty(destDir);
51
+ if (!isDirEmpty) {
52
+ console.error(`Error: Target directory "${destDir}" is not empty.`);
53
+ process.exit(1);
54
+ }
55
+
56
+ const settings = { ...Settings };
57
+ settings.name = `${Settings.name}${destDirName}`.toLowerCase();
58
+
59
+ const details = await promptPackageDetails(settings);
60
+ const templateDir = path.join(__dirname, '..', 'templates/typescript');
61
+
62
+ await copyTemplateFiles(templateDir, destDir);
63
+ const exportsJsonFile = path.join(destDir, 'exports.json');
64
+ updateExportsJsonFile(exportsJsonFile, details);
65
+
66
+ // create symlink in docs to README.md
67
+ const docsSymlinkTarget = path.join('../../../packages/', destDirName, '/README.md');
68
+ const docsSymlinkPath = path.join(process.cwd(), 'docs/packages/', destDirName, '/README.md');
69
+ await fse.ensureSymlink(docsSymlinkTarget, docsSymlinkPath);
70
+
71
+ console.log(`${chalk.green('Success')}, package has been initialized!`);
72
+ }
@@ -0,0 +1,3 @@
1
+ import { main } from './createPackage';
2
+
3
+ main();
@@ -0,0 +1,19 @@
1
+ import * as inquirer from 'inquirer';
2
+
3
+ interface IPromptPackageDetailsDefaults {
4
+ /** Package name */
5
+ name: string;
6
+ }
7
+
8
+ async function promptPackageDetails(defaultValues: IPromptPackageDetailsDefaults) {
9
+ return inquirer.prompt([
10
+ {
11
+ type: 'input',
12
+ name: 'name',
13
+ message: 'Package name:',
14
+ default: defaultValues.name,
15
+ },
16
+ ]);
17
+ }
18
+
19
+ export { promptPackageDetails };
@@ -0,0 +1,5 @@
1
+ const Settings = {
2
+ name: '',
3
+ };
4
+
5
+ export { Settings };
@@ -0,0 +1,4 @@
1
+ export interface IPackageOptions {
2
+ /** Package name */
3
+ name: string;
4
+ }
@@ -0,0 +1,9 @@
1
+ ---
2
+ id: README
3
+ title: My Package Title
4
+ hide_title: true
5
+ sidebar_label: My Package Title
6
+ ---
7
+
8
+ # My Package Title
9
+ Auto-generated SmartApps BIGscreen readme file
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "xxx",
3
+ "entryPoints": {
4
+ "/": "src/index.ts"
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ import { runScripts } from './src/runScripts';
2
+
3
+ runScripts();
@@ -0,0 +1,45 @@
1
+ import { execSync } from 'child_process';
2
+ import { runScripts } from '../runScripts';
3
+
4
+ jest.mock('../../../../package.json', () => ({
5
+ scripts: {
6
+ 'scripts:prepare:create-export-maps': 'ts-node ./utils/create-export-maps/index.ts',
7
+ 'scripts:run:test2': 'ts-node ./utils/test2.ts',
8
+ 'scripts:run:test1': 'ts-node ./utils/test1.ts',
9
+ },
10
+ }));
11
+
12
+ jest.mock('child_process', () => ({
13
+ execSync: jest.fn(),
14
+ }));
15
+
16
+ describe('runScripts', () => {
17
+ const argvBackup = process.argv;
18
+
19
+ afterEach(() => {
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ afterAll(() => {
24
+ process.argv = argvBackup;
25
+ });
26
+
27
+ it('should not run anything if no script found', () => {
28
+ process.argv = ['node', 'run-scripts/index.ts', 'build:.+'];
29
+ runScripts();
30
+ expect(execSync).not.toHaveBeenCalled();
31
+ });
32
+
33
+ it('should run found script', () => {
34
+ process.argv = ['node', 'run-scripts/index.ts', 'prepare:.+'];
35
+ runScripts();
36
+ expect(execSync).toHaveBeenCalledWith('npm run scripts:prepare:create-export-maps');
37
+ });
38
+
39
+ it('should run found scripts in order they are in package.json', () => {
40
+ process.argv = ['node', 'run-scripts/index.ts', 'run:.+'];
41
+ runScripts();
42
+ expect(execSync).toHaveBeenNthCalledWith(1, 'npm run scripts:run:test2');
43
+ expect(execSync).toHaveBeenNthCalledWith(2, 'npm run scripts:run:test1');
44
+ });
45
+ });
@@ -0,0 +1,20 @@
1
+ import { execSync } from 'child_process';
2
+ import { scripts } from '../../../package.json';
3
+
4
+ /**
5
+ * Runs all npm scripts from package.json that match given regexp.
6
+ * RegExp is passed as the 1st param.
7
+ */
8
+ export const runScripts = () => {
9
+ const matcher = new RegExp(process.argv[2] ?? '');
10
+ const scriptsToRun = Object.keys(scripts).filter((script) => script.match(matcher));
11
+ scriptsToRun.forEach((script) => {
12
+ console.log(`Running npm run ${script}`);
13
+ try {
14
+ execSync(`npm run ${script}`);
15
+ } catch (e) {
16
+ console.error((e as Error).message);
17
+ process.exit(1);
18
+ }
19
+ });
20
+ };