@24i/smartapps-bigscreen-rnv-build-engine 0.17.0 → 0.17.1-alpha.2054

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 (41) hide show
  1. package/README.md +3 -1
  2. package/dist/src/constants/platforms.js +1 -0
  3. package/dist/src/engine.js +5 -0
  4. package/dist/src/scripts/release/urlsMarkdown.js +1 -0
  5. package/dist/src/sdks/sdk-xbox/sdkXbox.js +1 -1
  6. package/dist/src/tasks/task.rnv.build.js +1 -0
  7. package/dist/src/tasks/task.rnv.configure.js +1 -0
  8. package/dist/src/tasks/task.rnv.deploy.js +1 -0
  9. package/dist/src/tasks/task.rnv.project.configure.js +1 -1
  10. package/dist/src/tasks/task.rnv.start.js +1 -0
  11. package/dist/templates/platforms/_shared/webpack.base.js +8 -8
  12. package/docs/PLATFORM_ADD.md +1 -1
  13. package/package.json +7 -7
  14. package/renative.engine.json +1 -0
  15. package/dist/src/__tests__/engine.spec.js +0 -57
  16. package/dist/src/__tests__/resolvers/resolveBaseUrl.spec.js +0 -99
  17. package/dist/src/__tests__/resolvers/resolveBuildFileExtension.spec.js +0 -26
  18. package/dist/src/__tests__/resolvers/resolveBuildFileName.spec.js +0 -89
  19. package/dist/src/__tests__/resolvers/resolveBuildVersion.spec.js +0 -50
  20. package/dist/src/__tests__/resolvers/resolveBuildVersionOffset.spec.js +0 -111
  21. package/dist/src/__tests__/resolvers/resolveDeployLocations.spec.js +0 -98
  22. package/dist/src/__tests__/resolvers/resolveGenericRnvConfig.spec.js +0 -92
  23. package/dist/src/__tests__/resolvers/resolveHbbtvDeployConfig.spec.js +0 -35
  24. package/dist/src/__tests__/resolvers/resolveHbbtvDeployUrl.spec.js +0 -41
  25. package/dist/src/__tests__/resolvers/resolveHbbtvRemoteBuildDirRelativePath.spec.js +0 -49
  26. package/dist/src/__tests__/resolvers/resolveSupportedPlatforms.spec.js +0 -22
  27. package/dist/src/__tests__/resolvers/resolveUsedFlavours.spec.js +0 -38
  28. package/dist/src/__tests__/resolvers/resolveZippedPlatformBuildsRelativeFilePath.spec.js +0 -18
  29. package/dist/src/__tests__/sdks/sdk-utils/registerSdkPath.spec.js +0 -60
  30. package/dist/src/__tests__/sdks/sdk-utils/sdk-installer/sdkInstaller.spec.js +0 -85
  31. package/dist/src/__tests__/sdks/sdk-utils/sdk-installer/services/clean.spec.js +0 -50
  32. package/dist/src/__tests__/sdks/sdk-utils/sdk-installer/services/download.spec.js +0 -103
  33. package/dist/src/__tests__/sdks/sdk-utils/sdk-installer/services/install.spec.js +0 -57
  34. package/dist/src/__tests__/sdks/sdk-utils/sdk-installer/services/unzip.spec.js +0 -51
  35. package/dist/src/__tests__/utils/forEachSupportedPlatformFlavour.spec.js +0 -104
  36. package/dist/src/__tests__/utils/generatePngSpriteMap.spec.js +0 -81
  37. package/dist/src/__tests__/utils/generateSvgSpriteMap.spec.js +0 -108
  38. package/dist/src/__tests__/utils/mergeSvgAndPngIcons.spec.js +0 -112
  39. package/dist/src/__tests__/utils/replaceRelevantStringsInConfig/replaceRelevantStringsInConfig.spec.js +0 -116
  40. package/dist/src/__tests__/utils/replaceRelevantStringsInConfig/replaceTemplateString.spec.js +0 -65
  41. package/dist/src/__tests__/utils/zipBuildsByPlatforms.spec.js +0 -69
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const childProcess = __importStar(require("child_process"));
27
- const services_1 = require("../../../../../sdks/sdk-utils/sdk-installer/services");
28
- jest.mock('child_process');
29
- describe('SDK Installer - Cleaner', () => {
30
- afterEach(() => {
31
- jest.clearAllMocks();
32
- });
33
- it('removes all dirs and files listed as paths in array', () => {
34
- childProcess.spawnSync.mockImplementationOnce(() => { });
35
- const spawnSyncSpy = jest.spyOn(childProcess, 'spawnSync');
36
- const pathsToClean = [
37
- '/path/to/dir1',
38
- '/path/to/dir2',
39
- '/path/to/file1.zip',
40
- '/path/to/file2.js',
41
- ];
42
- (0, services_1.clean)(pathsToClean);
43
- expect(spawnSyncSpy).toHaveBeenCalledTimes(pathsToClean.length);
44
- const [call0, call1, call2, call3] = spawnSyncSpy.mock.calls;
45
- expect(call0).toEqual(['rm', ['-r', '/path/to/dir1']]);
46
- expect(call1).toEqual(['rm', ['-r', '/path/to/dir2']]);
47
- expect(call2).toEqual(['rm', ['-r', '/path/to/file1.zip']]);
48
- expect(call3).toEqual(['rm', ['-r', '/path/to/file2.js']]);
49
- });
50
- });
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const stream_1 = __importDefault(require("stream"));
7
- const nock_1 = __importDefault(require("nock"));
8
- const http_1 = __importDefault(require("http"));
9
- const https_1 = __importDefault(require("https"));
10
- const fs_1 = __importDefault(require("fs"));
11
- const services_1 = require("../../../../../sdks/sdk-utils/sdk-installer/services");
12
- jest.mock('fs');
13
- fs_1.default.createWriteStream.mockImplementation(() => new stream_1.default.PassThrough());
14
- describe('SDK Installer - Downloader', () => {
15
- const HTTP_RESPONSE_STATUS_CODE_OK = 200;
16
- const HTTP_RESPONSE_STATUS_CODE_NOT_FOUND = 404;
17
- const httpBasePath = 'http://s3.amazonaws.com';
18
- const zipRelativeFilePath = '/file.zip';
19
- const zipFileHttpUrl = `${httpBasePath}${zipRelativeFilePath}`;
20
- const headersWithZipContentType = { 'Content-Type': 'application/zip' };
21
- const saveFilePath = `${process.cwd()}/test.zip`;
22
- const makeValidHttpNock = () => (0, nock_1.default)(httpBasePath)
23
- .get(zipRelativeFilePath)
24
- .reply(HTTP_RESPONSE_STATUS_CODE_OK, '', headersWithZipContentType);
25
- nock_1.default.disableNetConnect();
26
- afterEach(() => {
27
- jest.clearAllMocks();
28
- });
29
- afterAll(() => {
30
- nock_1.default.enableNetConnect();
31
- nock_1.default.cleanAll();
32
- nock_1.default.restore();
33
- });
34
- describe('Supported protocols', () => {
35
- it('calls http.get for URL with HTTP protocol', async () => {
36
- makeValidHttpNock();
37
- const getSpy = jest.spyOn(http_1.default, 'get');
38
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
39
- expect(getSpy).toBeCalledTimes(1);
40
- });
41
- it('calls https.get for URL with HTTPS protocol', async () => {
42
- (0, nock_1.default)(httpBasePath.replace('http:', 'https:'))
43
- .get(zipRelativeFilePath)
44
- .reply(HTTP_RESPONSE_STATUS_CODE_OK, '', headersWithZipContentType);
45
- const getSpy = jest.spyOn(https_1.default, 'get');
46
- await (0, services_1.download)(zipFileHttpUrl.replace('http:', 'https:'), saveFilePath);
47
- expect(getSpy).toBeCalledTimes(1);
48
- });
49
- it('throws an error when URL has unsupported protocol', async () => {
50
- await expect(async () => {
51
- await (0, services_1.download)('ftp://file.zip', saveFilePath);
52
- }).rejects.toThrow(new Error('ftp protocol is not supported'));
53
- });
54
- });
55
- describe('Handling response errors', () => {
56
- it('throws an error when returned content type is not application/zip', async () => {
57
- (0, nock_1.default)(httpBasePath)
58
- .get('/file.json')
59
- .reply(HTTP_RESPONSE_STATUS_CODE_OK, '', { 'Content-Type': 'application/json' });
60
- await expect(async () => {
61
- await (0, services_1.download)(`${httpBasePath}/file.json`, saveFilePath);
62
- }).rejects.toThrow(new Error('Wrong Content-Type: expected application/zip, received application/json'));
63
- (0, nock_1.default)(httpBasePath)
64
- .get(zipRelativeFilePath)
65
- .reply(HTTP_RESPONSE_STATUS_CODE_OK, '');
66
- await expect(async () => {
67
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
68
- }).rejects.toThrow(new Error('Missing Content-Type: expected application/zip'));
69
- });
70
- it('throws an error when request status is not 200', async () => {
71
- (0, nock_1.default)(httpBasePath)
72
- .get(zipRelativeFilePath)
73
- .reply(HTTP_RESPONSE_STATUS_CODE_NOT_FOUND, '', headersWithZipContentType);
74
- await expect(async () => {
75
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
76
- }).rejects.toThrow(new Error('Request Failed. Status Code: 404'));
77
- });
78
- });
79
- describe('Writing received data into a file', () => {
80
- beforeEach(() => {
81
- makeValidHttpNock();
82
- });
83
- it('Creates dest path if does not exist', async () => {
84
- const mkDirSync = jest.spyOn(fs_1.default, 'mkdirSync');
85
- fs_1.default.existsSync.mockImplementationOnce(() => false);
86
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
87
- expect(mkDirSync).toBeCalledTimes(1);
88
- expect(mkDirSync).toHaveBeenCalledWith(process.cwd(), { recursive: true });
89
- });
90
- it('Does not create dest path if path exists', async () => {
91
- const mkDirSync = jest.spyOn(fs_1.default, 'mkdirSync');
92
- fs_1.default.existsSync.mockImplementationOnce(() => true);
93
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
94
- expect(mkDirSync).toBeCalledTimes(0);
95
- });
96
- it('Calls write fn with dest param', async () => {
97
- const createWriteStream = jest.spyOn(fs_1.default, 'createWriteStream');
98
- await (0, services_1.download)(zipFileHttpUrl, saveFilePath);
99
- expect(createWriteStream).toBeCalledTimes(1);
100
- expect(createWriteStream).toHaveBeenCalledWith(saveFilePath);
101
- });
102
- });
103
- });
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const childProcess = __importStar(require("child_process"));
27
- const services_1 = require("../../../../../sdks/sdk-utils/sdk-installer/services");
28
- jest.mock('child_process');
29
- describe('SDK Installer - Installer', () => {
30
- childProcess.execSync.mockImplementation(() => '');
31
- afterEach(() => {
32
- jest.clearAllMocks();
33
- });
34
- describe('Calling external install.js script', () => {
35
- it('Calls with install.js path only when install path is not provided', () => {
36
- const execSyncSpy = jest.spyOn(childProcess, 'execSync');
37
- (0, services_1.install)('/install/from');
38
- expect(execSyncSpy).toHaveBeenCalledTimes(1);
39
- const params = execSyncSpy.mock.calls[0];
40
- const command = params[0];
41
- expect(command).toBe('node /install/from/install.js');
42
- });
43
- it('Calls with install path when it is provided', () => {
44
- const execSyncSpy = jest.spyOn(childProcess, 'execSync');
45
- (0, services_1.install)('/install/from', '/install/to');
46
- expect(execSyncSpy).toHaveBeenCalledTimes(1);
47
- const params = execSyncSpy.mock.calls[0];
48
- const command = params[0];
49
- expect(command).toBe('node /install/from/install.js /install/to');
50
- });
51
- });
52
- it('returns installed path', () => {
53
- childProcess.execSync.mockImplementationOnce(() => 'INSTALL_PATH=/sdk');
54
- const pathInstalledTo = (0, services_1.install)('/install/from');
55
- expect(pathInstalledTo).toBe('/sdk');
56
- });
57
- });
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const childProcess = __importStar(require("child_process"));
27
- const services_1 = require("../../../../../sdks/sdk-utils/sdk-installer/services");
28
- jest.mock('child_process');
29
- describe('SDK Installer - Unzipper', () => {
30
- childProcess.spawnSync.mockImplementation(() => ({ stderr: '' }));
31
- afterEach(() => {
32
- jest.clearAllMocks();
33
- });
34
- it('calls spawnSync with needed params', () => {
35
- const spawnSyncSpy = jest.spyOn(childProcess, 'spawnSync');
36
- (0, services_1.unzip)('/path/file.zip');
37
- expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
38
- const params = spawnSyncSpy.mock.calls[0];
39
- const command = params[0];
40
- expect(command).toBe('unzip');
41
- const args = params[1] || [];
42
- expect(args).not.toBeUndefined();
43
- expect(args.includes('/path/file.zip')).toBe(true);
44
- });
45
- it('throws an error when error occurs during unzipping', async () => {
46
- childProcess.spawnSync.mockImplementationOnce(() => ({ stderr: 'error' }));
47
- expect(() => {
48
- (0, services_1.unzip)('');
49
- }).toThrow(new Error('error'));
50
- });
51
- });
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const forEachSupportedPlatformFlavour_1 = require("../../utils/forEachSupportedPlatformFlavour");
4
- describe('forEachSupportedPlatformFlavour', () => {
5
- const originalConsoleLog = console.log;
6
- beforeEach(() => {
7
- console.log = jest.fn();
8
- });
9
- afterEach(() => {
10
- console.log = originalConsoleLog;
11
- jest.resetAllMocks();
12
- jest.clearAllMocks();
13
- jest.resetModules();
14
- });
15
- it('calls provided callback for each supported flavour', () => {
16
- const rnvC = {
17
- runtime: {
18
- scheme: 'scheme1',
19
- },
20
- buildConfig: {
21
- defaults: {
22
- supportedPlatforms: [
23
- 'webtv',
24
- 'tizen',
25
- 'webos',
26
- ],
27
- },
28
- platforms: {
29
- webtv: { deploy: { supportedFlavours: ['flavour1', 'flavour2'] } },
30
- tizen: { deploy: { supportedFlavours: ['flavour2', 'flavour3'] } },
31
- webos: { deploy: { supportedFlavours: ['flavour4'] } },
32
- hbbtv: { deploy: { supportedFlavours: ['flavour1', 'flavour2'] } },
33
- },
34
- },
35
- };
36
- const spyCb = jest.fn();
37
- (0, forEachSupportedPlatformFlavour_1.forEachSupportedPlatformFlavour)(rnvC, spyCb);
38
- expect(spyCb).toBeCalledTimes(5);
39
- expect(spyCb.mock.calls[0][0]).toStrictEqual({
40
- platform: 'webtv', flavour: 'flavour1', scheme: 'scheme1',
41
- });
42
- expect(spyCb.mock.calls[1][0]).toStrictEqual({
43
- platform: 'webtv', flavour: 'flavour2', scheme: 'scheme1',
44
- });
45
- expect(spyCb.mock.calls[2][0]).toStrictEqual({
46
- platform: 'tizen', flavour: 'flavour2', scheme: 'scheme1',
47
- });
48
- expect(spyCb.mock.calls[3][0]).toStrictEqual({
49
- platform: 'tizen', flavour: 'flavour3', scheme: 'scheme1',
50
- });
51
- expect(spyCb.mock.calls[4][0]).toStrictEqual({
52
- platform: 'webos', flavour: 'flavour4', scheme: 'scheme1',
53
- });
54
- });
55
- it('logs progress message', () => {
56
- const rnvC = {
57
- runtime: {
58
- scheme: 'scheme1',
59
- },
60
- buildConfig: {
61
- defaults: {
62
- supportedPlatforms: [
63
- 'tizen',
64
- 'webos',
65
- ],
66
- },
67
- platforms: {
68
- tizen: { deploy: { supportedFlavours: ['flavour1', 'flavour2'] } },
69
- webos: { deploy: { supportedFlavours: ['flavour1'] } },
70
- },
71
- },
72
- };
73
- const spyCb = jest.fn();
74
- const mockedLog = console.log;
75
- (0, forEachSupportedPlatformFlavour_1.forEachSupportedPlatformFlavour)(rnvC, spyCb);
76
- expect(mockedLog).toBeCalledTimes(3);
77
- expect(mockedLog.mock.calls[0][0]).toBe('\nProcessing "tizen" platform (1/2) and its "flavour1" flavour (1/2)...');
78
- expect(mockedLog.mock.calls[1][0]).toBe('\nProcessing "tizen" platform (1/2) and its "flavour2" flavour (2/2)...');
79
- expect(mockedLog.mock.calls[2][0]).toBe('\nProcessing "webos" platform (2/2) and its "flavour1" flavour (1/1)...');
80
- });
81
- it('not throws when supported flavour for platform are not defined', () => {
82
- const rnvC = {
83
- runtime: {
84
- scheme: 'scheme1',
85
- },
86
- buildConfig: {
87
- defaults: {
88
- supportedPlatforms: [
89
- 'tizen',
90
- 'webos',
91
- 'webtv',
92
- ],
93
- },
94
- platforms: {
95
- tizen: { deploy: {} },
96
- webos: {},
97
- },
98
- },
99
- };
100
- const spyCb = jest.fn();
101
- expect(() => (0, forEachSupportedPlatformFlavour_1.forEachSupportedPlatformFlavour)(rnvC, spyCb)).not.toThrow();
102
- expect(spyCb).toBeCalledTimes(0);
103
- });
104
- });
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const path_1 = __importDefault(require("path"));
8
- const generatePngSpriteMap_1 = require("../../utils/generatePngSpriteMap");
9
- const mockIconBase64 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEU0OkArMjhobHEoPUPFEBIuO0L+AAC2FBZ2JyuNICOfGx7xAwTjCAlCNTvVDA1aLzQ3COjMAAAAVUlEQVQI12NgwAaCDSA0888GCItjn0szWGBJTVoGSCjWs8TleQCQYV95evdxkFT8Kpe0PLDi5WfKd4LUsN5zS1sKFolt8bwAZrCaGqNYJAgFDEpQAAAzmxafI4vZWwAAAABJRU5ErkJggg==`';
10
- describe.skip('generatePngSpriteMap', () => {
11
- jest.setTimeout(60000);
12
- const originalConsoleLogFn = console.log;
13
- const projectDir = path_1.default.resolve(process.cwd(), 'temp_generatePngSpriteMap');
14
- const platformAssetsDir = path_1.default.resolve(projectDir, 'platformAssets');
15
- const runtimeDir = path_1.default.resolve(platformAssetsDir, 'runtime');
16
- const iconsDir = path_1.default.resolve(projectDir, 'icons');
17
- const rnvC = {
18
- runtime: {
19
- appId: 'appId',
20
- },
21
- platform: 'platform1',
22
- paths: {
23
- project: {
24
- dir: projectDir,
25
- builds: {
26
- dir: path_1.default.resolve(projectDir, 'platformBuilds'),
27
- },
28
- assets: {
29
- dir: platformAssetsDir,
30
- },
31
- },
32
- },
33
- buildConfig: {
34
- common: {
35
- pngIconPrefix: 'png-',
36
- },
37
- },
38
- };
39
- beforeEach(() => {
40
- fs_1.default.mkdirSync(iconsDir, { recursive: true });
41
- fs_1.default.mkdirSync(rnvC.paths.project.builds.dir, { recursive: true });
42
- fs_1.default.mkdirSync(runtimeDir, { recursive: true });
43
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'icon1.png'), mockIconBase64, 'base64');
44
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'icon2.png'), mockIconBase64, 'base64');
45
- fs_1.default.mkdirSync(path_1.default.resolve(iconsDir, 'inner'), { recursive: true });
46
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'inner/icon3.png'), mockIconBase64, 'base64');
47
- console.log = () => { };
48
- });
49
- afterEach(() => {
50
- fs_1.default.rmSync(projectDir, { recursive: true });
51
- console.log = originalConsoleLogFn;
52
- });
53
- it('generates png_icons.css and png_icons.json files', async () => {
54
- await (0, generatePngSpriteMap_1.generatePngSpriteMap)(rnvC);
55
- expect(fs_1.default.existsSync(path_1.default.resolve(runtimeDir, 'png_icons.css'))).toBeTruthy();
56
- expect(fs_1.default.existsSync(path_1.default.resolve(platformAssetsDir, 'png_icons.json'))).toBeTruthy();
57
- const outputJsonPath = path_1.default.resolve(platformAssetsDir, 'png_icons.json');
58
- expect(fs_1.default.existsSync(outputJsonPath)).toBe(true);
59
- const outputJsonContent = JSON.parse(fs_1.default.readFileSync(outputJsonPath).toString());
60
- expect(Object.keys(outputJsonContent)).toStrictEqual([
61
- 'png-icon1',
62
- 'png-icon2',
63
- 'png-icon3',
64
- ]);
65
- });
66
- it('remove empty files when nothing is generated', async () => {
67
- fs_1.default.rmSync(iconsDir, { recursive: true });
68
- fs_1.default.mkdirSync(iconsDir, { recursive: true });
69
- await (0, generatePngSpriteMap_1.generatePngSpriteMap)(rnvC);
70
- expect(fs_1.default.existsSync(path_1.default.resolve(runtimeDir, 'sprite.png'))).toBeFalsy();
71
- expect(fs_1.default.existsSync(path_1.default.resolve(runtimeDir, 'png_icons.css'))).toBeFalsy();
72
- expect(fs_1.default.existsSync(path_1.default.resolve(platformAssetsDir, 'png_icons.json'))).toBeFalsy();
73
- });
74
- it('no empty files when icons folder is not present', async () => {
75
- fs_1.default.rmSync(iconsDir, { recursive: true });
76
- await (0, generatePngSpriteMap_1.generatePngSpriteMap)(rnvC);
77
- expect(fs_1.default.existsSync(path_1.default.resolve(runtimeDir, 'sprite.png'))).toBeFalsy();
78
- expect(fs_1.default.existsSync(path_1.default.resolve(runtimeDir, 'png_icons.css'))).toBeFalsy();
79
- expect(fs_1.default.existsSync(path_1.default.resolve(platformAssetsDir, 'png_icons.json'))).toBeFalsy();
80
- });
81
- });
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const path_1 = __importDefault(require("path"));
8
- const child_process_1 = require("child_process");
9
- const generateSvgSpriteMap_1 = require("../../utils/generateSvgSpriteMap");
10
- describe('generateSvgSpriteMap', () => {
11
- const originalConsoleLogFn = console.log;
12
- const projectDir = path_1.default.resolve(process.cwd(), 'temp_generateSvgSpriteMap');
13
- const platformAssetsDir = path_1.default.resolve(projectDir, 'platformAssets');
14
- const runtimeDir = path_1.default.resolve(platformAssetsDir, 'runtime');
15
- const iconsDir = path_1.default.resolve(projectDir, 'icons');
16
- const svgoConfigPath = path_1.default.resolve(iconsDir, '.svgo.yml');
17
- const outputCssFilePath = path_1.default.resolve(runtimeDir, 'svg_icons.css');
18
- const outputJsonFilePath = path_1.default.resolve(platformAssetsDir, 'svg_icons.json');
19
- const rnvC = {
20
- runtime: {
21
- appId: 'appId',
22
- },
23
- platform: 'platform1',
24
- paths: {
25
- project: {
26
- dir: projectDir,
27
- builds: {
28
- dir: path_1.default.resolve(projectDir, 'platformBuilds'),
29
- },
30
- assets: {
31
- dir: platformAssetsDir,
32
- },
33
- },
34
- },
35
- buildConfig: {
36
- common: {
37
- svgIconsMaskList: [],
38
- svgIconPrefix: 'svg-',
39
- },
40
- },
41
- };
42
- beforeEach(() => {
43
- fs_1.default.mkdirSync(iconsDir, { recursive: true });
44
- fs_1.default.mkdirSync(rnvC.paths.project.builds.dir, { recursive: true });
45
- fs_1.default.mkdirSync(runtimeDir, { recursive: true });
46
- console.log = () => { };
47
- });
48
- afterEach(() => {
49
- fs_1.default.rmdirSync(projectDir, { recursive: true });
50
- console.log = originalConsoleLogFn;
51
- });
52
- it('should not generate any output when no icons are found', () => {
53
- (0, generateSvgSpriteMap_1.generateSvgSpriteMap)(rnvC);
54
- expect(fs_1.default.existsSync(outputCssFilePath)).toBeFalsy();
55
- expect(fs_1.default.existsSync(outputJsonFilePath)).toBeFalsy();
56
- });
57
- it('should not generate any output when no .svgo.yml is not found', () => {
58
- const svgData = '<svg viewBox="0 0 10 10"><circle cx="0" cy="0" r="10" fill="red" /></svg>';
59
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'icon1.svg'), svgData);
60
- (0, generateSvgSpriteMap_1.generateSvgSpriteMap)(rnvC);
61
- expect(fs_1.default.existsSync(outputCssFilePath)).toBeFalsy();
62
- expect(fs_1.default.existsSync(outputJsonFilePath)).toBeFalsy();
63
- });
64
- it('should not generate any output when no icons folder is not found', () => {
65
- (0, child_process_1.execSync)(`rm -rf ${iconsDir}`);
66
- (0, generateSvgSpriteMap_1.generateSvgSpriteMap)(rnvC);
67
- expect(fs_1.default.existsSync(outputCssFilePath)).toBeFalsy();
68
- expect(fs_1.default.existsSync(outputJsonFilePath)).toBeFalsy();
69
- });
70
- it('generates svg_icons.css and svg_icons.json when input icons are found', () => {
71
- fs_1.default.writeFileSync(svgoConfigPath, 'multipass: true');
72
- const svgData = '<svg viewBox="0 0 10 10"><circle cx="0" cy="0" r="10" fill="red" /></svg>';
73
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'icon1.svg'), svgData);
74
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'icon2.svg'), svgData);
75
- fs_1.default.mkdirSync(path_1.default.resolve(iconsDir, 'inner'), { recursive: true });
76
- fs_1.default.writeFileSync(path_1.default.resolve(iconsDir, 'inner/icon3.svg'), svgData);
77
- rnvC.buildConfig.common.svgIconsMaskList.push('icon1.svg');
78
- (0, generateSvgSpriteMap_1.generateSvgSpriteMap)(rnvC);
79
- rnvC.buildConfig.common.svgIconsMaskList.length = 0;
80
- expect(fs_1.default.existsSync(outputCssFilePath)).toBe(true);
81
- const outputCssContentRows = fs_1.default.readFileSync(outputCssFilePath).toString().split('\n');
82
- expect(outputCssContentRows).toHaveLength(15);
83
- expect(outputCssContentRows[0]).toBe('.icon-svg-icon1 {');
84
- expect(outputCssContentRows[1].startsWith(' background-image: url(')).toBe(true);
85
- expect(outputCssContentRows[2]).toBe('}');
86
- expect(outputCssContentRows[3]).toBe('');
87
- expect(outputCssContentRows[4]).toBe('.icon-mask-svg-icon1 {');
88
- expect(outputCssContentRows[5].startsWith(' -webkit-mask-image: url(')).toBe(true);
89
- expect(outputCssContentRows[6]).toBe('}');
90
- expect(outputCssContentRows[7]).toBe('');
91
- expect(outputCssContentRows[8]).toBe('.icon-svg-icon2 {');
92
- expect(outputCssContentRows[9].startsWith(' background-image: url(')).toBe(true);
93
- expect(outputCssContentRows[10]).toBe('}');
94
- expect(outputCssContentRows[11]).toBe('');
95
- expect(outputCssContentRows[12]).toBe('.icon-svg-icon3 {');
96
- expect(outputCssContentRows[13].startsWith(' background-image: url(')).toBe(true);
97
- expect(outputCssContentRows[14]).toBe('}');
98
- const outputJsonPath = path_1.default.resolve(platformAssetsDir, 'svg_icons.json');
99
- expect(fs_1.default.existsSync(outputJsonPath)).toBe(true);
100
- const outputJsonContent = JSON.parse(fs_1.default.readFileSync(outputJsonPath).toString());
101
- expect(outputJsonContent).toStrictEqual({
102
- 'svg-icon1': '',
103
- 'svg-icon2': '',
104
- 'svg-icon3': '',
105
- 'mask-svg-icon1': '',
106
- });
107
- });
108
- });