@appdirect/sfb-toolkit 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/Dockerfile +1 -1
  2. package/bin/index.js +33 -23
  3. package/coverage/clover.xml +2 -2
  4. package/coverage/lcov-report/constants/customUserAttributesMock.js.html +1 -1
  5. package/coverage/lcov-report/constants/index.html +1 -1
  6. package/coverage/lcov-report/constants/pageUrls.js.html +1 -1
  7. package/coverage/lcov-report/constants/userMock.js.html +1 -1
  8. package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +1 -1
  9. package/coverage/lcov-report/controllers/controllers-utils/index.html +1 -1
  10. package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +1 -1
  11. package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +1 -1
  12. package/coverage/lcov-report/controllers/data-filters/index.html +1 -1
  13. package/coverage/lcov-report/controllers/index.html +1 -1
  14. package/coverage/lcov-report/controllers/index.js.html +1 -1
  15. package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +1 -1
  16. package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +1 -1
  17. package/coverage/lcov-report/front-end-utils/src/components/base/index.html +1 -1
  18. package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +1 -1
  19. package/coverage/lcov-report/front-end-utils/src/components/container.js.html +1 -1
  20. package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +1 -1
  21. package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +1 -1
  22. package/coverage/lcov-report/front-end-utils/src/components/index.html +1 -1
  23. package/coverage/lcov-report/front-end-utils/src/components/search.js.html +1 -1
  24. package/coverage/lcov-report/front-end-utils/src/constants/index.html +1 -1
  25. package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +1 -1
  26. package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +1 -1
  27. package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +1 -1
  28. package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +1 -1
  29. package/coverage/lcov-report/front-end-utils/src/utils/index.html +1 -1
  30. package/coverage/lcov-report/index.html +1 -1
  31. package/coverage/lcov-report/middlewares/config.js.html +1 -1
  32. package/coverage/lcov-report/middlewares/index.html +1 -1
  33. package/npm-shrinkwrap.json +46542 -16911
  34. package/package.json +7 -4
  35. package/readme.md +11 -1
  36. package/src/tools/prompt-questions.js +31 -11
  37. package/src/tools/toolkit-about.js +7 -7
  38. package/src/tools/toolkit-checkout.js +8 -8
  39. package/src/tools/toolkit-common-fun.js +35 -17
  40. package/src/tools/toolkit-common-vars.js +17 -2
  41. package/src/tools/toolkit-components.js +26 -14
  42. package/src/tools/toolkit-config-setup.js +10 -10
  43. package/src/tools/toolkit-config.js +0 -1
  44. package/src/tools/toolkit-create-extension.js +93 -0
  45. package/src/tools/toolkit-create.js +14 -14
  46. package/src/tools/toolkit-install.js +5 -4
  47. package/src/tools/toolkit-package.js +5 -4
  48. package/src/tools/toolkit-setup-e2e.js +14 -14
  49. package/src/tools/toolkit-setup.js +13 -13
  50. package/src/tools/toolkit-status.js +2 -2
  51. package/src/tools/toolkit-storybook.js +4 -3
  52. package/src/tools/toolkit-update.js +5 -5
  53. package/src/tools/zip-theme.js +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appdirect/sfb-toolkit",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -55,8 +55,9 @@
55
55
  "name": "appdirect/sfb-toolkit"
56
56
  },
57
57
  "dependencies": {
58
- "@appdirect/sfb-theme-classic": "0.0.26",
59
- "@appdirect/sfb-theme-plaza": "0.0.57",
58
+ "@appdirect/public-custom-app-ui": "^0.0.12",
59
+ "@appdirect/sfb-theme-classic": "TO_CHANGE",
60
+ "@appdirect/sfb-theme-plaza": "TO_CHANGE",
60
61
  "@babel/core": "^7.19.1",
61
62
  "@babel/plugin-proposal-class-properties": "^7.18.6",
62
63
  "@babel/plugin-transform-runtime": "^7.19.1",
@@ -73,6 +74,7 @@
73
74
  "babel-loader": "^8.2.5",
74
75
  "babel-preset-minify": "^0.5.2",
75
76
  "body-parser": "^1.20.0",
77
+ "chalk": "^4.1.2",
76
78
  "cheerio": "^1.0.0-rc.12",
77
79
  "colors": "^1.4.0",
78
80
  "commander": "^9.4.0",
@@ -109,8 +111,9 @@
109
111
  "react-json-view": "^1.21.3",
110
112
  "react-select": "^4.3.1",
111
113
  "react-syntax-highlighter": "^15.5.0",
114
+ "replace-in-file": "^6.3.5",
115
+ "rimraf": "^4.1.3",
112
116
  "sass": "^1.55.0",
113
- "sass-loader": "^13.0.2",
114
117
  "scheduler": "^0.19.1",
115
118
  "seamless-immutable": "^7.1.4",
116
119
  "snapstub": "^5.0.1",
package/readme.md CHANGED
@@ -9,6 +9,16 @@ It can be easily mixed with eg. HTML, CSS, JavaScript, jQuery, SASS.
9
9
  * Node 16.x for versions 4.x.x
10
10
 
11
11
  ### Release Notes:
12
+ **4.0.3**
13
+ - Update `@appdirect/sfb-theme-plaza` to version 0.0.64 ([sfb-theme-mp2@0.0.64](https://www.npmjs.com/package/@appdirect/sfb-theme-plaza/v/0.0.64))
14
+ - Update `sfb-theme-components` library to version [0.0.321](https://www.npmjs.com/package/@appdirect/sfb-theme-components/v/0.0.321)
15
+
16
+ **4.0.2**
17
+ - `sfb-components` bundles are split by storefront page to improve LCP performance.
18
+ - Bug fix: Fix custom components with sfb-toolkit@4 on Windows.
19
+ - Bug fix: Fix favicon not showing in the Plaza theme.
20
+ - Update `@appdirect/sfb-theme-plaza` to version 0.0.59 ([sfb-theme-mp2@0.0.59](https://www.npmjs.com/package/@appdirect/sfb-theme-plaza/v/0.0.59))
21
+ - Update `sfb-theme-components` library to version [0.0.315](https://www.npmjs.com/package/@appdirect/sfb-theme-components/v/0.0.315)
12
22
 
13
23
  **4.0.1**
14
24
  - Toolkit is now able to work on Node 16.
@@ -140,7 +150,7 @@ Developers can have multiple themes in a single environment.
140
150
  - [Checkout Integration](https://help.appdirect.com/platform/Default.htm#StorefrontBuilder/sfb-checkout-intro.htm)
141
151
  - [Video Tutorials](https://help.appdirect.com/platform/Default.htm#StorefrontBuilder/sfb-toolkit-intro.htm)
142
152
  - [Nunjucks Template System Documentation](https://mozilla.github.io/nunjucks/)
143
- - [Contact Support](storefrontbuilder@appdirect.com)
153
+ - [Contact Support](mailto:storefrontbuilder@appdirect.com)
144
154
 
145
155
 
146
156
  This Repository is owned and maintained by Storefront Builder Team @ AppDirect Inc.
@@ -1,7 +1,8 @@
1
1
  const fs = require("fs")
2
2
  const inquirer = require("inquirer")
3
3
  const axios = require("axios")
4
- const { TOOLKIT_GLOBAL_CONFIG, THEME_TEMPLATES, WHO_ARE_YOU_PROMPT} = require("./toolkit-common-vars")
4
+ const chalk = require("chalk")
5
+ const { TOOLKIT_GLOBAL_CONFIG, THEME_TEMPLATES, WHO_ARE_YOU_PROMPT, EXTENSION_PROMPT } = require("./toolkit-common-vars")
5
6
 
6
7
  // small function to check if item has been defined
7
8
  const isDefined = answer => !!answer
@@ -11,7 +12,7 @@ const isValidFolderName = toTest => {
11
12
  const pattern = new RegExp(/^[a-z0-9_-]+$/, "i")
12
13
  const result = pattern.test(toTest)
13
14
  if (!result) {
14
- console.error(`\n${toTest} does not seem as valid folder name.`.red)
15
+ console.error(chalk.red(`\n${toTest} does not seem as valid folder name.`))
15
16
  }
16
17
  return toTest !== "undefined" && result
17
18
  }
@@ -34,7 +35,7 @@ const isValidURL = toTest => {
34
35
  )
35
36
  const result = pattern.test(toTest)
36
37
  if (!result) {
37
- console.error(`\n"${toTest}" does not seem as valid URL.`.red)
38
+ console.error(chalk.red(`\n"${toTest}" does not seem as valid URL.`))
38
39
  }
39
40
  return result
40
41
  }
@@ -50,20 +51,19 @@ const isValidMarketplaceURL = async toTest => {
50
51
  } catch (err) {
51
52
  switch (err.code) {
52
53
  case "ETIMEDOUT":
53
- console.log(
54
+ console.log(chalk.red(
54
55
  ` Unable to reach ${toTest}. Please make sure to provide valid marketplace URL and that if you are running a proxy, is it configured correctly with node https://jjasonclark.com/how-to-setup-node-behind-web-proxy/ \n`
55
- .red
56
- )
56
+ ))
57
57
  break
58
58
  default:
59
- console.log(
60
- ` ${toTest} does not seem to be a valid marketplace URL.\n`.red
61
- )
59
+ console.log(chalk.red(
60
+ ` ${toTest} does not seem to be a valid marketplace URL.\n`
61
+ ))
62
62
  break
63
63
  }
64
64
  return false
65
65
  }
66
- console.log(" Marketplace URL successfully verified.\n".green)
66
+ console.log(chalk.green(" Marketplace URL successfully verified.\n"))
67
67
  return true
68
68
  }
69
69
 
@@ -122,7 +122,27 @@ const QUESTIONS = [
122
122
  name: "PackSettingsChoice",
123
123
  message: "Do you want to include the Storefront Builder layout editor settings in this package? (This will override existing settings in the editor)",
124
124
  default: false
125
- }
125
+ },
126
+ {
127
+ type: "list",
128
+ name: "CreateExtension",
129
+ message: "Please select the type of extension you want to build:",
130
+ choices: EXTENSION_PROMPT,
131
+ },
132
+ {
133
+ type: "input",
134
+ name: "ExtensionName",
135
+ message:
136
+ "Name of the extension you want to build (letter & underscore only):",
137
+ validate: isValidFolderName,
138
+ },
139
+ {
140
+ type: "input",
141
+ name: "AppPath",
142
+ message:
143
+ "Path to the extension you want to build on the marketplace /app/:mypath (letter & dash, only) (This can be changed later):",
144
+ validate: isValidFolderName,
145
+ },
126
146
  ]
127
147
 
128
148
  // use only selected question
@@ -1,6 +1,6 @@
1
- const fs = require("fs")
2
- const moment = require("moment")
3
- const colors = require("colors")
1
+ const fs = require("fs");
2
+ const moment = require("moment");
3
+ const chalk = require("chalk");
4
4
 
5
5
  const { shouldBeProjectFolder } = require("./toolkit-common-fun");
6
6
  const { LOCAL_CONFIG } = require("./toolkit-config");
@@ -11,14 +11,14 @@ shouldBeProjectFolder(true);
11
11
  (() => {
12
12
  try {
13
13
  const projectData = LOCAL_CONFIG.read();
14
- console.log(`\n Available themes for ${projectData.projectName}:`)
14
+ console.log(`\n Available themes for ${projectData.projectName}:`);
15
15
  projectData.namespaces
16
16
  .map(namespace => {
17
- let parsedName = namespace.themeName === projectData.current ? `* ${namespace.themeName}`.yellow : ` ${namespace.themeName}`;
17
+ let parsedName = namespace.themeName === projectData.current ? `* ${chalk.yellow(namespace.themeName)}` : ` ${namespace.themeName}`;
18
18
  console.log(` ${parsedName}`)
19
19
  });
20
20
  console.log(`\n To switch to a different theme configuration, run \`sfb-toolkit checkout [themeName]\`\n`);
21
21
  } catch ( err ) {
22
- console.error(`\n ERROR: Unable to find configuration for current project due to: ${err}.\n`.red);
22
+ console.error(chalk.red(`\n ERROR: Unable to find configuration for current project due to: ${err}.\n`));
23
23
  }
24
- })();
24
+ })();
@@ -1,6 +1,6 @@
1
1
  const fs = require("fs")
2
- const colors = require("colors")
3
2
  const { spawn } = require("child_process")
3
+ const chalk = require("chalk")
4
4
 
5
5
  const { COMMAND_PARAM, TOOLKIT_PATH, COMPILERCSS_PATH } = require("./toolkit-common-vars");
6
6
  const { shouldBeProjectFolder } = require("./toolkit-common-fun");
@@ -12,7 +12,7 @@ const themeName = COMMAND_PARAM;
12
12
  shouldBeProjectFolder(true);
13
13
 
14
14
  if(!validateFun.isValidFolderName(themeName)){
15
- console.error(` ERROR: Please provide the theme name to checkout.`.red);
15
+ console.error(chalk.red(` ERROR: Please provide the theme name to checkout.`));
16
16
  process.exit(1);
17
17
  }
18
18
 
@@ -21,26 +21,26 @@ if(!validateFun.isValidFolderName(themeName)){
21
21
  try {
22
22
  projectData = LOCAL_CONFIG.read();
23
23
  } catch (err) {
24
- console.error(`\n ERROR: Unable to find configuration for current project due to: ${err}.\n`.red)
24
+ console.error(chalk.red(`\n ERROR: Unable to find configuration for current project due to: ${err}.\n`))
25
25
  process.exit(1);
26
26
  }
27
27
  const themeExists = projectData.namespaces.filter(namespace => namespace.themeName == themeName).length;
28
28
  if(!themeExists){
29
- console.error(` ERROR: Unable to find theme ${themeName} in current project.`.red);
29
+ console.error(chalk.red(` ERROR: Unable to find theme ${themeName} in current project.`));
30
30
  process.exit(1);
31
31
  }
32
32
  try {
33
33
  LOCAL_CONFIG.save({...projectData, current: themeName, modified: new Date()});
34
34
  } catch (err) {
35
- console.error(` ERROR: Unable to switch context to ${themeName} due to: ${err}`.red);
35
+ console.error(chalk.red(` ERROR: Unable to switch context to ${themeName} due to: ${err}`));
36
36
  process.exit(1);
37
37
  }
38
38
  try {
39
39
  LOCAL_CONFIG.configFileUpdate();
40
- console.log(` Context switched to ${themeName}.`.green);
41
- console.log("\n ** Please make sure to start or restart server to see changes ** \n".green);
40
+ console.log(chalk.green(` Context switched to ${themeName}.`));
41
+ console.log(chalk.green("\n ** Please make sure to start or restart server to see changes ** \n"));
42
42
  } catch (err) {
43
- console.error(` ERROR: Unable to switch context to ${themeName} due to: ${err}`.red);
43
+ console.error(chalk.red(` ERROR: Unable to switch context to ${themeName} due to: ${err}`));
44
44
  process.exit(1);
45
45
  }
46
46
 
@@ -1,15 +1,15 @@
1
1
  const fs = require("fs-extra");
2
2
  const moment = require("moment");
3
- const colors = require("colors");
4
3
  const prompt = require("./prompt-questions");
5
4
  const packageJson = require('package-json');
6
5
  const { spawnSync } = require("child_process");
6
+ const chalk = require("chalk")
7
7
 
8
8
  const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_PATH, THEME_COMPONENT_MODULE,
9
- THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH } = require("./toolkit-common-vars");
9
+ THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH, SASS_MODULE,
10
+ SASS_VERSION, SASS_LOADER_MODULE, SASS_LOADER_VERSION } = require("./toolkit-common-vars");
10
11
  const { has } = require("lodash");
11
12
 
12
-
13
13
  // function to remove project's folders (used to revert changes on error)
14
14
  const selfDestruction = (dir) => BOOTSTRAP_FOLDERS.forEach( file => fs.removeSync(`${dir}/${file}`));
15
15
 
@@ -24,11 +24,11 @@ const shouldBeProjectFolder = (should) => {
24
24
  const isProjectFolder = isProjectsFolder(CURRENT_PATH);
25
25
  switch(true){
26
26
  case !should && isProjectFolder:
27
- console.error(` ERROR: Unable to perform requested action. Please navigate away from the project folder.`.red);
27
+ console.error(chalk.red(` ERROR: Unable to perform requested action. Please navigate away from the project folder.`));
28
28
  process.exit(1);
29
29
  break;
30
30
  case should && !isProjectFolder:
31
- console.error(` ERROR: Unable to perform requested action. Please navigate to a project folder.`.red);
31
+ console.error(chalk.red(` ERROR: Unable to perform requested action. Please navigate to a project folder.`));
32
32
  process.exit(1);
33
33
  break;
34
34
  }
@@ -73,7 +73,7 @@ const getAvailableFolderWithPrompt = async (path, name, askFor, createIfNotExist
73
73
  if (err && err.code === 'ENOENT') {
74
74
  if (createIfNotExists) {
75
75
  fs.mkdirSync(`${path}/${name}`);
76
- console.log(` Folder ${path}/${name} created.`.green);
76
+ console.log(chalk.green(` Folder ${path}/${name} created.`));
77
77
  }
78
78
  return resolve(`${path}/${name}`);
79
79
  }
@@ -81,7 +81,7 @@ const getAvailableFolderWithPrompt = async (path, name, askFor, createIfNotExist
81
81
  // check if empty
82
82
  return resolve(`${path}/${name}`);
83
83
  }
84
- console.error(` ERROR: Unable to use a path ${path}/${name}. Folder already exists and is not empty. Try different name or try removing existing folder.`.red);
84
+ console.error(chalk.red(` ERROR: Unable to use a path ${path}/${name}. Folder already exists and is not empty. Try different name or try removing existing folder.`));
85
85
  const userAnswer = await prompt.ask([askFor]);
86
86
  return resolve(getAvailableFolderWithPrompt(path, userAnswer[askFor], askFor, createIfNotExists, canBeEmpty));
87
87
  });
@@ -111,7 +111,7 @@ const installSfbThemeComponents = () => {
111
111
 
112
112
  // check if sfb-theme-components is installed otherwise install it
113
113
  spawnSync('npm',
114
- [`ls ${THEME_COMPONENT_MODULE} 2>&1 | (findstr ${THEME_COMPONENT_MODULE} || grep ${THEME_COMPONENT_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION} --production --legacy-peer-deps`], {
114
+ [`ls ${THEME_COMPONENT_MODULE} 2>&1 | (findstr ${THEME_COMPONENT_MODULE} || grep ${THEME_COMPONENT_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION} --omit=dev --legacy-peer-deps`], {
115
115
  cwd: ACTIVE_THEME_PATH,
116
116
  stdio: "inherit",
117
117
  shell: true
@@ -158,9 +158,17 @@ const updateCustomComponentsMetadata = (data) => {
158
158
  if (hasPackageJson) {
159
159
  const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
160
160
  const sfbThemeComponentsVersion = themePackageJson.dependencies['@appdirect/sfb-theme-components'];
161
- data = data.replace('data-custom-components="false"', 'data-custom-components="true"');
162
- if(sfbThemeComponentsVersion)
161
+ const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
162
+ const customComponents = fs.existsSync(customComponentsPath);
163
+ if (customComponents && sfbThemeComponentsVersion) {
164
+ data = data.replace('data-custom-components="false"', 'data-custom-components="true"');
165
+ }
166
+ if (!customComponents) {
167
+ data = data.replace('data-custom-components="true"', 'data-custom-components="false"');
168
+ }
169
+ if(sfbThemeComponentsVersion) {
163
170
  data = data.replace(/data-sfb-theme-components-version=".*"/, `data-sfb-theme-components-version="${sfbThemeComponentsVersion}"`);
171
+ }
164
172
  }
165
173
  return data;
166
174
  }
@@ -176,8 +184,7 @@ const addMetadata = (metadata = {}, themePath) => {
176
184
  fs.writeFileSync(baseFilePath, updatedMetadata);
177
185
  return;
178
186
  }
179
- const headElemIndex = baseFileData.indexOf('<head>');
180
- const headElemLength = '<head>'.length;
187
+ const headElemIndex = baseFileData.indexOf('</head>');
181
188
  const providedMetadata = Object.keys(metadata).length;
182
189
 
183
190
  let themeTemplate;
@@ -220,20 +227,30 @@ const addMetadata = (metadata = {}, themePath) => {
220
227
  }
221
228
  }
222
229
 
223
- const output = baseFileData.substring(0, headElemIndex + headElemLength)
224
- + `\n <ad-theme`
230
+ const output = baseFileData.substring(0, headElemIndex)
231
+ + ` <ad-theme`
225
232
  + (themeTemplate ? `\n data-theme-template="${themeTemplate}"` : '')
226
233
  + (themeVersion ? `\n data-theme-version="${themeVersion}"` : '')
227
234
  + (createdBy ? `\n data-created-by="${createdBy}"` :'')
228
235
  + (createdAt ? `\n data-created-at="${createdAt}"` : '')
229
236
  + `\n data-custom-components="${customComponents}"`
230
237
  + `\n data-sfb-theme-components-version="${sfbThemeComponentsVersion}">`
231
- + `\n </ad-theme>`
232
- + baseFileData.substring(headElemIndex + headElemLength);
238
+ + `\n </ad-theme>\n`
239
+ + baseFileData.substring(headElemIndex);
233
240
 
234
241
  fs.writeFileSync(baseFilePath, output);
235
242
  }
236
243
 
244
+ const installSass = () => {
245
+ // install sass and sass-loader
246
+ spawnSync('npm',
247
+ [`i -S ${SASS_MODULE}@${SASS_VERSION} ${SASS_LOADER_MODULE}@${SASS_LOADER_VERSION} --omit=dev --legacy-peer-deps`], {
248
+ cwd: ACTIVE_THEME_PATH,
249
+ stdio: "inherit",
250
+ shell: true
251
+ })
252
+ }
253
+
237
254
  module.exports = {
238
255
  selfDestruction,
239
256
  filesCounter,
@@ -247,5 +264,6 @@ module.exports = {
247
264
  createThemeLogsFolder,
248
265
  createCustomThemePacakgeJson,
249
266
  updateCustomComponentsMetadata,
250
- addMetadata
267
+ addMetadata,
268
+ installSass
251
269
  }
@@ -15,7 +15,11 @@ const THEME_TEMPLATES_CONFIG_PATH = `${TOOLKIT_PATH}/themes-config.json`;
15
15
  const THEME_TEMPLATES = JSON.parse(fs.readFileSync(THEME_TEMPLATES_CONFIG_PATH));
16
16
  const PAGE_OBJECTS_SUFFIX = "/api/internal/storefront/v1";
17
17
  const THEME_COMPONENT_MODULE = "@appdirect/sfb-theme-components";
18
- const THEME_COMPONENT_VERSION = "0.0.293";
18
+ const THEME_COMPONENT_VERSION = "0.0.321";
19
+ const SASS_MODULE = "sass";
20
+ const SASS_VERSION = "1.57.1";
21
+ const SASS_LOADER_MODULE = "sass-loader";
22
+ const SASS_LOADER_VERSION = "13.2.0";
19
23
 
20
24
  let WORKSPACE_CONFIG;
21
25
  try {
@@ -34,6 +38,12 @@ const WHO_ARE_YOU_PROMPT = [
34
38
  { "name": "external dev" }
35
39
  ]
36
40
 
41
+ const EXTENSION_PROMPT = [
42
+ { name: "Blank Extension" },
43
+ { name: "DataGrid Boilerplate" },
44
+ { name: "Dashboard Boilerplate" }
45
+ ]
46
+
37
47
  module.exports = {
38
48
  TOOLKIT_GLOBAL_CONFIG,
39
49
  BOOTSTRAP_FOLDERS,
@@ -50,7 +60,12 @@ module.exports = {
50
60
  THEME_TEMPLATES,
51
61
  THEME_COMPONENT_MODULE,
52
62
  THEME_COMPONENT_VERSION,
63
+ SASS_MODULE,
64
+ SASS_VERSION,
65
+ SASS_LOADER_MODULE,
66
+ SASS_LOADER_VERSION,
53
67
  THEME_LOGS_PATH,
54
68
  THEME_LOGS_FILE_PATH,
55
- WHO_ARE_YOU_PROMPT
69
+ WHO_ARE_YOU_PROMPT,
70
+ EXTENSION_PROMPT,
56
71
  }
@@ -1,16 +1,17 @@
1
1
  const fs = require("fs-extra")
2
+ const chalk = require("chalk")
2
3
  const { shouldBeProjectFolder, installSfbThemeComponents,
3
- createPackageJson, updateCustomComponentsMetadata } = require("./toolkit-common-fun");
4
- const { ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
4
+ createPackageJson, updateCustomComponentsMetadata, installSass } = require("./toolkit-common-fun");
5
+ const { ACTIVE_THEME_PATH, TOOLKIT_PATH } = require("./toolkit-common-vars");
5
6
 
6
7
  shouldBeProjectFolder(true);
7
8
 
8
9
  const addCustomCompToBase = (baseFilePath, data) => {
9
10
  fs.writeFile(baseFilePath, data, (err) => {
10
- if (err) return console.error(' ERROR: Unable to perform update to use custom components.'.red);
11
- console.log('Successfully installed custom components!\nPlease start/restart the toolkit server to observe the changes.'.green);
12
- console.log('\n\nFor custom components documentation please execute the following command:'.green)
13
- console.log('sfb-toolkit storybook\n'.cyan)
11
+ if (err) return console.error(chalk.red(' ERROR: Unable to perform update to use custom components.'));
12
+ console.log(chalk.green('Successfully installed custom components!\nPlease start/restart the toolkit server to observe the changes.'));
13
+ console.log(chalk.green('\n\nFor custom components documentation please execute the following command:'))
14
+ console.log(chalk.cyan('sfb-toolkit storybook\n'))
14
15
  });
15
16
  }
16
17
 
@@ -25,23 +26,28 @@ const settingsSchemaData = `{ "useComponents": true }`;
25
26
 
26
27
  installSfbThemeComponents();
27
28
 
29
+ installSass();
30
+
28
31
  if(!fs.existsSync(`${ACTIVE_THEME_PATH}/settings-schema.json`)) {
29
32
  fs.writeFile(`${ACTIVE_THEME_PATH}/settings-schema.json`, settingsSchemaData, (err) => {
30
- if (err) return console.error(' ERROR: Unable to create settings-schema.json file.'.red);
33
+ if (err) return console.error(chalk.red(' ERROR: Unable to create settings-schema.json file.'));
31
34
  })
32
35
  }
33
36
 
34
37
  if (!customComponentsEnabled) {
35
- fs.copy(`${__dirname}/../../customComponents`, customComponentsPath, err => {
36
- if (err) return console.error(' ERROR: Unable to copy required files'.red);
37
- })
38
+ try {
39
+ fs.copySync(`${TOOLKIT_PATH}/customComponents`, customComponentsPath)
40
+ } catch (error) {
41
+ return console.error(chalk.red(` ERROR: Unable to copy required files\n ${error}`));
42
+ }
38
43
  }
39
44
 
40
45
  fs.readFile(baseFilePath, 'utf8', (err, data) => {
41
- if (err) return console.error(` ERROR: Unable to read the base layout file. Tried: ${baseFilePath}`.red);
46
+ if (err) return console.error(chalk.red(` ERROR: Unable to read the base layout file. Tried: ${baseFilePath}`));
42
47
 
43
48
  const cdnComponents = data.match(/\S+.+channelCanonicalBaseUrl.+(css|js).+/g);
44
49
  const assetsComponents = data.match(/\S+.+r\(.+assets.+sfb-components.+(css|js).+/g);
50
+ const splitBundles = data.match(/componentsBundles\(config\)/g);
45
51
 
46
52
  if (cdnComponents !== null) {
47
53
  data = data.replace(/\S+.+channelCanonicalBaseUrl.+css.+/,
@@ -54,6 +60,12 @@ const settingsSchemaData = `{ "useComponents": true }`;
54
60
 
55
61
  addCustomCompToBase(baseFilePath, data);
56
62
 
63
+ } else if (splitBundles !== null) {
64
+ data = data.replace('componentsBundles(config)', 'customComponentsBundles(config)');
65
+
66
+ data = updateCustomComponentsMetadata(data);
67
+
68
+ addCustomCompToBase(baseFilePath, data);
57
69
  } else if (assetsComponents === null) {
58
70
  data = updateCustomComponentsMetadata(data);
59
71
 
@@ -67,9 +79,9 @@ const settingsSchemaData = `{ "useComponents": true }`;
67
79
  addCustomCompToBase(baseFilePath, output);
68
80
 
69
81
  } else {
70
- console.log('Theme is already setup to use custom components.'.green)
71
- console.log('\n\nFor custom components documentation please execute the following command:'.green)
72
- console.log('sfb-toolkit storybook\n'.cyan)
82
+ console.log(chalk.green('Theme is already setup to use custom components.'))
83
+ console.log(chalk.green('\n\nFor custom components documentation please execute the following command:'))
84
+ console.log(chalk.cyan('sfb-toolkit storybook\n'))
73
85
  }
74
86
  })
75
87
  })();
@@ -1,6 +1,6 @@
1
1
  const fs = require("fs")
2
2
  const { copy } = require("fs-extra")
3
- const colors = require("colors")
3
+ const chalk = require("chalk")
4
4
  const prompt = require("./prompt-questions");
5
5
  const { TOOLKIT_GLOBAL_CONFIG} = require("./toolkit-common-vars")
6
6
 
@@ -24,12 +24,12 @@ let freshLocalConfig = {
24
24
  // Determine project's dir path
25
25
  let projectPath = `${CURRENT_PATH}/`; // by default
26
26
  if (!prompt.validateFun.isValidFolderName(projectName)){
27
- console.error(`Not valid project name`.red);
27
+ console.error(chalk.red(`Not valid project name`));
28
28
  process.exit(1);
29
29
  }
30
30
 
31
31
  if(!prompt.validateFun.isValidFolderName(themeName)){
32
- console.error(`Not valid theme name`.red);
32
+ console.error(chalk.red(`Not valid theme name`));
33
33
  process.exit(1);
34
34
  }
35
35
 
@@ -57,7 +57,7 @@ let freshLocalConfig = {
57
57
  freshLocalConfig.defaultValues.marketplacePath = TOOLKIT_GLOBAL_CONFIG.defaultValues.marketplacePath;
58
58
  freshLocalConfig.defaultValues.pageObjectsPath = `${TOOLKIT_GLOBAL_CONFIG.defaultValues.marketplacePath}${PAGE_OBJECTS_SUFFIX}`;
59
59
  } catch (err) {
60
- console.error(` Couldn't copy config file due to: \n ${err}`.red);
60
+ console.error(chalk.red(` Couldn't copy config file due to: \n ${err}`));
61
61
  selfDestruction(projectPath); // revert changes
62
62
  process.exit(1);
63
63
  }
@@ -70,19 +70,19 @@ let freshLocalConfig = {
70
70
  try {
71
71
  LOCAL_CONFIG.save(freshLocalConfig, projectPath);
72
72
  } catch (err) {
73
- console.error(` ERROR: Unable to save config file due to: \n ${err}`.red);
73
+ console.error(chalk.red(` ERROR: Unable to save config file due to: \n ${err}`));
74
74
  process.exit(1);
75
75
  }
76
76
 
77
77
  try {
78
78
  LOCAL_CONFIG.configFileUpdate(projectPath);
79
- console.log(` Project context switched to ${freshLocalConfig.current}.`.green);
79
+ console.log(chalk.green(` Project context switched to ${freshLocalConfig.current}.`));
80
80
  } catch ( err ) {
81
- console.error(` ERROR: Unable to switch context to ${freshLocalConfig.current} due to: ${err}`.red);
81
+ console.error(chalk.red(` ERROR: Unable to switch context to ${freshLocalConfig.current} due to: ${err}`));
82
82
  process.exit(1);
83
83
  }
84
84
 
85
- console.log(` Theme location: ${projectPath}/`.green)
86
- console.log(` Configuration file location: ${projectPath}/config/`.green)
87
- console.log(`\n All done for config setup! ${projectPath}\n`.green);
85
+ console.log(chalk.green(` Theme location: ${projectPath}/`))
86
+ console.log(chalk.green(` Configuration file location: ${projectPath}/config/`))
87
+ console.log(chalk.green(`\n All done for config setup! ${projectPath}\n`));
88
88
  })();
@@ -45,4 +45,3 @@ module.exports = {
45
45
  configFileUpdate
46
46
  }
47
47
  }
48
-
@@ -0,0 +1,93 @@
1
+ const { copy } = require("fs-extra");
2
+ const colors = require("colors");
3
+ const rimraf = require("rimraf");
4
+ const replace = require("replace-in-file");
5
+ const prompt = require("./prompt-questions");
6
+
7
+ const { CURRENT_PATH, TOOLKIT_PATH } = require("./toolkit-common-vars");
8
+ const { shouldBeProjectFolder } = require("./toolkit-common-fun");
9
+
10
+ shouldBeProjectFolder(true);
11
+ (async () => {
12
+ // by default
13
+
14
+ try {
15
+ const { CreateExtension } = await prompt.ask(["CreateExtension"]);
16
+ const { ExtensionName } = await prompt.ask(["ExtensionName"]);
17
+ const { AppPath } = await prompt.ask(["AppPath"]);
18
+ const { MarketplacePath } = await prompt.ask(["MarketplacePath"]);
19
+ console.log("------------****-----------\n");
20
+ console.log(" ");
21
+ console.log("Please wait while we create your new extension\n".yellow);
22
+ console.log(" ");
23
+ console.log("------------****-----------\n");
24
+
25
+ const ExtensionsPath = `${CURRENT_PATH}/extensions/${ExtensionName}`;
26
+ await rimraf.sync(
27
+ `${TOOLKIT_PATH}/node_modules/@appdirect/public-custom-app-ui/node_modules`
28
+ );
29
+ await copy(
30
+ `${TOOLKIT_PATH}/node_modules/@appdirect/public-custom-app-ui`,
31
+ `${ExtensionsPath}`
32
+ );
33
+
34
+ const updateWebpackConfig = () => ({
35
+ files: `${ExtensionsPath}/webpack.config.js`,
36
+ from: `microuits`,
37
+ to: `extension_${ExtensionName}`,
38
+ });
39
+
40
+ const updatePackagejson = () => ({
41
+ files: `${ExtensionsPath}/package.json`,
42
+ from: `@appdirect/public-custom-app-ui`,
43
+ to: `extension_${ExtensionName}`,
44
+ });
45
+
46
+ const updatePackageLockjson = () => ({
47
+ files: `${ExtensionsPath}/npm-shrinkwrap.json`,
48
+ from: `@appdirect/public-custom-app-ui`,
49
+ to: `extension_${ExtensionName}`,
50
+ });
51
+
52
+ const updateConfig = () => ({
53
+ files: `${ExtensionsPath}/static/app-dev-config.json`,
54
+ from: `microuits`,
55
+ to: `extension_${ExtensionName}`,
56
+ });
57
+
58
+ const updateWebpackConfig2 = () => ({
59
+ files: `${ExtensionsPath}/webpack.config.js`,
60
+ from: `const APPPATH = 'desiredPath';`,
61
+ to: `const APPPATH = '${AppPath}';`,
62
+ });
63
+
64
+ const updateWebpackConfig3 = () => ({
65
+ files: `${ExtensionsPath}/webpack.config.js`,
66
+ from: `const developmentMarketplaceDomain = "https://engage19billing.test.devappdirect.me";`,
67
+ to: `const developmentMarketplaceDomain = "${MarketplacePath}";`,
68
+ });
69
+
70
+ await replace(updateWebpackConfig());
71
+ await replace(updateWebpackConfig2());
72
+ await replace(updateWebpackConfig3());
73
+ await replace(updatePackagejson());
74
+ await replace(updatePackageLockjson());
75
+ await replace(updateConfig());
76
+
77
+ console.log("------------****-----------\n");
78
+ console.log(" ");
79
+ console.log("Your new extension is ready to go!\n".green);
80
+ console.log(
81
+ `You can find your new extension in extensions/${ExtensionName}\n`.green
82
+ );
83
+ console.log(
84
+ `To get started, go into that folder, run the command "npm install && npm start", You can also have a look at our document at https://developer.appdirect.com. \n`
85
+ .green
86
+ );
87
+ console.log(" ");
88
+ console.log("------------****-----------\n");
89
+ } catch (err) {
90
+ console.error(` ERROR: Unable to copy extensions files due to: ${err}`.red);
91
+ process.exit(1);
92
+ }
93
+ })();