@movable/rollup-plugin-manifest-merger 3.0.0-canvases.0 → 3.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 (76) hide show
  1. package/.eslintrc.js +2 -3
  2. package/build/src/index.js +12 -0
  3. package/build/src/plugins/manifest-merger.js +110 -0
  4. package/build/src/plugins/studio-index-builder.js +38 -0
  5. package/build/src/types/packages.js +2 -0
  6. package/build/src/utils/default-package-index.html +34 -0
  7. package/build/src/utils/index-js-builder.js +121 -0
  8. package/build/test/helpers/expect-ast-equals.js +13 -0
  9. package/build/test/helpers/setup-fixture.js +18 -0
  10. package/build/test/index-test.js +57 -0
  11. package/build/test/plugins/manifest-merger-test.js +96 -0
  12. package/build/test/utils/index-js-builder-test.js +64 -0
  13. package/package.json +32 -36
  14. package/src/index.ts +5 -0
  15. package/src/plugins/manifest-merger.ts +154 -0
  16. package/src/plugins/studio-index-builder.ts +40 -0
  17. package/src/types/packages.ts +6 -0
  18. package/src/utils/default-package-index.html +34 -0
  19. package/src/utils/index-js-builder.ts +171 -0
  20. package/test/.eslintrc.js +2 -1
  21. package/test/fixtures/{test-app → test-app-no-integration-ids}/app-manifest.yml +2 -0
  22. package/test/fixtures/{test-app → test-app-no-integration-ids}/index.js +2 -2
  23. package/test/fixtures/test-app-no-integration-ids/node_modules/@movable-internal/test-dep/index.js +1 -0
  24. package/test/fixtures/test-app-no-integration-ids/node_modules/@movable-internal/test-dep/package-manifest.yml +3 -0
  25. package/test/fixtures/test-app-no-integration-ids/node_modules/@movable-internal/test-dep/package.json +3 -0
  26. package/test/fixtures/test-app-no-integration-ids/package.json +5 -0
  27. package/test/fixtures/test-app-with-app-and-package-integration-ids/app-manifest.yml +12 -0
  28. package/test/fixtures/test-app-with-app-and-package-integration-ids/index.js +9 -0
  29. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep/index.js +1 -0
  30. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep/package-manifest.yml +7 -0
  31. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep/package.json +3 -0
  32. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep-2/index.js +1 -0
  33. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep-2/package-manifest.yml +7 -0
  34. package/test/fixtures/test-app-with-app-and-package-integration-ids/node_modules/@movable-internal/test-dep-2/package.json +3 -0
  35. package/test/fixtures/test-app-with-app-and-package-integration-ids/package.json +6 -0
  36. package/test/fixtures/test-app-with-app-integration-ids/app-manifest.yml +12 -0
  37. package/test/fixtures/test-app-with-app-integration-ids/index.js +7 -0
  38. package/test/fixtures/test-app-with-app-integration-ids/node_modules/@movable-internal/test-dep/index.js +1 -0
  39. package/test/fixtures/test-app-with-app-integration-ids/node_modules/@movable-internal/test-dep/package-manifest.yml +3 -0
  40. package/test/fixtures/test-app-with-app-integration-ids/node_modules/@movable-internal/test-dep/package.json +3 -0
  41. package/test/fixtures/test-app-with-app-integration-ids/package.json +5 -0
  42. package/test/fixtures/test-package/node_modules/@movable/studio-framework/index.js +1 -0
  43. package/test/fixtures/test-package/node_modules/@movable/studio-framework/package.json +4 -0
  44. package/test/fixtures/test-package/package-manifest.yml +3 -0
  45. package/test/fixtures/test-package/package.json +12 -0
  46. package/test/fixtures/test-package/src/index.js +3 -0
  47. package/test/fixtures/test-package/src/random-file.js +1 -0
  48. package/test/fixtures/test-package/test-app-manifest.yml +5 -0
  49. package/test/helpers/expect-ast-equals.ts +14 -0
  50. package/test/helpers/setup-fixture.ts +15 -0
  51. package/test/index-test.ts +62 -0
  52. package/test/plugins/manifest-merger-test.ts +108 -0
  53. package/test/utils/index-js-builder-test.ts +75 -0
  54. package/tsconfig.json +13 -0
  55. package/.babelrc +0 -24
  56. package/.eslintignore +0 -3
  57. package/.prettierrc.js +0 -5
  58. package/TODO.md +0 -41
  59. package/index.d.ts +0 -11
  60. package/src/index.js +0 -64
  61. package/src/merger.js +0 -33
  62. package/test/fixtures/js/app-manifest.js +0 -24
  63. package/test/fixtures/js/merged-manifest.js +0 -159
  64. package/test/fixtures/js/olapic-manifest.js +0 -140
  65. package/test/fixtures/js/retail-manifest.js +0 -69
  66. package/test/fixtures/test-app/node_modules/test-dep/main.js +0 -2
  67. package/test/fixtures/test-app/node_modules/test-dep/package-manifest.yml +0 -4
  68. package/test/fixtures/test-app/node_modules/test-dep/package.json +0 -4
  69. package/test/fixtures/test-app/package.json +0 -5
  70. package/test/fixtures/test-dist/bundle.js +0 -6
  71. package/test/fixtures/test-dist/manifest.json +0 -1
  72. package/test/fixtures/yml/app-manifest.yml +0 -25
  73. package/test/fixtures/yml/olapic-manifest.yml +0 -67
  74. package/test/fixtures/yml/retail-manifest.yml +0 -65
  75. package/test/index-test.js +0 -123
  76. package/test/plugin-test.js +0 -75
package/.eslintrc.js CHANGED
@@ -1,12 +1,11 @@
1
+ /* eslint-env node */
1
2
  module.exports = {
2
- extends: ['airbnb-base', 'plugin:prettier/recommended'],
3
- plugins: [],
3
+ extends: ['@movable/eslint-config-typescript'],
4
4
  parserOptions: {
5
5
  ecmaVersion: 2018,
6
6
  sourceType: 'module'
7
7
  },
8
8
  env: {
9
- browser: false,
10
9
  node: true
11
10
  }
12
11
  };
@@ -0,0 +1,12 @@
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
+ exports.inputFile = exports.manifestMerger = exports.packageBuilder = void 0;
7
+ const studio_index_builder_1 = require("./plugins/studio-index-builder");
8
+ Object.defineProperty(exports, "packageBuilder", { enumerable: true, get: function () { return studio_index_builder_1.packageBuilder; } });
9
+ const manifest_merger_1 = __importDefault(require("./plugins/manifest-merger"));
10
+ exports.manifestMerger = manifest_merger_1.default;
11
+ const inputFile = studio_index_builder_1.INPUT_FILE;
12
+ exports.inputFile = inputFile;
@@ -0,0 +1,110 @@
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 pluginutils_1 = require("@rollup/pluginutils");
7
+ const yamljs_1 = __importDefault(require("yamljs"));
8
+ const resolve_1 = __importDefault(require("resolve"));
9
+ const pkg_dir_1 = __importDefault(require("pkg-dir"));
10
+ const fs_1 = require("fs");
11
+ const APP_FILTER = pluginutils_1.createFilter(/app-manifest\.yml$/);
12
+ const PACKAGE_FILTER = pluginutils_1.createFilter(/\.yml$/);
13
+ function manifestMerger(opts) {
14
+ const fileName = opts.output;
15
+ const outputJSON = !!opts.outputJSON;
16
+ const shouldUpdateFrameworkVersion = !opts.ignoreFrameworkVersionUpdate;
17
+ let appManifest;
18
+ const studioFrameworkPath = resolve_1.default.sync('@movable/studio-framework', { basedir: process.cwd() });
19
+ const frameworkPkgPath = `${pkg_dir_1.default.sync(studioFrameworkPath)}/package.json`;
20
+ const studioFrameworkPkg = require(frameworkPkgPath);
21
+ const pathPackageMap = new Map();
22
+ const packageDependencies = [
23
+ { name: '@movable/studio-framework', version: studioFrameworkPkg.version }
24
+ ];
25
+ const packageCache = new Map();
26
+ return {
27
+ name: 'Studio Manifest Merger Rollup Plugin',
28
+ buildStart() {
29
+ if (opts.appManifest) {
30
+ this.addWatchFile(opts.appManifest);
31
+ appManifest = yamljs_1.default.parse(fs_1.readFileSync(opts.appManifest).toString('utf-8'));
32
+ }
33
+ },
34
+ buildEnd() {
35
+ if (!appManifest) {
36
+ throw new Error('There was no app-manifest.yml imported. You may provide a "appManifest" to the "manifestBundler()" options');
37
+ }
38
+ },
39
+ resolveId(id) {
40
+ if (!APP_FILTER(id) && PACKAGE_FILTER(id)) {
41
+ const path = resolve_1.default.sync(id, { basedir: process.cwd() });
42
+ const importRoot = pkg_dir_1.default.sync(path);
43
+ const pkg = require(`${importRoot}/package.json`);
44
+ pathPackageMap.set(path, pkg.name);
45
+ this.addWatchFile(path);
46
+ return path;
47
+ }
48
+ },
49
+ transform(yml, id) {
50
+ const noCode = {
51
+ code: '',
52
+ map: { mappings: '' }
53
+ };
54
+ if (APP_FILTER(id)) {
55
+ appManifest = yamljs_1.default.parse(yml);
56
+ return noCode;
57
+ }
58
+ if (PACKAGE_FILTER(id)) {
59
+ const packageManifest = yamljs_1.default.parse(yml);
60
+ const name = pathPackageMap.get(id);
61
+ if (name) {
62
+ packageManifest.name = name;
63
+ }
64
+ else {
65
+ throw new Error(`Could not determine the package name for file: ${id}. Make sure that "nodeResolve()" is placed after "manifestMerger()"`);
66
+ }
67
+ packageCache.set(id, packageManifest);
68
+ return noCode;
69
+ }
70
+ return null;
71
+ },
72
+ generateBundle() {
73
+ // Make sure the studio_options key is present
74
+ if (!appManifest.studio_options)
75
+ appManifest.studio_options = {};
76
+ if (shouldUpdateFrameworkVersion) {
77
+ // Add the framework version to studio_options
78
+ appManifest.studio_options.framework_version = studioFrameworkPkg.version;
79
+ appManifest.studio_options.package_dependencies = packageDependencies;
80
+ }
81
+ // Add the package manifests to the array
82
+ const manifests = [];
83
+ const integrationIds = [...(appManifest.integration_ids || [])];
84
+ for (const [, val] of packageCache.entries()) {
85
+ if (Array.isArray(val.integration_ids)) {
86
+ integrationIds.push(...val.integration_ids);
87
+ }
88
+ manifests.push(val);
89
+ }
90
+ appManifest.package_manifests = manifests;
91
+ if (integrationIds.length) {
92
+ appManifest.integration_ids = [...new Set(integrationIds)];
93
+ }
94
+ if (fileName) {
95
+ const inline = 12; // The level where you switch to inline YAML
96
+ const indent = 2; // The amount of spaces to use for indentation of nested nodes.
97
+ const source = outputJSON
98
+ ? JSON.stringify(appManifest)
99
+ : yamljs_1.default.stringify(appManifest, inline, indent);
100
+ // eslint-disable-next-line no-param-reassign
101
+ this.emitFile({
102
+ type: 'asset',
103
+ fileName,
104
+ source
105
+ });
106
+ }
107
+ }
108
+ };
109
+ }
110
+ exports.default = manifestMerger;
@@ -0,0 +1,38 @@
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
+ exports.packageBuilder = exports.INPUT_FILE = void 0;
7
+ const uuid_1 = require("uuid");
8
+ const index_js_builder_1 = __importDefault(require("../utils/index-js-builder"));
9
+ const fs_1 = require("fs");
10
+ const path_1 = __importDefault(require("path"));
11
+ exports.INPUT_FILE = `${uuid_1.v4()}.js`;
12
+ function packageBuilder(opts) {
13
+ const pkg = JSON.parse(fs_1.readFileSync('./package.json').toString('utf-8'));
14
+ const indexHtmlSource = fs_1.readFileSync(path_1.default.join(__dirname, '../utils/default-package-index.html')).toString('utf-8');
15
+ return {
16
+ name: 'Studio Package Builder Rollup Plugin',
17
+ resolveId(id) {
18
+ if (id === exports.INPUT_FILE) {
19
+ return id;
20
+ }
21
+ return null;
22
+ },
23
+ async load(id) {
24
+ if (id === exports.INPUT_FILE) {
25
+ return index_js_builder_1.default(pkg, opts.entry);
26
+ }
27
+ return null;
28
+ },
29
+ generateBundle() {
30
+ this.emitFile({
31
+ type: 'asset',
32
+ fileName: 'index.html',
33
+ source: indexHtmlSource
34
+ });
35
+ }
36
+ };
37
+ }
38
+ exports.packageBuilder = packageBuilder;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="movable-cli-version" value="1.0.0">
6
+ <meta name="studio-bundled" value="true">
7
+ <meta name="cp-version" value="0">
8
+ <!-- DO NOT MODIFY -->
9
+ </head>
10
+
11
+ <body>
12
+
13
+ <div id="react-root"></div>
14
+
15
+ <!-- MI WYSIWYG: DO NOT MODIFY CODE BEYOND THIS POINT. This code is auto-generated by Studio and will be overwritten -->
16
+
17
+ <div style="display: none;" class="mi-attributes">[]</div>
18
+ <!-- END MI WYSIWYG -->
19
+
20
+ <script>
21
+ // Your code should set window.APP_SUCCESSFULLY_RENDERED to true once it
22
+ // has completed successfully.
23
+ window.APP_SUCCESSFULLY_RENDERED = false;
24
+
25
+ window.addEventListener('capture-ready', function () {
26
+ if (!window.APP_SUCCESSFULLY_RENDERED) {
27
+ MICapture.error('Did not capture as app did not indicate that it was ready for capture. (Checking window.APP_SUCCESSFULLY_RENDERED)');
28
+ }
29
+ });
30
+ </script>
31
+
32
+ <script src="./dist/index.js"></script>
33
+ </body>
34
+ </html>
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const recast_1 = require("recast");
4
+ const { builders: b } = recast_1.types;
5
+ const BASE = `
6
+ import StudioFramework from '@movable/studio-framework';
7
+
8
+ export default class App extends StudioFramework {
9
+ setup() {}
10
+ }
11
+
12
+ const app = new App();
13
+
14
+ app.render(document.getElementById('react-root')).then(() => {
15
+ window.APP_SUCCESSFULLY_RENDERED = true;
16
+ });
17
+ `;
18
+ function defaultPackageName(packageName) {
19
+ return `_${packageName.replace(/[^A-Za-z0-9]/g, '_')}`;
20
+ }
21
+ /**
22
+ * Generates an Import statement
23
+ *
24
+ * ex: `import _my_package from "my-package";
25
+ *
26
+ * @param packageName {string} the unique name of the package
27
+ * @param variableName {string} the variable name of the default package import
28
+ */
29
+ function makePackageImport(packageName, variableName) {
30
+ const importFrom = b.literal(packageName);
31
+ const defaultImportSpecifier = b.importDefaultSpecifier(b.identifier(variableName));
32
+ return b.importDeclaration([defaultImportSpecifier], importFrom);
33
+ }
34
+ /**
35
+ * Generates a plain import statement.
36
+ *
37
+ * ex: `import "my-package/manifest.yml";`
38
+ *
39
+ * @param packageName {string} the name of the file to be imported
40
+ */
41
+ function makePlainPackageImport(importName) {
42
+ const importFrom = b.literal(importName);
43
+ return b.importDeclaration([], importFrom);
44
+ }
45
+ /**
46
+ * Creates an expression that looks up the `setGrouping` method:
47
+ *
48
+ * ex: `this.setGrouping`
49
+ */
50
+ function setGroupingMember() {
51
+ const thisExpression = b.thisExpression();
52
+ const setGrouping = b.identifier('setGrouping');
53
+ return b.memberExpression(thisExpression, setGrouping);
54
+ }
55
+ /**
56
+ * Creates an initialization function with the given function name
57
+ *
58
+ * ex: `packageInitFuncName(this)`
59
+ *
60
+ * @param packageInitializationFunctionName {string} the package initialization function
61
+ */
62
+ function makeStandardInitalizeStatement(packageInitializationFunctionName) {
63
+ const packageInitializationFunctionID = b.identifier(packageInitializationFunctionName);
64
+ const packageInitialization = b.callExpression(packageInitializationFunctionID, [
65
+ b.thisExpression()
66
+ ]);
67
+ return b.expressionStatement(packageInitialization);
68
+ }
69
+ /**
70
+ * Creates a statement to call `setGrouping` with the package name and initialization function:
71
+ *
72
+ * ex: `this.setGrouping("my-package", () => { initilizationFn(this); })`
73
+ *
74
+ * @param packageName {string} the unique name of the package
75
+ * @param packageInitializationFunctionName {string} the package initialization function
76
+ */
77
+ function makeSetGroupingStatement(packageName, packageInitializationFunctionName) {
78
+ const packageNameArg = b.literal(packageName);
79
+ const initStatement = makeStandardInitalizeStatement(packageInitializationFunctionName);
80
+ const anonymousFn = b.arrowFunctionExpression([], b.blockStatement([initStatement]));
81
+ const memberExpression = setGroupingMember();
82
+ const callExpression = b.callExpression(memberExpression, [packageNameArg, anonymousFn]);
83
+ return b.expressionStatement(callExpression);
84
+ }
85
+ function makeRelativeImport(path) {
86
+ return path.startsWith('./') ? path : `./${path}`;
87
+ }
88
+ function generateImports(pkg, entryPath) {
89
+ const { name, ['studio-package']: studioPackage } = pkg;
90
+ const setups = [];
91
+ const imports = [];
92
+ const variableName = defaultPackageName(name);
93
+ const relativeEntry = makeRelativeImport(entryPath);
94
+ imports.push(makePackageImport(relativeEntry.replace(/\.js$/, ''), variableName));
95
+ if (studioPackage && studioPackage.manifest) {
96
+ const relativeManifest = makeRelativeImport(studioPackage.manifest);
97
+ imports.push(makePlainPackageImport(relativeManifest));
98
+ }
99
+ setups.push(makeSetGroupingStatement(name, variableName));
100
+ return [imports, setups];
101
+ }
102
+ function generateApp(pkg, entryPath) {
103
+ const app = recast_1.parse(BASE);
104
+ const [imports, setups] = generateImports(pkg, entryPath);
105
+ const BODY = app.program.body;
106
+ // Add imports after the StudioFrameworkImport
107
+ BODY.splice(1, 0, ...imports);
108
+ // Insert the "setups" into the setup method:
109
+ recast_1.visit(app, {
110
+ visitBlockStatement(path) {
111
+ const parentValue = path.parent.parent.value;
112
+ if (parentValue.type === 'MethodDefinition' && parentValue.key.name === 'setup') {
113
+ path.value.body.push(...setups);
114
+ return false;
115
+ }
116
+ this.traverse(path);
117
+ }
118
+ });
119
+ return recast_1.prettyPrint(app, { tabWidth: 2 }).code;
120
+ }
121
+ exports.default = generateApp;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const recast_1 = require("recast");
5
+ function printAst(ast) {
6
+ return recast_1.prettyPrint(ast, { tabWidth: 2 }).code;
7
+ }
8
+ function expectAstEqual(compareFrom, compareTo) {
9
+ const astA = recast_1.parse(compareFrom);
10
+ const astB = recast_1.parse(compareTo);
11
+ chai_1.expect(printAst(astA)).to.eq(printAst(astB));
12
+ }
13
+ exports.default = expectAstEqual;
@@ -0,0 +1,18 @@
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 mocha_1 = require("mocha");
7
+ const path_1 = __importDefault(require("path"));
8
+ function setupFixture(fixtureName) {
9
+ const previousCWD = process.cwd();
10
+ mocha_1.beforeEach(() => {
11
+ const fixturePath = path_1.default.join(__dirname, '../fixtures', fixtureName);
12
+ process.chdir(fixturePath);
13
+ });
14
+ mocha_1.afterEach(() => {
15
+ process.chdir(previousCWD);
16
+ });
17
+ }
18
+ exports.default = setupFixture;
@@ -0,0 +1,57 @@
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 mocha_1 = require("mocha");
7
+ const chai_1 = require("chai");
8
+ const rollup_1 = require("rollup");
9
+ const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
10
+ const yamljs_1 = __importDefault(require("yamljs"));
11
+ const index_1 = require("../src/index");
12
+ const setup_fixture_1 = __importDefault(require("./helpers/setup-fixture"));
13
+ mocha_1.describe('test', () => {
14
+ setup_fixture_1.default('test-package');
15
+ mocha_1.it('can bundle based on an index', async () => {
16
+ const bundle = await rollup_1.rollup({
17
+ input: index_1.inputFile,
18
+ plugins: [
19
+ index_1.packageBuilder({ entry: 'src/index.js' }),
20
+ index_1.manifestMerger({ output: 'manifest.yml', appManifest: 'test-app-manifest.yml' }),
21
+ plugin_node_resolve_1.default()
22
+ ]
23
+ });
24
+ const { output } = await bundle.generate({
25
+ format: 'es'
26
+ });
27
+ const javascript = output.find(({ fileName }) => fileName === index_1.inputFile);
28
+ const yaml = output.find(({ fileName }) => fileName === 'manifest.yml');
29
+ const html = output.find(({ fileName }) => fileName === 'index.html');
30
+ // @ts-ignore
31
+ chai_1.expect(javascript.code).to.contain('test-package');
32
+ // @ts-ignore
33
+ chai_1.expect(javascript.code).to.contain('src/random-file');
34
+ // @ts-ignore
35
+ chai_1.expect(javascript.code).to.contain('@movable/studio-framework');
36
+ // @ts-ignore
37
+ chai_1.expect(html.source).to.contain(`<div style="display: none;" class="mi-attributes">[]</div>`);
38
+ // @ts-ignore
39
+ const manifest = yamljs_1.default.parse(yaml.source);
40
+ chai_1.expect(manifest).to.deep.eq({
41
+ name: 'Test App Manifest',
42
+ authors: ['Foo'],
43
+ height: 400,
44
+ width: 600,
45
+ package_manifests: [
46
+ {
47
+ authors: ['Test Developer'],
48
+ name: 'test-package'
49
+ }
50
+ ],
51
+ studio_options: {
52
+ framework_version: '2.34.0',
53
+ package_dependencies: [{ name: '@movable/studio-framework', version: '2.34.0' }]
54
+ }
55
+ });
56
+ });
57
+ });
@@ -0,0 +1,96 @@
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 mocha_1 = require("mocha");
7
+ const chai_1 = require("chai");
8
+ const rollup_1 = require("rollup");
9
+ const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
10
+ const yamljs_1 = __importDefault(require("yamljs"));
11
+ const index_1 = require("../../src/index");
12
+ const setup_fixture_1 = __importDefault(require("../helpers/setup-fixture"));
13
+ const studioFrameworkPkg = require('@movable/studio-framework/package.json');
14
+ const expectedAppManifest = {
15
+ name: 'App Manifest',
16
+ options: [{ name: 'Option 2' }, { framework_version: '1.10.0' }],
17
+ string_array: ['one', 'two', 'three'],
18
+ package_manifests: [
19
+ {
20
+ name: '@movable-internal/test-dep',
21
+ authors: ['Test Developer']
22
+ }
23
+ ],
24
+ studio_options: {
25
+ framework_version: studioFrameworkPkg.version,
26
+ package_dependencies: [
27
+ { name: '@movable/studio-framework', version: studioFrameworkPkg.version }
28
+ ]
29
+ }
30
+ };
31
+ const bundledManifest = async ({ outputJSON = true, ignoreFrameworkVersionUpdate = false } = {}) => {
32
+ const outputFile = outputJSON ? 'manifest.json' : 'manifest.yml';
33
+ const bundle = await rollup_1.rollup({
34
+ input: 'index.js',
35
+ plugins: [
36
+ index_1.manifestMerger({
37
+ outputJSON,
38
+ output: outputFile,
39
+ ignoreFrameworkVersionUpdate
40
+ }),
41
+ plugin_node_resolve_1.default()
42
+ ]
43
+ });
44
+ const { output } = await bundle.generate({
45
+ format: 'es'
46
+ });
47
+ const file = output.find(({ fileName }) => fileName === outputFile);
48
+ // @ts-ignore
49
+ return outputJSON ? JSON.parse(file.source) : yamljs_1.default.parse(file.source);
50
+ };
51
+ mocha_1.describe('manifestMerger - app test', async () => {
52
+ setup_fixture_1.default('test-app-no-integration-ids');
53
+ mocha_1.it('can build the manifest via dependencies with yml output', async () => {
54
+ const manifest = await bundledManifest({ outputJSON: false });
55
+ chai_1.expect(manifest).to.deep.equal(expectedAppManifest);
56
+ });
57
+ mocha_1.it('can optionally ignore the actual Studio Framework version', async () => {
58
+ const manifest = await bundledManifest({
59
+ outputJSON: false,
60
+ ignoreFrameworkVersionUpdate: true
61
+ });
62
+ chai_1.expect(manifest).to.deep.equal({
63
+ ...expectedAppManifest,
64
+ studio_options: { framework_version: '2.15' }
65
+ });
66
+ mocha_1.it('can build the manifest via dependencies with json output', async () => {
67
+ const manifest = await bundledManifest();
68
+ chai_1.expect(manifest).to.deep.equal(expectedAppManifest);
69
+ });
70
+ });
71
+ mocha_1.it('can build the manifest via dependencies', async () => {
72
+ const manifest = await bundledManifest();
73
+ chai_1.expect(manifest).to.deep.equal(expectedAppManifest);
74
+ });
75
+ });
76
+ mocha_1.describe('manifest merger - integration ids', () => {
77
+ mocha_1.describe('app with existing ids / dependencies with ids', () => {
78
+ setup_fixture_1.default('test-app-with-app-and-package-integration-ids');
79
+ mocha_1.it('it can build multiple integration ids from multiple packages', async () => {
80
+ const manifest = await bundledManifest();
81
+ chai_1.expect(manifest.integration_ids).to.have.members(['app-123', '123', 'abc', 'foo', 'bar']);
82
+ });
83
+ mocha_1.it('it does not duplicate appManifest.integration_ids upon regeneration', async () => {
84
+ await bundledManifest();
85
+ const manifest = await bundledManifest();
86
+ chai_1.expect(manifest.integration_ids).to.have.members(['app-123', '123', 'abc', 'foo', 'bar']);
87
+ });
88
+ });
89
+ mocha_1.describe('app with existing ids / dependencies with no ids', () => {
90
+ setup_fixture_1.default('test-app-with-app-integration-ids');
91
+ mocha_1.it('it can build integration ids with no package integration ids', async () => {
92
+ const manifest = await bundledManifest();
93
+ chai_1.expect(manifest.integration_ids).to.have.members(['app-123']);
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,64 @@
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 mocha_1 = require("mocha");
7
+ const index_js_builder_1 = __importDefault(require("../../src/utils/index-js-builder"));
8
+ const expect_ast_equals_1 = __importDefault(require("../helpers/expect-ast-equals"));
9
+ mocha_1.describe('app template builder', () => {
10
+ mocha_1.it('imports package when `studio-package` present', () => {
11
+ const app = index_js_builder_1.default({
12
+ name: 'my-package',
13
+ version: '1.3.4',
14
+ main: 'src/index.js'
15
+ }, 'src/index.js');
16
+ expect_ast_equals_1.default(app, `
17
+ import StudioFramework from '@movable/studio-framework';
18
+ import _my_package from './src/index';
19
+
20
+ export default class App extends StudioFramework {
21
+ setup() {
22
+ this.setGrouping('my-package', () => {
23
+ _my_package(this)
24
+ });
25
+ }
26
+ }
27
+
28
+ const app = new App();
29
+
30
+ app.render(document.getElementById('react-root')).then(() => {
31
+ window.APP_SUCCESSFULLY_RENDERED = true;
32
+ });
33
+ `);
34
+ });
35
+ mocha_1.it('imports manifest when manifest key in `studio-package` present', () => {
36
+ const app = index_js_builder_1.default({
37
+ name: 'my-package',
38
+ version: '1.3.4',
39
+ main: 'src/index.js',
40
+ 'studio-package': {
41
+ manifest: 'package-manifest.yml'
42
+ }
43
+ }, 'src/index.js');
44
+ expect_ast_equals_1.default(app, `
45
+ import StudioFramework from '@movable/studio-framework';
46
+ import _my_package from './src/index';
47
+ import './package-manifest.yml';
48
+
49
+ export default class App extends StudioFramework {
50
+ setup() {
51
+ this.setGrouping('my-package', () => {
52
+ _my_package(this)
53
+ });
54
+ }
55
+ }
56
+
57
+ const app = new App();
58
+
59
+ app.render(document.getElementById('react-root')).then(() => {
60
+ window.APP_SUCCESSFULLY_RENDERED = true;
61
+ });
62
+ `);
63
+ });
64
+ });