at-builder 1.2.2 → 1.2.4

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.
@@ -4,7 +4,8 @@
4
4
  "Bash(npm run build:prod:*)",
5
5
  "Bash(node:*)",
6
6
  "Bash(npx tsc:*)",
7
- "Bash(find:*)"
7
+ "Bash(find:*)",
8
+ "Bash(rm:*)"
8
9
  ],
9
10
  "deny": []
10
11
  }
@@ -11,10 +11,8 @@ const fs = require('fs');
11
11
  * @returns {Array} - Array of actions that plop needs to perform
12
12
  */
13
13
  exports.actionHandler = (data) => {
14
- let { executionPath } = process.env;
15
14
  let actions = [];
16
15
  let fileName = '';
17
- let componentType = '';
18
16
  let folderName = '';
19
17
  let testPath = '';
20
18
  let numberOfVariations;
@@ -30,44 +28,52 @@ exports.actionHandler = (data) => {
30
28
  { 'global': true, 'path': `${testPath}/Vanalytics/analytics.js`, 'templateFile': `${TEMPLATE_DIR}/analytics.hbs`, variation },
31
29
  { 'global': false, 'path': `${folderName}/constants/index.js`, 'templateFile': `${TEMPLATE_DIR}/constants.hbs`, variation },
32
30
  { 'global': false, 'path': `${folderName}/scripts/app.js`, 'templateFile': `${TEMPLATE_DIR}/component.cb.hbs`, variation },
33
- { 'global': false, 'path': `${folderName}/css/style.scss`, 'templateFile': `${TEMPLATE_DIR}/style.hbs`, variation }
31
+ { 'global': false, 'path': `${folderName}/css/style.scss`, 'templateFile': `${TEMPLATE_DIR}/style.hbs`, variation },
32
+ { 'global': true, 'path': `${testPath}/shared/build.config.json`, 'templateFile': `${TEMPLATE_DIR}/build.config.hbs`, variation }
34
33
  ];
35
34
  }
36
35
 
37
- // Get the track path from the environment variable
38
- trackName = executionPath + "/Activities";
39
- // trackName = path.join(fs.readFileSync(path.join(process.cwd(), 'sample.txt'), { flag: 'r' }).toString(), 'Activities');
36
+ // Get the activities path from environment variables (same approach as webpack config)
37
+ const PWD = process.env.executionPath || process.cwd();
38
+ console.log(`šŸ“ Using ACTIVITIES_BASE_FOLDER directory: ${process.env.executionPath}`);
39
+ const ACTIVITIES_BASE_FOLDER = process.env.ACTIVITIES_BASE_FOLDER || 'Activities';
40
+ trackName = path.join(PWD, ACTIVITIES_BASE_FOLDER);
41
+
42
+ // Log the activities path for debugging
43
+ console.log(`šŸ“ Using activities directory: ${trackName}`);
44
+
45
+ // Ensure the activities directory exists
46
+ if (!fs.existsSync(trackName)) {
47
+ fs.mkdirSync(trackName, { recursive: true });
48
+ console.log(`šŸ“ Created activities directory: ${trackName}`);
49
+ }
40
50
 
41
51
  // Convert the name to camel case
42
52
  fileName = toCamelCase(name);
43
53
 
44
54
  // Get the number of variations from the user
45
55
  numberOfVariations = parseInt(variationName);
46
-
56
+
47
57
  let constantMappingFile = null;
48
58
 
49
59
  // If the user has provided track name and test name and variation name
50
60
  if (trackName && testName && variationName) {
51
61
  // Get the current year
52
- let year = new Date().getFullYear();
53
- // testPath = trackName + `/${year}/` + testName;
54
62
  testPath = trackName + `/${testName}`;
55
63
  // Get the constant mapping
56
64
  constantMappingFile = assignConstants();
57
65
  // Convert the name to pascal case
58
66
  fileName = toPascalCase(name);
59
- // Set the component type
60
- componentType = TEMPLATE_TYPE_SUFFIX_CLASS_BASED;
61
67
  }
62
68
 
63
69
  // Create actions for the global files
64
70
  createActionObject(true);
65
71
 
66
-
72
+
67
73
 
68
74
  // Loop through the number of variations provided by the user
69
75
  let i = 1;
70
-
76
+
71
77
  do {
72
78
  // Get the variation name
73
79
  let variation = "Variation-" + i;
@@ -111,9 +117,70 @@ exports.actionHandler = (data) => {
111
117
  });
112
118
  }
113
119
 
120
+ // Update .env file with the new activity name
121
+ updateEnvFile(testName);
114
122
 
123
+ // Show completion message
124
+ console.log(`\nšŸŽ‰ Activity "${testName}" created successfully!`);
125
+ console.log(`šŸ“ Location: ${testPath}`);
126
+ console.log(`šŸ“‹ Number of variations: ${numberOfVariations}`);
127
+ console.log(`šŸ”§ ACTIVITY_FOLDER_NAME updated in .env file`);
128
+ console.log(`\nšŸ’” Run "atb build" to build your activity`);
129
+ console.log(`šŸ’” Run "atb doctor" to check your configuration`);
115
130
 
116
131
  // Return the actions
117
132
  return actions;
118
133
  }
119
134
 
135
+ /**
136
+ * Updates the .env file with the new activity folder name
137
+ * @param {string} activityName - The name of the activity to set in ACTIVITY_FOLDER_NAME
138
+ */
139
+ function updateEnvFile(activityName) {
140
+ const PWD = process.env.executionPath || process.cwd();
141
+ const envPath = path.join(PWD, '.env');
142
+
143
+ if (!fs.existsSync(envPath)) {
144
+ console.log('āš ļø .env file not found, skipping ACTIVITY_FOLDER_NAME update');
145
+ console.log('šŸ’” Run "atb init" to create .env file');
146
+ return;
147
+ }
148
+
149
+ if (!activityName || activityName.trim() === '') {
150
+ console.log('āš ļø Activity name is empty, skipping .env update');
151
+ return;
152
+ }
153
+
154
+ try {
155
+ // Read the current .env file
156
+ let envContent = fs.readFileSync(envPath, 'utf8');
157
+
158
+ // Clean activity name (remove quotes if present)
159
+ const cleanActivityName = activityName.trim().replace(/^["']|["']$/g, '');
160
+
161
+ // Update or add ACTIVITY_FOLDER_NAME
162
+ const activityFolderRegex = /^ACTIVITY_FOLDER_NAME=.*$/m;
163
+ const newLine = `ACTIVITY_FOLDER_NAME="${cleanActivityName}"`;
164
+
165
+ if (activityFolderRegex.test(envContent)) {
166
+ // Update existing line
167
+ envContent = envContent.replace(activityFolderRegex, newLine);
168
+ console.log(`āœ… Updated ACTIVITY_FOLDER_NAME to "${cleanActivityName}" in .env file`);
169
+ } else {
170
+ // Add new line if it doesn't exist, ensure it ends with newline
171
+ if (!envContent.endsWith('\n')) {
172
+ envContent += '\n';
173
+ }
174
+ envContent += newLine;
175
+ console.log(`āœ… Added ACTIVITY_FOLDER_NAME="${cleanActivityName}" to .env file`);
176
+ }
177
+
178
+ // Write the updated content back to .env file
179
+ fs.writeFileSync(envPath, envContent, 'utf8');
180
+
181
+ } catch (error) {
182
+ console.error(`āŒ Error updating .env file: ${error.message}`);
183
+ console.log('šŸ’” You may need to manually set ACTIVITY_FOLDER_NAME in your .env file');
184
+ }
185
+ }
186
+
@@ -5,8 +5,16 @@
5
5
  * Mutation observer initialize
6
6
  */
7
7
 
8
- var observer = new MutationObserver(function (mutations) {
9
-
8
+ const observer = new MutationObserver(function (mutations) {
9
+ mutations.forEach(function (mutation) {
10
+ if (mutation.addedNodes.length) {
11
+ mutation.addedNodes.forEach(function (node) {
12
+ if (node.classList) {
13
+ // do something
14
+ }
15
+ });
16
+ }
17
+ });
10
18
  });
11
19
 
12
20
  // observing now
@@ -19,5 +27,7 @@
19
27
  window.{{windowFlagName}} = true;
20
28
  }
21
29
  }
22
- catch(err){}
30
+ catch (err){
31
+ console.log(err);
32
+ }
23
33
  }());
@@ -0,0 +1,7 @@
1
+ {
2
+ "activityInfo": {
3
+ "id": null,
4
+ "name": "",
5
+ "variations": {}
6
+ }
7
+ }
@@ -1,34 +1,79 @@
1
- {{!-- import { Observer } from '../../../../.globals/services/observer';
2
- import { logger } from '../../../../.globals/services/logger';
3
- import { GetDOMElement } from '../../../../.globals/services/domHandler'; --}}
4
- {{!-- import * as CONSTANTS from '../constants'; --}}
1
+ // import * as CONSTANTS from '../constants';
5
2
 
6
3
  export class App {
7
-
8
4
  /**
9
- * @param define constructor properties
5
+ * @param define constructor properties
10
6
  */
11
- constructor(){
12
- {{!-- this.domHandler = GetDOMElement;
13
- this.loggerService = logger; --}}
14
- };
7
+ constructor() {
8
+ this.state = {}; // For managing app state
9
+ }
15
10
 
16
11
  /**
17
- * Executes on load of the test , observer is initialised
12
+ * Initializes the application, sets up observer and logs the event
18
13
  */
19
14
  init = () => {
20
- {{!-- this.observer = new Observer();
21
- this.observer.setObserver(this.callback); --}}
15
+ this.isRunning = true;
16
+ this.onStart();
17
+ }
18
+
19
+ /**
20
+ * Starts the app or app-specific functionality
21
+ */
22
+ onStart = () => {
23
+ // Additional initialization logic (e.g., setting up listeners, data fetching)
24
+ }
25
+
26
+ /**
27
+ * Reset the app to its initial state
28
+ */
29
+ reset = () => {
30
+ this.state = {}; // Reset state
31
+ this.onStart(); // Optionally restart app functionality
22
32
  }
23
33
 
24
34
  /**
25
- * Disconnet mutation observer , clear any window variable or perform cleanup activity
35
+ * Disconnect mutation observer , clear any window variable or perform cleanup activity
26
36
  */
27
- destroy(){};
28
-
37
+ destroy = () => {
38
+ }
39
+
40
+ /**
41
+ * Handles errors that occur within the app
42
+ * @param {string} message - Error message to log
43
+ * @param {Error} error - Optional error object
44
+ */
45
+ handleError = (message, error = null) => {
46
+ // Additional error handling (e.g., sending error details to a server)
47
+ }
48
+
49
+ /**
50
+ * Logs app's current state
51
+ */
52
+ logState = () => {
53
+ }
54
+
55
+ /**
56
+ * Sets or updates a property in the app's state
57
+ * @param {string} key - The key of the state property
58
+ * @param {any} value - The value to set
59
+ */
60
+ setState = (key, value) => {
61
+ this.state[key] = value;
62
+ }
63
+
64
+ /**
65
+ * Gets a property from the app's state
66
+ * @param {string} key - The key of the state property
67
+ * @returns {any} - The value of the state property
68
+ */
69
+ getState = (key) => {
70
+ return this.state[key];
71
+ }
72
+
29
73
  /**
30
74
  * Mutation Observer Callback
31
75
  */
32
76
  callback = () => {
77
+ // Callback logic for mutation observer
33
78
  }
34
79
  }
@@ -58,4 +58,4 @@ class CustomWrapperPlugin {
58
58
  }
59
59
  }
60
60
 
61
- module.exports = CustomWrapperPlugin;
61
+ export default CustomWrapperPlugin;
package/README.md CHANGED
@@ -3,14 +3,20 @@
3
3
  [![npm version](https://badge.fury.io/js/at-builder.svg)](https://www.npmjs.com/package/at-builder)
4
4
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
5
 
6
- `at-builder` is a simple command-line tool designed to streamline Adobe Target activity creation and building processes.
6
+ A streamlined command-line tool for creating, building, and deploying Adobe Target A/B testing activities with modern web technologies.
7
7
 
8
8
  ---
9
9
 
10
- ## **Features**
10
+ ## **šŸŽÆ Features**
11
11
 
12
- - šŸ”§ **Prod Build**: Build target ready code in your local and ship to any target activity.
13
- - šŸš€ **Help Information**: Get detailed instructions on available commands and usage directly from the CLI.
12
+ - šŸ—ļø **Project Initialization**: Set up new projects with complete configuration
13
+ - šŸŽØ **Activity Templates**: Generate new activities with customizable variations
14
+ - ⚔ **Smart Building**: Development and production builds with hot reload
15
+ - šŸš€ **Adobe Target Deployment**: Direct deployment to Adobe Target activities
16
+ - 🩺 **Health Diagnostics**: Automatic configuration validation and fixing
17
+ - šŸ“ **Flexible Structure**: Configurable activities folder structure
18
+ - šŸ”§ **Environment Management**: Automatic .env file handling
19
+ - šŸ’» **Modern Toolchain**: TypeScript, Webpack, Babel, SCSS support
14
20
 
15
21
  ---
16
22
 
@@ -24,73 +30,244 @@ npm install -g at-builder
24
30
 
25
31
  ---
26
32
 
27
- ## **Usage**
33
+ ## **šŸš€ Quick Start**
28
34
 
29
- Run the command-line tool:
35
+ 1. **Initialize a new project:**
36
+ ```bash
37
+ atb init
38
+ ```
39
+
40
+ 2. **Create a new activity:**
41
+ ```bash
42
+ atb new
43
+ ```
30
44
 
45
+ 3. **Build your activity:**
31
46
  ```bash
32
- atb
47
+ atb build
33
48
  ```
34
49
 
35
- ### **Available Commands**
50
+ 4. **Deploy to Adobe Target:**
51
+ ```bash
52
+ atb deploy
53
+ ```
36
54
 
37
- - **`new`**: Creates a new activity.
38
- - **`build`**: Creates a build.
55
+ ---
56
+
57
+ ## **šŸ“‹ Commands Reference**
58
+
59
+ ### **Core Commands**
60
+
61
+ | Command | Description | Options |
62
+ |---------|-------------|---------|
63
+ | `atb init` | Initialize project with configuration files | |
64
+ | `atb new` | Create new Adobe Target activity with variations | |
65
+ | `atb build` | Build activity for development | `--prod` for production |
66
+ | `atb dev` | Start development server with file watching | `--browser` to open browser |
67
+ | `atb deploy` | Deploy activity to Adobe Target | `--dry-run` for testing |
68
+ | `atb doctor` | Diagnose and fix configuration issues | `--fix` to auto-fix |
39
69
 
40
70
  ### **Examples**
41
71
 
42
72
  ```bash
43
- # Create a new activity
44
- atb -c new
73
+ # Initialize new project
74
+ atb init
75
+
76
+ # Create new activity
77
+ atb new
78
+
79
+ # Development build with hot reload
80
+ atb build
81
+
82
+ # Production build for Adobe Target
83
+ atb build --prod
84
+
85
+ # Development server with browser
86
+ atb dev --browser
45
87
 
46
- # Build the project
47
- atb -c build
88
+ # Deploy to Adobe Target
89
+ atb deploy
48
90
 
49
- # Build the project for target activity
50
- atb -p -c build
91
+ # Check project configuration
92
+ atb doctor
93
+
94
+ # Auto-fix configuration issues
95
+ atb doctor --fix
51
96
  ```
52
97
 
53
98
  ---
54
99
 
55
- ## **API Documentation**
100
+ ## **šŸ”§ Project Structure**
101
+
102
+ After initialization, your project will have:
103
+
104
+ ```
105
+ your-project/
106
+ ā”œā”€ā”€ .env # Environment configuration
107
+ ā”œā”€ā”€ adobe.config.js # Adobe Target API settings
108
+ ā”œā”€ā”€ watch-config.json # Build configuration
109
+ ā”œā”€ā”€ package.json # NPM configuration
110
+ └── Activities/ # Your activities folder
111
+ └── your-activity/ # Activity folder (auto-created)
112
+ ā”œā”€ā”€ Variation-1/ # Test variations
113
+ │ ā”œā”€ā”€ index.js # Entry point
114
+ │ ā”œā”€ā”€ css/
115
+ │ │ └── style.scss
116
+ │ ā”œā”€ā”€ scripts/
117
+ │ │ └── app.js
118
+ │ └── constants/
119
+ │ └── index.js
120
+ ā”œā”€ā”€ Vanalytics/ # Analytics tracking
121
+ └── shared/ # Shared configuration
122
+ ```
56
123
 
57
- ### **`getVersion()`**
124
+ ---
58
125
 
59
- - **Description**: Retrieves the version number from the `package.json` file.
60
- - **Returns**: *(string)* - The version number of the package.
126
+ ## **āš™ļø Configuration**
61
127
 
62
- #### **Example**
128
+ ### **Environment Variables (.env)**
129
+
130
+ ```bash
131
+ # Project Structure
132
+ ACTIVITIES_BASE_FOLDER="Activities"
133
+ ACTIVITY_FOLDER_NAME="your-activity-name"
134
+
135
+ # Development Settings
136
+ NODE_ENV="development"
137
+ PUPPETEER_LANDING_PAGE=""
138
+ TARGET_URL=""
139
+ LOGIN_URL=""
140
+ VARIATION="Variation-1"
141
+
142
+ # Adobe Target Deployment
143
+ ADOBE_CLIENT_ID="your-client-id"
144
+ ADOBE_CLIENT_SECRET="your-client-secret"
145
+ ```
146
+
147
+ ### **Adobe Target Configuration (adobe.config.js)**
63
148
 
64
149
  ```javascript
65
- const { getVersion } = require("at-builder");
150
+ module.exports = {
151
+ BASE_URL: 'https://mc.adobe.io/target/activities/',
152
+ IMS_TOKEN_URL: 'https://ims-na1.adobelogin.com/ims/token/v1',
153
+ IMS_SCOPE: 'openid,target_sdk'
154
+ };
155
+ ```
156
+
157
+ ---
158
+
159
+ ## **šŸ”„ Workflow**
160
+
161
+ 1. **Setup**: Run `atb init` to create project configuration
162
+ 2. **Create**: Run `atb new` to generate activity templates
163
+ 3. **Develop**: Modify variations in `/Activities/{name}/Variation-*/`
164
+ 4. **Test**: Run `atb build` for development testing
165
+ 5. **Build**: Run `atb build --prod` for production deployment
166
+ 6. **Deploy**: Run `atb deploy` to deploy to Adobe Target
66
167
 
67
- console.log(getVersion()); // Outputs the version number of the package
168
+ ---
169
+
170
+ ## **🩺 Troubleshooting**
171
+
172
+ ### **Health Check**
173
+ ```bash
174
+ # Diagnose configuration issues
175
+ atb doctor
176
+
177
+ # Automatically fix issues
178
+ atb doctor --fix
179
+ ```
180
+
181
+ ### **Common Issues**
182
+
183
+ - **Missing .env file**: Run `atb init` or `atb doctor --fix`
184
+ - **Build errors**: Check `ACTIVITY_FOLDER_NAME` in .env
185
+ - **Deploy failures**: Verify Adobe credentials in .env
186
+ - **Missing activity folder**: Create activity with `atb new`
187
+
188
+ ## **🚨 Advanced Configuration**
189
+
190
+ ### **Custom Activities Folder**
191
+
192
+ You can customize the activities folder location:
193
+
194
+ ```bash
195
+ # Use a different activities folder
196
+ ACTIVITIES_BASE_FOLDER="MyActivities"
197
+ ```
198
+
199
+ ### **Build Scripts Integration**
200
+
201
+ Add to your project's package.json:
202
+
203
+ ```json
204
+ {
205
+ "scripts": {
206
+ "build:target": "atb build --prod",
207
+ "deploy:target": "atb deploy",
208
+ "dev:target": "atb dev --browser"
209
+ }
210
+ }
68
211
  ```
69
212
 
70
- ### **`getHelpInfo()`**
213
+ ---
71
214
 
72
- - **Description**: Provides a string containing help information for the `atb` command-line tool.
73
- - **Returns**: *(string)* - The help information string.
215
+ ## **šŸ”Œ API Integration**
74
216
 
75
- #### **Example**
217
+ For programmatic usage:
76
218
 
77
219
  ```javascript
78
- const { getHelpInfo } = require("at-builder");
220
+ const { getVersion, getHelpInfo } = require("at-builder");
221
+
222
+ // Get version
223
+ console.log(getVersion());
79
224
 
225
+ // Get help information
80
226
  console.log(getHelpInfo());
81
- // Outputs detailed help information for the CLI tool
82
227
  ```
83
228
 
84
229
  ---
85
230
 
86
- ## **License**
231
+ ## **šŸ¤ Contributing**
232
+
233
+ 1. Fork the repository
234
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
235
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
236
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
237
+ 5. Open a Pull Request
238
+
239
+ ---
240
+
241
+ ## **šŸ“ Changelog**
242
+
243
+ ### v1.2.3
244
+ - ✨ Added `deploy` command for Adobe Target deployment
245
+ - 🩺 Added `doctor` command for configuration diagnostics
246
+ - šŸ”§ Automatic .env file updates when creating activities
247
+ - šŸ“ Configurable activities folder structure
248
+ - ⚔ Improved environment variable validation
249
+ - šŸš€ Enhanced error handling and user guidance
250
+
251
+ ### Previous Versions
252
+ - v1.2.2: Build improvements and bug fixes
253
+ - v1.2.1: Enhanced CLI interface
254
+ - v1.2.0: Initial public release
255
+
256
+ ---
257
+
258
+ ## **šŸ“„ License**
87
259
 
88
260
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
89
261
 
90
262
  ---
91
263
 
92
- ## **Support**
264
+ ## **šŸ†˜ Support**
265
+
266
+ - **Repository**: [https://github.com/upesenga/at-builder](https://github.com/upesenga/at-builder)
267
+ - **Issues**: [https://github.com/upesenga/at-builder/issues](https://github.com/upesenga/at-builder/issues)
268
+ - **Author**: Upendra Sengar
269
+ - **License**: MIT
93
270
 
94
- If you encounter any issues or have questions, feel free to email.
271
+ ---
95
272
 
96
- ---
273
+ **Made with ā¤ļø for Adobe Target developers**