@adobe/alloy 2.21.0-beta.1 → 2.21.0-beta.10
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 +9 -0
- package/babel.config.cjs +93 -0
- package/libEs5/constants/libraryVersion.js +1 -1
- package/libEs5/core/componentCreators.js +4 -0
- package/libEs5/standalone.js +18 -0
- package/libEs6/constants/libraryVersion.js +1 -1
- package/libEs6/core/componentCreators.js +8 -0
- package/libEs6/standalone.js +16 -0
- package/package.json +34 -29
- package/rollup.config.js +164 -0
- package/scripts/alloyBuilder.js +215 -0
- package/scripts/helpers/alloyComponents.js +63 -0
- package/scripts/helpers/conditionalBuildBabelPlugin.js +57 -0
- package/scripts/helpers/versionBabelPlugin.js +43 -0
- package/scripts/build-alloy.js +0 -125
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.
|
package/babel.config.cjs
ADDED
|
@@ -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.
|
|
17
|
+
var _default = exports.default = "2.21.0-beta.10";
|
|
@@ -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)();
|
|
@@ -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,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/alloy",
|
|
3
|
-
"version": "2.21.0-beta.
|
|
3
|
+
"version": "2.21.0-beta.10",
|
|
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
|
-
"
|
|
19
|
+
"alloyBuilder": "scripts/alloyBuilder.js"
|
|
14
20
|
},
|
|
15
21
|
"scripts": {
|
|
16
22
|
"clean": "rimraf dist distTest libEs5 libEs6",
|
|
@@ -35,7 +41,7 @@
|
|
|
35
41
|
"build": "npm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
|
|
36
42
|
"build:cli": "node scripts/build-alloy.js",
|
|
37
43
|
"prepare": "husky && cd sandbox && npm install",
|
|
38
|
-
"
|
|
44
|
+
"prepack": "rimraf libEs5 libEs6 && babel src -d libEs5 --env-name npmEs5 && babel src -d libEs6 --env-name npmEs6",
|
|
39
45
|
"checkthattestfilesexist": "./scripts/checkThatTestFilesExist.js",
|
|
40
46
|
"add-license": "./scripts/add-license.js",
|
|
41
47
|
"preinstall": "npx force-resolutions"
|
|
@@ -71,27 +77,31 @@
|
|
|
71
77
|
"@adobe/reactor-load-script": "^1.1.1",
|
|
72
78
|
"@adobe/reactor-object-assign": "^1.0.0",
|
|
73
79
|
"@adobe/reactor-query-string": "^1.0.0",
|
|
74
|
-
"css.escape": "^1.5.1",
|
|
75
|
-
"js-cookie": "3.0.5",
|
|
76
|
-
"parse-uri": "^1.0.9",
|
|
77
|
-
"uuid": "^9.0.1"
|
|
78
|
-
},
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@adobe/alloy": "2.21.0-beta.0",
|
|
81
|
-
"@babel/cli": "^7.24.7",
|
|
82
80
|
"@babel/core": "^7.24.7",
|
|
83
81
|
"@babel/eslint-parser": "^7.24.7",
|
|
84
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
|
|
85
|
-
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
86
82
|
"@babel/plugin-transform-template-literals": "^7.24.7",
|
|
87
83
|
"@babel/preset-env": "^7.24.7",
|
|
88
|
-
"@babel/types": "^7.24.7",
|
|
89
|
-
"@eslint/js": "^9.4.0",
|
|
90
|
-
"@octokit/rest": "^20.1.1",
|
|
91
84
|
"@rollup/plugin-babel": "^6.0.4",
|
|
92
85
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
93
86
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
94
87
|
"@rollup/plugin-terser": "^0.4.4",
|
|
88
|
+
"commander": "^12.1.0",
|
|
89
|
+
"css.escape": "^1.5.1",
|
|
90
|
+
"inquirer": "^9.2.23",
|
|
91
|
+
"js-cookie": "3.0.5",
|
|
92
|
+
"parse-uri": "^1.0.9",
|
|
93
|
+
"rollup": "^4.18.0",
|
|
94
|
+
"rollup-plugin-glob-import": "^0.5.0",
|
|
95
|
+
"rollup-plugin-istanbul": "^5.0.0",
|
|
96
|
+
"rollup-plugin-license": "^3.5.0",
|
|
97
|
+
"uuid": "^10.0.0"
|
|
98
|
+
},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@adobe/alloy": "^2.21.0-beta.7",
|
|
101
|
+
"@eslint/js": "^9.5.0",
|
|
102
|
+
"@octokit/rest": "^21.0.0",
|
|
103
|
+
"@babel/cli": "^7.24.7",
|
|
104
|
+
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
95
105
|
"bundlesize": "^0.18.2",
|
|
96
106
|
"chai": "^5.1.1",
|
|
97
107
|
"chalk": "^5.3.0",
|
|
@@ -106,8 +116,8 @@
|
|
|
106
116
|
"eslint-plugin-prettier": "^5.1.3",
|
|
107
117
|
"eslint-plugin-testcafe": "^0.2.1",
|
|
108
118
|
"force-resolutions": "^1.0.11",
|
|
109
|
-
"glob": "^10.4.
|
|
110
|
-
"globals": "^15.
|
|
119
|
+
"glob": "^10.4.2",
|
|
120
|
+
"globals": "^15.6.0",
|
|
111
121
|
"handlebars": "^4.7.8",
|
|
112
122
|
"husky": "^9.0.11",
|
|
113
123
|
"jasmine": "^5.1.0",
|
|
@@ -124,27 +134,22 @@
|
|
|
124
134
|
"karma-safari-launcher": "^1.0.0",
|
|
125
135
|
"karma-sauce-launcher": "^4.3.6",
|
|
126
136
|
"karma-spec-reporter": "0.0.36",
|
|
127
|
-
"lint-staged": "^15.2.
|
|
128
|
-
"prettier": "^3.3.
|
|
137
|
+
"lint-staged": "^15.2.7",
|
|
138
|
+
"prettier": "^3.3.2",
|
|
129
139
|
"promise-polyfill": "^8.3.0",
|
|
130
140
|
"read-cache": "^1.0.0",
|
|
131
141
|
"recursive-readdir": "^2.2.3",
|
|
132
142
|
"request": "^2.88.0",
|
|
133
143
|
"rimraf": "^5.0.7",
|
|
134
|
-
"rollup": "^4.18.0",
|
|
135
|
-
"rollup-plugin-glob-import": "^0.5.0",
|
|
136
|
-
"rollup-plugin-istanbul": "^5.0.0",
|
|
137
|
-
"rollup-plugin-license": "^3.4.0",
|
|
138
144
|
"semver": "^7.6.2",
|
|
139
145
|
"staged-git-files": "^1.3.0",
|
|
140
146
|
"start-server-and-test": "^2.0.4",
|
|
141
|
-
"testcafe": "^3.6.
|
|
147
|
+
"testcafe": "^3.6.1",
|
|
142
148
|
"testcafe-browser-provider-saucelabs": "^3.0.0",
|
|
143
149
|
"testcafe-reporter-junit": "^3.0.2",
|
|
144
|
-
"testcafe-reporter-saucelabs": "^3.
|
|
150
|
+
"testcafe-reporter-saucelabs": "^3.2.0",
|
|
145
151
|
"url-exists-nodejs": "^0.2.4",
|
|
146
|
-
"url-parse": "^1.5.10"
|
|
147
|
-
"yargs": "^17.7.2"
|
|
152
|
+
"url-parse": "^1.5.10"
|
|
148
153
|
},
|
|
149
154
|
"overrides": {
|
|
150
155
|
"karma-sauce-launcher": {
|
package/rollup.config.js
ADDED
|
@@ -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,215 @@
|
|
|
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 { fileURLToPath } from "url";
|
|
20
|
+
import { buildConfig } from "../rollup.config.js";
|
|
21
|
+
import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
|
|
22
|
+
import components from "./helpers/alloyComponents.js";
|
|
23
|
+
|
|
24
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
|
|
26
|
+
let sourceRootPath = `${dirname}/../src`;
|
|
27
|
+
if (!fs.existsSync(sourceRootPath)) {
|
|
28
|
+
sourceRootPath = `${dirname}/../libEs6`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getOptionalComponents = (() => {
|
|
32
|
+
const componentCreatorsPath = `${sourceRootPath}/core/componentCreators.js`;
|
|
33
|
+
|
|
34
|
+
// Read componentCreators.js
|
|
35
|
+
const componentCreatorsContent = fs.readFileSync(
|
|
36
|
+
componentCreatorsPath,
|
|
37
|
+
"utf8",
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Extract optional components based on @skipwhen directive
|
|
41
|
+
const optionalComponents = componentCreatorsContent
|
|
42
|
+
.split("\n")
|
|
43
|
+
.filter((line) => line.trim().startsWith("/* @skipwhen"))
|
|
44
|
+
.map((line) => {
|
|
45
|
+
const match = line.match(/ENV\.alloy_([a-zA-Z0-9]+) === false/);
|
|
46
|
+
if (match) {
|
|
47
|
+
const [, componentName] = match;
|
|
48
|
+
return componentName.toLowerCase(); // Ensure this matches the expected format for exclusion
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
})
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
|
|
54
|
+
return () => optionalComponents;
|
|
55
|
+
})();
|
|
56
|
+
|
|
57
|
+
const getDefaultPath = () => {
|
|
58
|
+
return process.cwd();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getFile = (argv) => {
|
|
62
|
+
return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getFileSizeInKB = (filePath) => {
|
|
66
|
+
const stats = fs.statSync(filePath);
|
|
67
|
+
const fileSizeInBytes = stats.size;
|
|
68
|
+
return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const build = async (argv) => {
|
|
72
|
+
const rollupConfig = buildConfig({
|
|
73
|
+
input: `${sourceRootPath}/standalone.js`,
|
|
74
|
+
file: getFile(argv),
|
|
75
|
+
minify: argv.minify,
|
|
76
|
+
babelPlugins: [
|
|
77
|
+
conditionalBuildBabelPlugin(
|
|
78
|
+
argv.exclude.reduce((acc, module) => {
|
|
79
|
+
acc[`alloy_${module}`] = "false";
|
|
80
|
+
return acc;
|
|
81
|
+
}, {}),
|
|
82
|
+
),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const bundle = await rollup(rollupConfig);
|
|
87
|
+
await bundle.write(rollupConfig.output[0]);
|
|
88
|
+
console.log(
|
|
89
|
+
`🎉 Wrote ${
|
|
90
|
+
path.isAbsolute(argv.outputDir)
|
|
91
|
+
? rollupConfig.output[0].file
|
|
92
|
+
: path.relative(process.cwd(), rollupConfig.output[0].file)
|
|
93
|
+
} (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const getMakeBuildCommand = () =>
|
|
98
|
+
new Command("build")
|
|
99
|
+
.description("Build a custom version of the alloy.js library.")
|
|
100
|
+
.addOption(
|
|
101
|
+
new Option(
|
|
102
|
+
"-e, --exclude <modules...>",
|
|
103
|
+
"optional components that can be excluded from the build",
|
|
104
|
+
)
|
|
105
|
+
.choices(getOptionalComponents())
|
|
106
|
+
.default([])
|
|
107
|
+
.argParser((value) => {
|
|
108
|
+
const modules = value.split(",");
|
|
109
|
+
|
|
110
|
+
modules.forEach((module) => {
|
|
111
|
+
if (!getOptionalComponents().includes(module))
|
|
112
|
+
throw new InvalidOptionArgumentError(
|
|
113
|
+
`Module "${module}" does not exists. Allowed choices are "${getOptionalComponents().join('", "')}".`,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return modules;
|
|
118
|
+
}),
|
|
119
|
+
)
|
|
120
|
+
.addOption(new Option("-M, --no-minify", "disable code minification"))
|
|
121
|
+
.addOption(
|
|
122
|
+
new Option(
|
|
123
|
+
"-o, --outputDir <dir>",
|
|
124
|
+
"the output directory for the generated build",
|
|
125
|
+
)
|
|
126
|
+
.default(getDefaultPath())
|
|
127
|
+
.argParser((value) => {
|
|
128
|
+
if (!path.isAbsolute(value)) {
|
|
129
|
+
value = `${getDefaultPath()}${path.sep}${value}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const stats = fs.statSync(value);
|
|
134
|
+
if (!stats.isDirectory()) {
|
|
135
|
+
throw new InvalidOptionArgumentError(
|
|
136
|
+
`Output directory "${value}" is not a valid directory path.`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw new InvalidOptionArgumentError(
|
|
141
|
+
`Output directory "${value}" is not a valid directory path. ${error.message}`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return value.replace(new RegExp(`${path.sep}+$`, "g"), "");
|
|
146
|
+
}),
|
|
147
|
+
)
|
|
148
|
+
.action(async (opts) => {
|
|
149
|
+
await build(opts);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const getInteractiveBuildCommand = () =>
|
|
153
|
+
new Command("interactive-build")
|
|
154
|
+
.description(
|
|
155
|
+
"Interactive process that will ask a series of questions and then it will generate a build.",
|
|
156
|
+
)
|
|
157
|
+
.action(async () => {
|
|
158
|
+
await inquirer
|
|
159
|
+
.prompt([
|
|
160
|
+
{
|
|
161
|
+
type: "checkbox",
|
|
162
|
+
name: "include",
|
|
163
|
+
message: "What components should be included in your Alloy build?",
|
|
164
|
+
choices: components,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: "list",
|
|
168
|
+
name: "minify",
|
|
169
|
+
message: "How would you like your JavaScript to be?",
|
|
170
|
+
choices: [
|
|
171
|
+
{ name: "Minified", value: true },
|
|
172
|
+
{ name: "Unminified", value: false },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: "string",
|
|
177
|
+
name: "outputDir",
|
|
178
|
+
message: "Where would you like to save the build?",
|
|
179
|
+
default: process.cwd(),
|
|
180
|
+
},
|
|
181
|
+
])
|
|
182
|
+
.then(async (opts) => {
|
|
183
|
+
const { include } = opts;
|
|
184
|
+
const exclude = components
|
|
185
|
+
.map((v) => v.value)
|
|
186
|
+
.filter((component) => !include.includes(component));
|
|
187
|
+
|
|
188
|
+
opts.exclude = exclude;
|
|
189
|
+
delete opts.include;
|
|
190
|
+
|
|
191
|
+
await build(opts);
|
|
192
|
+
})
|
|
193
|
+
.catch((error) => {
|
|
194
|
+
if (error.isTtyError) {
|
|
195
|
+
console.error(
|
|
196
|
+
"Prompt couldn't be rendered in the current environment",
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
console.error("An error occurred: ", error);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const program = new Command();
|
|
205
|
+
|
|
206
|
+
program
|
|
207
|
+
.name("alloy")
|
|
208
|
+
.description(
|
|
209
|
+
"Tool for generating custom Adobe Experience Platform Web SDK builds.",
|
|
210
|
+
)
|
|
211
|
+
.version("1.0.0");
|
|
212
|
+
|
|
213
|
+
program.addCommand(getMakeBuildCommand());
|
|
214
|
+
program.addCommand(getInteractiveBuildCommand(), { isDefault: true });
|
|
215
|
+
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
|
+
};
|
package/scripts/build-alloy.js
DELETED
|
@@ -1,125 +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
|
-
const argv = yargs(hideBin(process.argv))
|
|
53
|
-
.scriptName("build-alloy")
|
|
54
|
-
.example([
|
|
55
|
-
[`$0 --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
|
|
56
|
-
[`$0 --minify --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
|
|
57
|
-
])
|
|
58
|
-
.option("exclude", {
|
|
59
|
-
describe: "components that can be excluded from the build",
|
|
60
|
-
choices: optionalComponents,
|
|
61
|
-
type: "array",
|
|
62
|
-
alias: "e",
|
|
63
|
-
default: [],
|
|
64
|
-
})
|
|
65
|
-
.option("minify", {
|
|
66
|
-
type: "boolean",
|
|
67
|
-
default: false,
|
|
68
|
-
alias: "m",
|
|
69
|
-
})
|
|
70
|
-
.option("outputDir", {
|
|
71
|
-
alias: "o",
|
|
72
|
-
default: getDefaultPath(),
|
|
73
|
-
})
|
|
74
|
-
.coerce("outputDir", (opt) => {
|
|
75
|
-
if (opt !== getDefaultPath()) {
|
|
76
|
-
opt = `${getDefaultPath()}${path.sep}${opt}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const stats = fs.statSync(opt);
|
|
81
|
-
if (!stats.isDirectory()) {
|
|
82
|
-
throw new Error("Output directory must be a valid directory path.");
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
throw new Error("Output directory must be a valid directory path.");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return opt.replace(new RegExp(`${path.sep}+$`, "g"), "");
|
|
89
|
-
}).argv;
|
|
90
|
-
|
|
91
|
-
const getFile = () => {
|
|
92
|
-
return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const getFileSizeInKB = (filePath) => {
|
|
96
|
-
const stats = fs.statSync(filePath);
|
|
97
|
-
const fileSizeInBytes = stats.size;
|
|
98
|
-
return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const buildWithComponents = async () => {
|
|
102
|
-
const rollupConfig = buildConfig({
|
|
103
|
-
file: getFile(),
|
|
104
|
-
minify: argv.minify,
|
|
105
|
-
babelPlugins: [
|
|
106
|
-
conditionalBuildBabelPlugin(
|
|
107
|
-
argv.exclude.reduce((acc, module) => {
|
|
108
|
-
acc[`alloy_${module}`] = "false";
|
|
109
|
-
return acc;
|
|
110
|
-
}, {}),
|
|
111
|
-
),
|
|
112
|
-
],
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const bundle = await rollup(rollupConfig);
|
|
116
|
-
await bundle.write(rollupConfig.output[0]);
|
|
117
|
-
console.log(
|
|
118
|
-
`🎉 Wrote ${path.relative(
|
|
119
|
-
process.cwd(),
|
|
120
|
-
rollupConfig.output[0].file,
|
|
121
|
-
)} (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
buildWithComponents();
|