@adobe/alloy 2.21.0-beta.4 → 2.21.0-beta.5

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/LICENSE_BANNER ADDED
@@ -0,0 +1,9 @@
1
+ Copyright 2019 Adobe. All rights reserved.
2
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
3
+ you may not use this file except in compliance with the License. You may obtain a copy
4
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
@@ -0,0 +1,93 @@
1
+ /*
2
+ Copyright 2021 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ /*
14
+ * This file is used in 4 scenarios:
15
+ * 1. Building files specified in rollup.config.js
16
+ * 2. Building libEs5/ files when publishing to NPM
17
+ * 3. Building libEs6/ files when publishing to NPM
18
+ * 4. Testcafe compiling clientFunctions. Unfortunately, there is no configuration I've found
19
+ * to tell Testcafe not to use this file.
20
+ *
21
+ * Environments:
22
+ * "rollup" - Used for rollup.config.js
23
+ * "npmEs5" - Used for building libEs5 files when publishing to NPM
24
+ * "npmEs6" - Used for building libEs6 files when publishing to NPM
25
+ */
26
+
27
+ const targets = {
28
+ browsers: [
29
+ "last 2 Chrome versions",
30
+ "last 2 Firefox versions",
31
+ "last 2 Safari versions",
32
+ "last 2 Edge versions",
33
+ "Explorer >= 10",
34
+ ],
35
+ };
36
+
37
+ const transformTemplateLiteralsPlugin = [
38
+ "@babel/plugin-transform-template-literals",
39
+ {
40
+ loose: true,
41
+ },
42
+ ];
43
+ const versionPlugin = [
44
+ "./scripts/helpers/versionBabelPlugin",
45
+ { cwd: __dirname },
46
+ ];
47
+
48
+ const transformModulesCommonjsPlugin = [
49
+ "@babel/plugin-transform-modules-commonjs",
50
+ {
51
+ strict: true,
52
+ noInterop: true,
53
+ },
54
+ ];
55
+
56
+ const npmIgnoreFiles = ["src/baseCode.js"];
57
+
58
+ module.exports = {
59
+ env: {
60
+ rollup: {
61
+ presets: [
62
+ [
63
+ "@babel/preset-env",
64
+ {
65
+ modules: false,
66
+ targets,
67
+ },
68
+ ],
69
+ ],
70
+ plugins: [transformTemplateLiteralsPlugin, versionPlugin],
71
+ },
72
+ npmEs5: {
73
+ presets: [
74
+ [
75
+ "@babel/preset-env",
76
+ {
77
+ targets,
78
+ },
79
+ ],
80
+ ],
81
+ ignore: npmIgnoreFiles,
82
+ plugins: [
83
+ transformTemplateLiteralsPlugin,
84
+ versionPlugin,
85
+ transformModulesCommonjsPlugin,
86
+ ],
87
+ },
88
+ npmEs6: {
89
+ ignore: npmIgnoreFiles,
90
+ plugins: [versionPlugin],
91
+ },
92
+ },
93
+ };
@@ -14,4 +14,4 @@ governing permissions and limitations under the License.
14
14
  */
15
15
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
16
16
  // see babel-plugin-version
17
- var _default = exports.default = "2.21.0-beta.4";
17
+ var _default = exports.default = "2.21.0-beta.5";
@@ -31,9 +31,13 @@ governing permissions and limitations under the License.
31
31
  /* @skipwhen ENV.alloy_activitycollector === false */
32
32
  /* @skipwhen ENV.alloy_audiences === false */
33
33
  /* @skipwhen ENV.alloy_personalization === false */
34
+ /* @skipwhen ENV.alloy_context === false */
35
+ /* @skipwhen ENV.alloy_privacy === false */
34
36
  /* @skipwhen ENV.alloy_eventmerge === false */
35
37
  /* @skipwhen ENV.alloy_decisioningengine === false */
36
38
  /* @skipwhen ENV.alloy_machinelearning === false */
39
+ /* @skipwhen ENV.alloy_streamingmedia === false */
40
+ /* @skipwhen ENV.alloy_legacymediaanalytics === false */
37
41
  // TODO: Register the Components here statically for now. They might be registered differently.
38
42
  // TODO: Figure out how sub-components will be made available/registered
39
43
  var _default = exports.default = [_index.default, _index2.default, _index3.default, _index4.default, _index5.default, _index6.default, _index7.default, _index8.default, _index9.default, _index11.default, _index10.default, _index13.default, _index12.default];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _index = require("./core/index.js");
4
+ /*
5
+ Copyright 2020 Adobe. All rights reserved.
6
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License. You may obtain a copy
8
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software distributed under
11
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ OF ANY KIND, either express or implied. See the License for the specific language
13
+ governing permissions and limitations under the License.
14
+ */
15
+
16
+ // This file is used by rollup to create the browser version that is uploaded to cdn
17
+
18
+ (0, _index.default)();
@@ -13,4 +13,4 @@ governing permissions and limitations under the License.
13
13
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
14
14
  // see babel-plugin-version
15
15
 
16
- export default "2.21.0-beta.4";
16
+ export default "2.21.0-beta.5";
@@ -26,7 +26,11 @@ import createAudiences from "../components/Audiences/index.js";
26
26
 
27
27
  /* @skipwhen ENV.alloy_personalization === false */
28
28
  import createPersonalization from "../components/Personalization/index.js";
29
+
30
+ /* @skipwhen ENV.alloy_context === false */
29
31
  import createContext from "../components/Context/index.js";
32
+
33
+ /* @skipwhen ENV.alloy_privacy === false */
30
34
  import createPrivacy from "../components/Privacy/index.js";
31
35
 
32
36
  /* @skipwhen ENV.alloy_eventmerge === false */
@@ -38,7 +42,11 @@ import createDecisioningEngine from "../components/DecisioningEngine/index.js";
38
42
 
39
43
  /* @skipwhen ENV.alloy_machinelearning === false */
40
44
  import createMachineLearning from "../components/MachineLearning/index.js";
45
+
46
+ /* @skipwhen ENV.alloy_streamingmedia === false */
41
47
  import createStreamingMedia from "../components/StreamingMedia/index.js";
48
+
49
+ /* @skipwhen ENV.alloy_legacymediaanalytics === false */
42
50
  import createLegacyMediaAnalytics from "../components/LegacyMediaAnalytics/index.js";
43
51
 
44
52
  // TODO: Register the Components here statically for now. They might be registered differently.
@@ -0,0 +1,16 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ // This file is used by rollup to create the browser version that is uploaded to cdn
14
+
15
+ import core from "./core/index.js";
16
+ core();
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.21.0-beta.4",
3
+ "version": "2.21.0-beta.5",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "type": "module",
6
6
  "main": "libEs5/index.js",
7
7
  "module": "libEs6/index.js",
8
8
  "files": [
9
9
  "libEs5",
10
- "libEs6"
10
+ "libEs6",
11
+ "LICENSE_BANNER",
12
+ "babel.config.cjs",
13
+ "rollup.config.js",
14
+ "scripts/helpers/alloyComponents.js",
15
+ "scripts/helpers/conditionalBuildBabelPlugin.js",
16
+ "scripts/helpers/versionBabelPlugin.js"
11
17
  ],
12
18
  "bin": {
13
- "alloy": "scripts/tui-builder.js",
14
- "build-alloy": "scripts/build-alloy.js"
19
+ "alloyBuilder": "scripts/alloyBuilder.js"
15
20
  },
16
21
  "scripts": {
17
22
  "clean": "rimraf dist distTest libEs5 libEs6",
@@ -36,7 +41,7 @@
36
41
  "build": "npm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
37
42
  "build:cli": "node scripts/build-alloy.js",
38
43
  "prepare": "husky && cd sandbox && npm install",
39
- "prepublishOnly": "rimraf libEs5 libEs6 && babel src -d libEs5 --env-name npmEs5 && babel src -d libEs6 --env-name npmEs6",
44
+ "prepack": "rimraf libEs5 libEs6 && babel src -d libEs5 --env-name npmEs5 && babel src -d libEs6 --env-name npmEs6",
40
45
  "checkthattestfilesexist": "./scripts/checkThatTestFilesExist.js",
41
46
  "add-license": "./scripts/add-license.js",
42
47
  "preinstall": "npx force-resolutions"
@@ -73,13 +78,12 @@
73
78
  "@adobe/reactor-object-assign": "^1.0.0",
74
79
  "@adobe/reactor-query-string": "^1.0.0",
75
80
  "css.escape": "^1.5.1",
76
- "inquirer": "^9.2.23",
77
81
  "js-cookie": "3.0.5",
78
82
  "parse-uri": "^1.0.9",
79
83
  "uuid": "^9.0.1"
80
84
  },
81
85
  "devDependencies": {
82
- "@adobe/alloy": "^2.21.0-beta.3",
86
+ "@adobe/alloy": "^2.21.0-beta.4",
83
87
  "@babel/cli": "^7.24.7",
84
88
  "@babel/core": "^7.24.7",
85
89
  "@babel/eslint-parser": "^7.24.7",
@@ -97,6 +101,7 @@
97
101
  "bundlesize": "^0.18.2",
98
102
  "chai": "^5.1.1",
99
103
  "chalk": "^5.3.0",
104
+ "commander": "^12.1.0",
100
105
  "concurrently": "^8.2.2",
101
106
  "date-fns": "^3.6.0",
102
107
  "dotenv": "^16.4.5",
@@ -112,6 +117,7 @@
112
117
  "globals": "^15.4.0",
113
118
  "handlebars": "^4.7.8",
114
119
  "husky": "^9.0.11",
120
+ "inquirer": "^9.2.23",
115
121
  "jasmine": "^5.1.0",
116
122
  "jasmine-core": "^5.1.2",
117
123
  "karma": "^6.4.3",
@@ -145,8 +151,7 @@
145
151
  "testcafe-reporter-junit": "^3.0.2",
146
152
  "testcafe-reporter-saucelabs": "^3.1.0",
147
153
  "url-exists-nodejs": "^0.2.4",
148
- "url-parse": "^1.5.10",
149
- "yargs": "^17.7.2"
154
+ "url-parse": "^1.5.10"
150
155
  },
151
156
  "overrides": {
152
157
  "karma-sauce-launcher": {
@@ -0,0 +1,164 @@
1
+ /*
2
+ Copyright 2019 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import path from "path";
14
+ import resolve from "@rollup/plugin-node-resolve";
15
+ import commonjs from "@rollup/plugin-commonjs";
16
+ import babel from "@rollup/plugin-babel";
17
+ import terser from "@rollup/plugin-terser";
18
+ import license from "rollup-plugin-license";
19
+ import { fileURLToPath } from "url";
20
+
21
+ // Set these boolean environment options to control which files are built:
22
+ // build the snippet that must be add to the page
23
+ const BASE_CODE = "BASE_CODE";
24
+ // build the standalone distribution
25
+ const STANDALONE = "STANDALONE";
26
+ // build the standalone distribution, but put it in the sandbox directory
27
+ const SANDBOX = "SANDBOX";
28
+ // build the npm package entrypoint (createInstance)
29
+ const NPM_PACKAGE_LOCAL = "NPM_PACKAGE_LOCAL";
30
+ // build from the published npm package
31
+ const NPM_PACKAGE_PROD = "NPM_PACKAGE_PROD";
32
+ // Add "_MIN" to the end of the option name to build the minified version
33
+
34
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
35
+
36
+ const buildPlugins = ({ variant, minify, babelPlugins }) => {
37
+ const plugins = [
38
+ resolve({
39
+ preferBuiltins: false,
40
+ // Support the browser field in dependencies' package.json.
41
+ // Useful for the uuid package.
42
+ mainFields: ["module", "main", "browser"],
43
+ }),
44
+ commonjs(),
45
+ babel({
46
+ envName: "rollup",
47
+ babelHelpers: "bundled",
48
+ configFile: path.resolve(dirname, "babel.config.cjs"),
49
+ plugins: babelPlugins,
50
+ }),
51
+ ];
52
+
53
+ if (minify) {
54
+ if (variant === BASE_CODE) {
55
+ plugins.push(
56
+ terser({
57
+ mangle: true,
58
+ compress: {
59
+ unused: true,
60
+ },
61
+ output: {
62
+ wrap_func_args: false,
63
+ },
64
+ toplevel: true,
65
+ }),
66
+ );
67
+ } else {
68
+ plugins.push(terser());
69
+ }
70
+ }
71
+ if (variant === STANDALONE) {
72
+ plugins.push(
73
+ license({
74
+ cwd: dirname,
75
+ banner: {
76
+ content: {
77
+ file: path.join(dirname, "LICENSE_BANNER"),
78
+ },
79
+ },
80
+ }),
81
+ );
82
+ }
83
+
84
+ return plugins;
85
+ };
86
+
87
+ export const buildConfig = ({
88
+ variant = STANDALONE,
89
+ minify = false,
90
+ babelPlugins = [],
91
+ input = `${dirname}/src/standalone.js`,
92
+ file,
93
+ }) => {
94
+ const plugins = buildPlugins({ variant, minify, babelPlugins });
95
+ const minifiedExtension = minify ? ".min" : "";
96
+
97
+ if (variant === BASE_CODE) {
98
+ return {
99
+ input: "src/baseCode.js",
100
+ output: [
101
+ {
102
+ file: `distTest/baseCode${minifiedExtension}.js`,
103
+ format: "cjs",
104
+ strict: false,
105
+ },
106
+ ],
107
+ plugins,
108
+ };
109
+ }
110
+ if (variant === STANDALONE || variant === SANDBOX) {
111
+ const destDirectory = variant === SANDBOX ? "sandbox/public/" : "dist/";
112
+
113
+ return {
114
+ input,
115
+ output: [
116
+ {
117
+ file: file || `${destDirectory}alloy${minifiedExtension}.js`,
118
+ format: "iife",
119
+ intro:
120
+ "if (document.documentMode && document.documentMode < 11) {\n" +
121
+ " console.warn('The Adobe Experience Cloud Web SDK does not support IE 10 and below.');\n" +
122
+ " return;\n" +
123
+ "}\n",
124
+ sourcemap: variant === SANDBOX,
125
+ },
126
+ ],
127
+ plugins,
128
+ };
129
+ }
130
+
131
+ // NPM_PACKAGE_LOCAL or NPM_PACKAGE_PROD
132
+ const filename =
133
+ variant === NPM_PACKAGE_LOCAL ? "npmPackageLocal" : "npmPackageProd";
134
+
135
+ return {
136
+ input: `test/functional/helpers/${filename}.js`,
137
+ output: [
138
+ {
139
+ file: `distTest/${filename}${minifiedExtension}.js`,
140
+ format: "iife",
141
+ },
142
+ ],
143
+ plugins,
144
+ };
145
+ };
146
+
147
+ const config = [];
148
+
149
+ const addConfig = (variant) => {
150
+ if (process.env[variant]) {
151
+ config.push(buildConfig({ variant, minify: false }));
152
+ }
153
+ if (process.env[`${variant}_MIN`]) {
154
+ config.push(buildConfig({ variant, minify: true }));
155
+ }
156
+ };
157
+
158
+ addConfig(BASE_CODE);
159
+ addConfig(STANDALONE);
160
+ addConfig(SANDBOX);
161
+ addConfig(NPM_PACKAGE_LOCAL);
162
+ addConfig(NPM_PACKAGE_PROD);
163
+
164
+ export default config;
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ Copyright 2023 Adobe. All rights reserved.
5
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License. You may obtain a copy
7
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software distributed under
9
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
+ OF ANY KIND, either express or implied. See the License for the specific language
11
+ governing permissions and limitations under the License.
12
+ */
13
+
14
+ import fs from "fs";
15
+ import path from "path";
16
+ import { rollup } from "rollup";
17
+ import { Command, Option, InvalidOptionArgumentError } from "commander";
18
+ import inquirer from "inquirer";
19
+ import { buildConfig } from "../rollup.config.js";
20
+ import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
21
+ import components from "./helpers/alloyComponents.js";
22
+
23
+ const dirname = import.meta.dirname;
24
+ let sourceRootPath = `${dirname}/../src`;
25
+ if (!fs.existsSync(sourceRootPath)) {
26
+ sourceRootPath = `${dirname}/../libEs6`;
27
+ }
28
+
29
+ const getOptionalComponents = (() => {
30
+ const componentCreatorsPath = `${sourceRootPath}/core/componentCreators.js`;
31
+
32
+ // Read componentCreators.js
33
+ const componentCreatorsContent = fs.readFileSync(
34
+ componentCreatorsPath,
35
+ "utf8",
36
+ );
37
+
38
+ // Extract optional components based on @skipwhen directive
39
+ const optionalComponents = componentCreatorsContent
40
+ .split("\n")
41
+ .filter((line) => line.trim().startsWith("/* @skipwhen"))
42
+ .map((line) => {
43
+ const match = line.match(/ENV\.alloy_([a-zA-Z0-9]+) === false/);
44
+ if (match) {
45
+ const [, componentName] = match;
46
+ return componentName.toLowerCase(); // Ensure this matches the expected format for exclusion
47
+ }
48
+ return null;
49
+ })
50
+ .filter(Boolean);
51
+
52
+ return () => optionalComponents;
53
+ })();
54
+
55
+ const getDefaultPath = () => {
56
+ return process.cwd();
57
+ };
58
+
59
+ const getFile = (argv) => {
60
+ return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
61
+ };
62
+
63
+ const getFileSizeInKB = (filePath) => {
64
+ const stats = fs.statSync(filePath);
65
+ const fileSizeInBytes = stats.size;
66
+ return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
67
+ };
68
+
69
+ const build = async (argv) => {
70
+ const rollupConfig = buildConfig({
71
+ input: `${sourceRootPath}/standalone.js`,
72
+ file: getFile(argv),
73
+ minify: argv.minify,
74
+ babelPlugins: [
75
+ conditionalBuildBabelPlugin(
76
+ argv.exclude.reduce((acc, module) => {
77
+ acc[`alloy_${module}`] = "false";
78
+ return acc;
79
+ }, {}),
80
+ ),
81
+ ],
82
+ });
83
+
84
+ const bundle = await rollup(rollupConfig);
85
+ await bundle.write(rollupConfig.output[0]);
86
+ console.log(
87
+ `🎉 Wrote ${
88
+ path.isAbsolute(argv.outputDir)
89
+ ? rollupConfig.output[0].file
90
+ : path.relative(process.cwd(), rollupConfig.output[0].file)
91
+ } (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
92
+ );
93
+ };
94
+
95
+ const getMakeBuildCommand = () =>
96
+ new Command("build")
97
+ .description("Build a custom version of the alloy.js library.")
98
+ .addOption(
99
+ new Option(
100
+ "-e, --exclude <modules...>",
101
+ "optional components that can be excluded from the build",
102
+ )
103
+ .choices(getOptionalComponents())
104
+ .default([])
105
+ .argParser((value) => {
106
+ const modules = value.split(",");
107
+
108
+ modules.forEach((module) => {
109
+ if (!getOptionalComponents().includes(module))
110
+ throw new InvalidOptionArgumentError(
111
+ `Module "${module}" does not exists. Allowed choices are "${getOptionalComponents().join('", "')}".`,
112
+ );
113
+ });
114
+
115
+ return modules;
116
+ }),
117
+ )
118
+ .addOption(new Option("-M, --no-minify", "disable code minification"))
119
+ .addOption(
120
+ new Option(
121
+ "-o, --outputDir <dir>",
122
+ "the output directory for the generated build",
123
+ )
124
+ .default(getDefaultPath())
125
+ .argParser((value) => {
126
+ if (!path.isAbsolute(value)) {
127
+ value = `${getDefaultPath()}${path.sep}${value}`;
128
+ }
129
+
130
+ try {
131
+ const stats = fs.statSync(value);
132
+ if (!stats.isDirectory()) {
133
+ throw new InvalidOptionArgumentError(
134
+ `Output directory "${value}" is not a valid directory path.`,
135
+ );
136
+ }
137
+ } catch (error) {
138
+ throw new InvalidOptionArgumentError(
139
+ `Output directory "${value}" is not a valid directory path. ${error.message}`,
140
+ );
141
+ }
142
+
143
+ return value.replace(new RegExp(`${path.sep}+$`, "g"), "");
144
+ }),
145
+ )
146
+ .action(async (opts) => {
147
+ await build(opts);
148
+ });
149
+
150
+ const getInteractiveBuildCommand = () =>
151
+ new Command("interactive-build")
152
+ .description(
153
+ "Interactive process that will ask a series of questions and then it will generate a build.",
154
+ )
155
+ .action(async () => {
156
+ await inquirer
157
+ .prompt([
158
+ {
159
+ type: "checkbox",
160
+ name: "include",
161
+ message: "What components should be included in your Alloy build?",
162
+ choices: components,
163
+ },
164
+ {
165
+ type: "list",
166
+ name: "minify",
167
+ message: "How would you like your JavaScript to be?",
168
+ choices: [
169
+ { name: "Minified", value: true },
170
+ { name: "Unminified", value: false },
171
+ ],
172
+ },
173
+ {
174
+ type: "string",
175
+ name: "outputDir",
176
+ message: "Where would you like to save the build?",
177
+ default: process.cwd(),
178
+ },
179
+ ])
180
+ .then(async (opts) => {
181
+ const { include } = opts;
182
+ const exclude = components
183
+ .map((v) => v.value)
184
+ .filter((component) => !include.includes(component));
185
+
186
+ opts.exclude = exclude;
187
+ delete opts.include;
188
+
189
+ await build(opts);
190
+ })
191
+ .catch((error) => {
192
+ if (error.isTtyError) {
193
+ console.error(
194
+ "Prompt couldn't be rendered in the current environment",
195
+ );
196
+ } else {
197
+ console.error("An error occurred: ", error);
198
+ }
199
+ });
200
+ });
201
+
202
+ const program = new Command();
203
+
204
+ program
205
+ .name("alloy")
206
+ .description(
207
+ "Tool for generating custom Adobe Experience Platform Web SDK builds.",
208
+ )
209
+ .version("1.0.0");
210
+
211
+ program.addCommand(getMakeBuildCommand());
212
+ program.addCommand(getInteractiveBuildCommand(), { isDefault: true });
213
+ program.parse();
@@ -0,0 +1,63 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
10
+ */
11
+
12
+ export default [
13
+ {
14
+ name: "Activity Collector",
15
+ value: "activitycollector",
16
+ checked: true,
17
+ },
18
+ {
19
+ name: "Audiences",
20
+ value: "audiences",
21
+ checked: true,
22
+ },
23
+ {
24
+ name: "Context",
25
+ value: "context",
26
+ checked: true,
27
+ },
28
+ {
29
+ name: "Decision Engine",
30
+ value: "decisioningengine",
31
+ checked: true,
32
+ },
33
+ {
34
+ name: "Event Merge",
35
+ value: "eventmerge",
36
+ checked: true,
37
+ },
38
+ {
39
+ name: "Personalization",
40
+ value: "personalization",
41
+ checked: true,
42
+ },
43
+ {
44
+ name: "Privacy",
45
+ value: "privacy",
46
+ checked: true,
47
+ },
48
+ {
49
+ name: "Streaming Media",
50
+ value: "streamingmedia",
51
+ checked: true,
52
+ },
53
+ {
54
+ name: "Legacy Media Analytics",
55
+ value: "legacymediaanalytics",
56
+ checked: true,
57
+ },
58
+ {
59
+ name: "Machine Learning",
60
+ value: "machinelearning",
61
+ checked: true,
62
+ },
63
+ ];
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (excludedModules) => ({
14
+ visitor: {
15
+ ImportDeclaration(path) {
16
+ let skipWhenComments = [];
17
+ if (path.node.leadingComments) {
18
+ skipWhenComments = path.node.leadingComments.filter((c) => {
19
+ return c.value.trim().startsWith("@skipwhen");
20
+ });
21
+ }
22
+
23
+ if (skipWhenComments.length > 0) {
24
+ const [, webSDKModuleName, value] = skipWhenComments[0].value.match(
25
+ "ENV.(.*) === (false|true)",
26
+ );
27
+
28
+ if (excludedModules[webSDKModuleName] === value) {
29
+ const variableName = path.node.specifiers[0].local.name;
30
+
31
+ // Wrap the variable declaration in an IIFE to turn it into an expression
32
+ path.replaceWithSourceString(
33
+ `(() => { const ${variableName} = () => {}; })()`,
34
+ );
35
+ }
36
+ }
37
+ },
38
+ ExportDefaultDeclaration(path) {
39
+ if (path.node.declaration.type === "ArrayExpression") {
40
+ path.node.declaration.elements = path.node.declaration.elements.filter(
41
+ (element) => {
42
+ if (element.name) {
43
+ const variableName = element.name;
44
+ const componentName = variableName
45
+ .replace("create", "")
46
+ .toLowerCase();
47
+ return !Object.keys(excludedModules).includes(
48
+ `alloy_${componentName}`,
49
+ );
50
+ }
51
+ return true;
52
+ },
53
+ );
54
+ }
55
+ },
56
+ },
57
+ });
@@ -0,0 +1,43 @@
1
+ import { createRequire } from "module";
2
+
3
+ const require = createRequire(import.meta.url);
4
+
5
+ const version = null;
6
+ const getVersion = ({ opts: { cwd } }) => {
7
+ if (version) {
8
+ return version;
9
+ }
10
+
11
+ // eslint-disable-next-line import/no-dynamic-require
12
+ const packageJson = require(`${cwd}/package.json`);
13
+ return packageJson.version;
14
+ };
15
+
16
+ export default (_ref) => {
17
+ const t = _ref.types;
18
+
19
+ return {
20
+ visitor: {
21
+ // __VERSION__
22
+ ReferencedIdentifier(path, state) {
23
+ const identifier = state.opts.identifier;
24
+ const transform = identifier === undefined ? true : identifier; // 默认转换
25
+
26
+ const define = state.opts.define || "__VERSION__"; // 默认值
27
+ if (transform && path.node.name === define) {
28
+ path.replaceWith(t.valueToNode(getVersion(state)));
29
+ }
30
+ },
31
+ // "__VERSION__"
32
+ StringLiteral(path, state) {
33
+ const stringLiteral = state.opts.stringLiteral;
34
+ const transform = stringLiteral === undefined ? true : stringLiteral;
35
+
36
+ const define = state.opts.define || "__VERSION__";
37
+ if (transform && path.node.value === define) {
38
+ path.replaceWith(t.valueToNode(getVersion(state)));
39
+ }
40
+ },
41
+ },
42
+ };
43
+ };
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /*
4
- Copyright 2023 Adobe. All rights reserved.
5
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License. You may obtain a copy
7
- of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- Unless required by applicable law or agreed to in writing, software distributed under
9
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- OF ANY KIND, either express or implied. See the License for the specific language
11
- governing permissions and limitations under the License.
12
- */
13
-
14
- import fs from "fs";
15
- import path from "path";
16
- import { rollup } from "rollup";
17
- import yargs from "yargs/yargs";
18
- // eslint-disable-next-line import/extensions
19
- import { hideBin } from "yargs/helpers";
20
- import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
21
- import { buildConfig } from "../rollup.config.js";
22
-
23
- const dirname = import.meta.dirname;
24
-
25
- // Path to componentCreators.js
26
- const componentCreatorsPath = path.join(
27
- dirname,
28
- "../src/core/componentCreators.js",
29
- );
30
-
31
- // Read componentCreators.js
32
- const componentCreatorsContent = fs.readFileSync(componentCreatorsPath, "utf8");
33
-
34
- // Extract optional components based on @skipwhen directive
35
- const optionalComponents = componentCreatorsContent
36
- .split("\n")
37
- .filter((line) => line.trim().startsWith("/* @skipwhen"))
38
- .map((line) => {
39
- const match = line.match(/ENV\.alloy_([a-zA-Z0-9]+) === false/);
40
- if (match) {
41
- const [, componentName] = match;
42
- return componentName.toLowerCase(); // Ensure this matches the expected format for exclusion
43
- }
44
- return null;
45
- })
46
- .filter(Boolean);
47
-
48
- const getDefaultPath = () => {
49
- return process.cwd();
50
- };
51
-
52
- let pathIsAbsolute = false;
53
-
54
- const argv = yargs(hideBin(process.argv))
55
- .scriptName("build-alloy")
56
- .example([
57
- [`$0 --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
58
- [`$0 --minify --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
59
- ])
60
- .option("exclude", {
61
- describe: "components that can be excluded from the build",
62
- choices: optionalComponents,
63
- type: "array",
64
- alias: "e",
65
- default: [],
66
- })
67
- .option("minify", {
68
- type: "boolean",
69
- default: true,
70
- alias: "m",
71
- })
72
- .option("outputDir", {
73
- alias: "o",
74
- default: getDefaultPath(),
75
- })
76
- .coerce("outputDir", (opt) => {
77
- if (!path.isAbsolute(opt)) {
78
- opt = `${getDefaultPath()}${path.sep}${opt}`;
79
- } else {
80
- pathIsAbsolute = true;
81
- }
82
-
83
- try {
84
- const stats = fs.statSync(opt);
85
- if (!stats.isDirectory()) {
86
- throw new Error("Output directory must be a valid directory path.");
87
- }
88
- } catch (error) {
89
- throw new Error("Output directory must be a valid directory path.");
90
- }
91
-
92
- return opt.replace(new RegExp(`${path.sep}+$`, "g"), "");
93
- }).argv;
94
-
95
- const getFile = () => {
96
- return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
97
- };
98
-
99
- const getFileSizeInKB = (filePath) => {
100
- const stats = fs.statSync(filePath);
101
- const fileSizeInBytes = stats.size;
102
- return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
103
- };
104
-
105
- const buildWithComponents = async () => {
106
- const rollupConfig = buildConfig({
107
- file: getFile(),
108
- minify: argv.minify,
109
- babelPlugins: [
110
- conditionalBuildBabelPlugin(
111
- argv.exclude.reduce((acc, module) => {
112
- acc[`alloy_${module}`] = "false";
113
- return acc;
114
- }, {}),
115
- ),
116
- ],
117
- });
118
-
119
- const bundle = await rollup(rollupConfig);
120
- await bundle.write(rollupConfig.output[0]);
121
- console.log(
122
- `🎉 Wrote ${
123
- pathIsAbsolute
124
- ? rollupConfig.output[0].file
125
- : path.relative(process.cwd(), rollupConfig.output[0].file)
126
- } (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
127
- );
128
- };
129
-
130
- buildWithComponents();
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /*
4
- Copyright 2024 Adobe. All rights reserved.
5
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License. You may obtain a copy
7
- of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- Unless required by applicable law or agreed to in writing, software distributed under
9
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- OF ANY KIND, either express or implied. See the License for the specific language
11
- governing permissions and limitations under the License.
12
- */
13
-
14
- import inquirer from "inquirer";
15
- import util from "util";
16
- import { exec } from "child_process";
17
- import components from "./helpers/alloyComponents.js";
18
-
19
- const execAsync = util.promisify(exec);
20
-
21
- inquirer
22
- .prompt([
23
- {
24
- type: "checkbox",
25
- name: "include",
26
- message: "What components should be included in your Alloy build?",
27
- choices: components,
28
- },
29
- {
30
- type: "list",
31
- name: "minify",
32
- message: "How would you like your JavaScript to be?",
33
- choices: [
34
- { name: "Minified", value: true },
35
- { name: "Unminified", value: false },
36
- ],
37
- },
38
- {
39
- type: "string",
40
- name: "outputDir",
41
- message: "Where would you like to save the build?",
42
- default: process.cwd(),
43
- },
44
- ])
45
- .then(async (answers) => {
46
- const { include, minify, outputDir } = answers;
47
- const exclude = components
48
- .map((v) => v.value)
49
- .filter((component) => !include.includes(component));
50
-
51
- let params = `--outputDir ${outputDir}`;
52
-
53
- if (exclude.length > 0) {
54
- params += ` --exclude ${exclude.join(" ")}`;
55
- }
56
-
57
- if (!minify) {
58
- params += " --no-minify";
59
- }
60
-
61
- const resultPromise = execAsync(`npm run build:cli -- ${params}`);
62
- const output = await resultPromise;
63
- console.log(output.stdout);
64
- })
65
- .catch((error) => {
66
- if (error.isTtyError) {
67
- console.error("Prompt couldn't be rendered in the current environment");
68
- } else {
69
- console.error("An error occurred: ", error);
70
- }
71
- });