@scandipwa/magento-scripts 1.14.1-alpha.2 → 1.14.1-alpha.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 (46) hide show
  1. package/index.js +13 -0
  2. package/lib/tasks/file-system/create-php-storm-config.js +82 -0
  3. package/lib/tasks/file-system/index.js +1 -1
  4. package/lib/tasks/requirements/docker/index.js +2 -0
  5. package/lib/tasks/requirements/docker/install.js +11 -11
  6. package/lib/tasks/requirements/docker/running-status.js +137 -0
  7. package/lib/tasks/requirements/docker/version.js +2 -0
  8. package/lib/tasks/start.js +2 -6
  9. package/lib/util/instance-metadata.js +1 -7
  10. package/lib/util/is-running-root.js +3 -0
  11. package/lib/util/systemctl.js +46 -0
  12. package/package.json +2 -3
  13. package/typings/context.d.ts +0 -2
  14. package/lib/config/xml-parser.js +0 -61
  15. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +0 -248
  16. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +0 -85
  17. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +0 -154
  18. package/lib/tasks/file-system/create-phpstorm-config/index.js +0 -27
  19. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +0 -29
  20. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +0 -54
  21. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +0 -31
  22. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +0 -42
  23. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +0 -37
  24. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +0 -80
  25. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +0 -29
  26. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +0 -145
  27. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +0 -20
  28. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +0 -60
  29. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +0 -119
  30. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +0 -37
  31. package/lib/tasks/file-system/create-phpstorm-config/keys.js +0 -14
  32. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +0 -67
  33. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +0 -57
  34. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +0 -76
  35. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +0 -63
  36. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +0 -69
  37. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +0 -77
  38. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +0 -98
  39. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +0 -57
  40. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +0 -66
  41. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +0 -64
  42. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +0 -60
  43. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +0 -51
  44. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +0 -74
  45. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +0 -5
  46. package/typings/phpstorm.d.ts +0 -33
package/index.js CHANGED
@@ -5,6 +5,19 @@ const getLatestVersion = require('@scandipwa/scandipwa-dev-utils/latest-version'
5
5
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
6
6
  const semver = require('semver');
7
7
  const isInstalledGlobally = require('is-installed-globally');
8
+ const isRunningRoot = require('./lib/util/is-running-root');
9
+
10
+ if (isRunningRoot()) {
11
+ logger.error('Root privileges detected!');
12
+ console.log(`
13
+ We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
14
+ We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
15
+
16
+ If you are experiencing problems with ${ logger.style.misc('Docker') }, ${ logger.style.misc('PHPBrew') } and ${ logger.style.misc('PHP') } compilation or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
17
+ `);
18
+
19
+ process.exit(1);
20
+ }
8
21
 
9
22
  const commands = [
10
23
  require('./lib/commands/link'),
@@ -0,0 +1,82 @@
1
+ const setConfigFile = require('../../util/set-config');
2
+ const pathExists = require('../../util/path-exists');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ const createPhpStormConfig = () => ({
7
+ title: 'Setting PHPStorm config',
8
+ task: async ({ config: { phpStorm }, ports }) => {
9
+ const { phpLanguageLevel } = phpStorm.php;
10
+ const jdbcUrl = `jdbc:mysql://localhost:${ports.mysql}/magento`;
11
+
12
+ try {
13
+ await setConfigFile({
14
+ configPathname: phpStorm.xdebug.path,
15
+ template: phpStorm.xdebug.templatePath,
16
+ overwrite: true,
17
+ templateArgs: {
18
+ phpStorm
19
+ }
20
+ });
21
+ } catch (e) {
22
+ throw new Error(`Unexpected error accrued during workspace.xml config creation\n\n${e}`);
23
+ }
24
+
25
+ try {
26
+ await setConfigFile({
27
+ configPathname: phpStorm.php.path,
28
+ template: phpStorm.php.templatePath,
29
+ overwrite: true,
30
+ templateArgs: {
31
+ phpLanguageLevel
32
+ }
33
+ });
34
+ } catch (e) {
35
+ throw new Error(`Unexpected error accrued during php.xml config creation\n\n${e}`);
36
+ }
37
+
38
+ try {
39
+ await setConfigFile({
40
+ configPathname: phpStorm.database.dataSourcesLocal.path,
41
+ template: phpStorm.database.dataSourcesLocal.templatePath,
42
+ overwrite: true,
43
+ templateArgs: {
44
+ phpStorm
45
+ }
46
+ });
47
+ } catch (e) {
48
+ throw new Error(`Unexpected error accrued during dataSources.local.xml config creation\n\n${e}`);
49
+ }
50
+
51
+ try {
52
+ await setConfigFile({
53
+ configPathname: phpStorm.database.dataSources.path,
54
+ template: phpStorm.database.dataSources.templatePath,
55
+ overwrite: true,
56
+ templateArgs: {
57
+ phpStorm,
58
+ jdbcUrl
59
+ }
60
+ });
61
+ } catch (e) {
62
+ throw new Error(`Unexpected error accrued during dataSources.xml config creation\n\n${e}`);
63
+ }
64
+
65
+ if (!await pathExists(path.resolve('./.idea/dataSources'))) {
66
+ await fs.promises.mkdir(path.resolve('./.idea/dataSources'));
67
+ }
68
+
69
+ try {
70
+ await setConfigFile({
71
+ configPathname: phpStorm.inspectionTools.path,
72
+ template: phpStorm.inspectionTools.templatePath,
73
+ overwrite: true,
74
+ templateArgs: {}
75
+ });
76
+ } catch (e) {
77
+ throw new Error(`Unexpected error accrued during Project_Default.xml config creation\n\n${e}`);
78
+ }
79
+ }
80
+ });
81
+
82
+ module.exports = createPhpStormConfig;
@@ -1,7 +1,7 @@
1
1
  const createNginxConfig = require('./create-nginx-config');
2
2
  const createPhpConfig = require('./create-php-config');
3
3
  const createPhpFpmConfig = require('./create-php-fpm-config');
4
- const createPhpStormConfig = require('./create-phpstorm-config');
4
+ const createPhpStormConfig = require('./create-php-storm-config');
5
5
  const createVSCodeConfig = require('./create-vscode-config');
6
6
 
7
7
  /**
@@ -4,6 +4,7 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
4
  const getIsWsl = require('../../../util/is-wsl');
5
5
  const installDocker = require('./install');
6
6
  const { checkDockerSocketPermissions } = require('./permissions');
7
+ const checkDockerStatus = require('./running-status');
7
8
  const getDockerVersion = require('./version');
8
9
 
9
10
  /**
@@ -61,6 +62,7 @@ ${ logger.style.link('https://docs.create-magento-app.com/getting-started/prereq
61
62
  }
62
63
 
63
64
  return task.newListr([
65
+ checkDockerStatus(),
64
66
  getDockerVersion(),
65
67
  {
66
68
  task: (ctx) => {
@@ -3,13 +3,16 @@ const { execCommandTask } = require('../../../util/exec-async-command');
3
3
  const installDependenciesTask = require('../../../util/install-dependencies-task');
4
4
  const executeSudoCommand = require('../../../util/execute-sudo-command');
5
5
 
6
+ const downloadDockerInstallScriptCommand = () => execCommandTask('curl -fsSL https://get.docker.com -o get-docker.sh');
7
+ const runDockerInstallScriptCommand = () => executeSudoCommand('sudo sh get-docker.sh');
8
+ const enableAndStartDockerCommand = () => executeSudoCommand('sudo systemctl enable docker --now');
9
+
6
10
  const postInstallSteps = [
7
11
  executeSudoCommand('[ $(getent group docker) ] && sudo groupadd docker', {
8
12
  withCode: true
9
13
  }),
10
14
  executeSudoCommand(`sudo usermod -aG docker ${process.env.USER}`)
11
15
  ];
12
-
13
16
  /**
14
17
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
15
18
  */
@@ -24,26 +27,23 @@ const installDocker = () => ({
24
27
  platform: 'Arch Linux',
25
28
  dependenciesToInstall: ['docker']
26
29
  }),
27
- executeSudoCommand('sudo systemctl start docker.service'),
28
- executeSudoCommand('sudo systemctl enable docker.service'),
30
+ enableAndStartDockerCommand(),
29
31
  ...postInstallSteps
30
32
  ]);
31
33
  }
32
34
  case 'Fedora':
33
35
  case 'CentOS': {
34
36
  return task.newListr([
35
- execCommandTask('curl -fsSL https://get.docker.com -o get-docker.sh'),
36
- executeSudoCommand('sudo sh get-docker.sh'),
37
- executeSudoCommand('sudo systemctl start docker'),
38
- executeSudoCommand('sudo systemctl enable docker')
37
+ downloadDockerInstallScriptCommand(),
38
+ runDockerInstallScriptCommand(),
39
+ enableAndStartDockerCommand()
39
40
  ]);
40
41
  }
41
42
  case 'Ubuntu': {
42
43
  return task.newListr([
43
- execCommandTask('curl -fsSL https://get.docker.com -o get-docker.sh'),
44
- executeSudoCommand('sudo sh get-docker.sh'),
45
- executeSudoCommand('sudo service docker start'),
46
- executeSudoCommand('sudo systemctl enable docker.service'),
44
+ downloadDockerInstallScriptCommand(),
45
+ runDockerInstallScriptCommand(),
46
+ enableAndStartDockerCommand(),
47
47
  ...postInstallSteps
48
48
  ]);
49
49
  }
@@ -0,0 +1,137 @@
1
+ const os = require('os');
2
+ const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
+ const getIsWsl = require('../../../util/is-wsl');
4
+ const pathExists = require('../../../util/path-exists');
5
+ const sleep = require('../../../util/sleep');
6
+ const { systemctlControl } = require('../../../util/systemctl');
7
+
8
+ const pathToDockerApplication = '/Applications/Docker.app';
9
+
10
+ const getDockerVersion = () => execAsyncSpawn('docker version --format {{.Server.Version}}', {
11
+ withCode: true
12
+ });
13
+
14
+ /**
15
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
16
+ */
17
+ const checkDockerStatusMacOS = () => ({
18
+ title: 'Checking Docker status on MacOS',
19
+ task: async (ctx, task) => {
20
+ const { result, code } = await getDockerVersion();
21
+
22
+ if (code !== 0 && result.includes('Is the docker daemon running?')) {
23
+ const dockerOpenAppConfirmation = await task.prompt({
24
+ type: 'Confirm',
25
+ message: 'Looks like Docker is not running, would you like us to open a Docker for Mac application and wait for it to start up?'
26
+ });
27
+
28
+ if (dockerOpenAppConfirmation && await pathExists(pathToDockerApplication)) {
29
+ await execAsyncSpawn(`open ${pathToDockerApplication}`);
30
+ let ready = false;
31
+ let attempts = 0;
32
+ while (!ready) {
33
+ if (attempts > 24 && !ready) {
34
+ throw new Error('Docker haven\'t started in 2 mins, exiting...');
35
+ }
36
+ try {
37
+ const { code: startupCode } = await getDockerVersion();
38
+ if (startupCode !== 0) {
39
+ task.output = `Waiting for Docker to startup for ${attempts * 5} seconds...`;
40
+ attempts++;
41
+ await sleep(5000);
42
+ } else {
43
+ ready = true;
44
+ }
45
+ } catch (e) {
46
+ //
47
+ }
48
+ }
49
+
50
+ return;
51
+ }
52
+
53
+ task.skip('User skipped running Docker');
54
+ }
55
+ },
56
+ options: {
57
+ bottomBar: 10
58
+ }
59
+ });
60
+
61
+ /**
62
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
63
+ */
64
+ const checkDockerStatusWSL = () => ({
65
+ title: 'Checking Docker status on Windows WSL',
66
+ task: async () => {
67
+ const { result, code } = await getDockerVersion();
68
+
69
+ if (code !== 0 && result.includes('Is the docker daemon running?')) {
70
+ throw new Error(`Docker is not running!
71
+
72
+ Please open Docker Desktop application for Windows and make sure that Docker is running. Then you can try again!`);
73
+ }
74
+ }
75
+ });
76
+
77
+ /**
78
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
79
+ */
80
+ const checkDockerStatusLinux = () => ({
81
+ title: 'Checking Docker status on Linux',
82
+ task: async (ctx, task) => {
83
+ const dockerService = systemctlControl('docker');
84
+
85
+ const isRunning = await dockerService.isRunning();
86
+ const isEnabled = await dockerService.isEnabled();
87
+
88
+ if (!isEnabled && !isRunning) {
89
+ const dockerStartConfirmation = await task.prompt({
90
+ type: 'Confirm',
91
+ message: `Looks like Docker is not enabled and not running, would you like to enable and run it?
92
+
93
+ This action requires root privileges.`
94
+ });
95
+
96
+ if (dockerStartConfirmation) {
97
+ await dockerService.enableAndStart();
98
+
99
+ return;
100
+ }
101
+ task.skip('User skipped running Docker');
102
+ } else if (!isRunning) {
103
+ const dockerStartConfirmation = await task.prompt({
104
+ type: 'Confirm',
105
+ message: `Looks like Docker is not running, would you like to run it?
106
+
107
+ This action requires root privileges.`
108
+ });
109
+
110
+ if (dockerStartConfirmation) {
111
+ await dockerService.start();
112
+
113
+ return;
114
+ }
115
+ task.skip('User skipped running Docker');
116
+ }
117
+ }
118
+ });
119
+
120
+ /**
121
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
122
+ */
123
+ const checkDockerStatus = () => ({
124
+ title: 'Checking Docker status',
125
+ task: async (ctx, task) => {
126
+ if (os.platform() === 'darwin') {
127
+ return task.newListr(checkDockerStatusMacOS());
128
+ }
129
+ if (!await getIsWsl()) {
130
+ return task.newListr(checkDockerStatusLinux());
131
+ }
132
+
133
+ return task.newListr(checkDockerStatusWSL());
134
+ }
135
+ });
136
+
137
+ module.exports = checkDockerStatus;
@@ -13,6 +13,8 @@ const getDockerVersion = () => ({
13
13
  const dockerVersion = result.split('').filter((c) => /[\d.]/i.test(c)).join('') || result;
14
14
 
15
15
  ctx.dockerVersion = dockerVersion;
16
+ } else {
17
+ throw new Error(`Got unexpected result during Docker version retrieval!\n\n${ result }`);
16
18
  }
17
19
  }
18
20
  });
@@ -29,7 +29,6 @@ const convertLegacyVolumes = require('./docker/convert-legacy-volumes');
29
29
  const enableMagentoComposerPlugins = require('./magento/enable-magento-composer-plugins');
30
30
  const getIsWsl = require('../util/is-wsl');
31
31
  const checkForXDGOpen = require('../util/xdg-open-exists');
32
- const { getInstanceMetadata, constants: { WEB_LOCATION_TITLE } } = require('../util/instance-metadata');
33
32
 
34
33
  /**
35
34
  * @type {() => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
@@ -190,11 +189,8 @@ const start = () => ({
190
189
 
191
190
  return false;
192
191
  },
193
- task: (ctx) => {
194
- const instanceMetadata = getInstanceMetadata(ctx);
195
- const locationOnTheWeb = instanceMetadata.frontend.find(({ title }) => title === WEB_LOCATION_TITLE);
196
-
197
- openBrowser(locationOnTheWeb.text);
192
+ task: ({ ports, config: { overridenConfiguration: { host, ssl } } }) => {
193
+ openBrowser(`${ssl.enabled ? 'https' : 'http'}://${host}${ssl.enabled || ports.app === 80 ? '' : `:${ports.app}`}/`);
198
194
  },
199
195
  options: {
200
196
  showTimer: false
@@ -70,11 +70,5 @@ const getInstanceMetadata = (ctx) => {
70
70
  };
71
71
 
72
72
  module.exports = {
73
- getInstanceMetadata,
74
- constants: {
75
- WEB_LOCAL_LOCATION_TITLE,
76
- WEB_LOCATION_TITLE,
77
- WEB_ADMIN_LOCATION_TITLE,
78
- WEB_ADMIN_CREDENTIALS_TITLE
79
- }
73
+ getInstanceMetadata
80
74
  };
@@ -0,0 +1,3 @@
1
+ const isRunningRoot = () => process.getuid() === 0; // UID 0 is always root
2
+
3
+ module.exports = isRunningRoot;
@@ -0,0 +1,46 @@
1
+ const { execAsyncSpawn } = require('./exec-async-command');
2
+
3
+ /**
4
+ * @param {String} cmd
5
+ * @param {String} serviceName
6
+ * @param {{ now: boolean }} options
7
+ */
8
+ const run = (cmd, serviceName, options = {}) => execAsyncSpawn(
9
+ `systemctl ${ cmd }${ serviceName ? ` ${ serviceName }` : '' }${ options.now ? ' --now' : ''}`,
10
+ {
11
+ withCode: true
12
+ }
13
+ );
14
+
15
+ const daemonReload = () => run('daemon-reload');
16
+
17
+ const systemctlControl = (serviceName) => ({
18
+ disable: () => run('disable', serviceName),
19
+ enable: () => run('enable', serviceName),
20
+ enableAndStart: () => run('enable', serviceName, { now: true }),
21
+ restart: () => run('restart', serviceName),
22
+ start: () => run('start', serviceName),
23
+ stop: () => run('stop', serviceName),
24
+ isEnabled: async () => {
25
+ try {
26
+ const { result } = await run('is-enabled', serviceName);
27
+ return result.includes('enabled');
28
+ } catch (e) {
29
+ return false;
30
+ }
31
+ },
32
+ isRunning: async () => {
33
+ try {
34
+ const { result } = await run('status', serviceName);
35
+
36
+ return result.includes('active (running)');
37
+ } catch (e) {
38
+ return false;
39
+ }
40
+ }
41
+ });
42
+
43
+ module.exports = {
44
+ systemctlControl,
45
+ daemonReload
46
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "1.14.1-alpha.2",
6
+ "version": "1.14.1-alpha.3",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -26,7 +26,6 @@
26
26
  "conf": "10.1.1",
27
27
  "enquirer": "2.3.6",
28
28
  "eta": "1.12.3",
29
- "fast-xml-parser": "^4.0.7",
30
29
  "hjson": "^3.2.2",
31
30
  "is-installed-globally": "0.4.0",
32
31
  "joi": "17.6.0",
@@ -52,5 +51,5 @@
52
51
  "mysql",
53
52
  "scandipwa"
54
53
  ],
55
- "gitHead": "8f43ab3d68af6442bbd618efd785654ac62e54b8"
54
+ "gitHead": "262eae9eb5d71053f48d177426320182c5b5a9eb"
56
55
  }
@@ -1,7 +1,6 @@
1
1
  import mysql2 from 'mysql2';
2
2
 
3
3
  import { CMAConfiguration, PHPExtensions } from './index';
4
- import { PHPStormConfig } from './phpstorm';
5
4
 
6
5
  export interface ListrContext {
7
6
  magentoVersion: string
@@ -83,7 +82,6 @@ export interface ListrContext {
83
82
  overridenConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
84
83
  userConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
85
84
  nonOverridenConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
86
- phpStorm: PHPStormConfig
87
85
  }
88
86
  systemConfiguration: {
89
87
  analytics: boolean
@@ -1,61 +0,0 @@
1
- const { XMLParser, XMLBuilder } = require('fast-xml-parser');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const pathExists = require('../util/path-exists');
5
-
6
- /**
7
- * @type {import('fast-xml-parser').X2jOptions}
8
- */
9
- const xmlParserConfig = {
10
- ignoreAttributes: false,
11
- parseAttributeValue: false,
12
- trimValues: true,
13
- allowBooleanAttributes: true
14
- };
15
-
16
- /**
17
- * @type {Partial<import('fast-xml-parser').XmlBuilderOptions>}
18
- */
19
- const xmlBuilderConfig = {
20
- ...xmlParserConfig,
21
- format: true,
22
- suppressEmptyNode: true,
23
- suppressBooleanAttributes: false
24
- };
25
-
26
- const parser = new XMLParser(xmlParserConfig);
27
- const builder = new XMLBuilder(xmlBuilderConfig);
28
-
29
- /**
30
- * Load xml file to js object
31
- * @param {String} filePath
32
- */
33
- const loadXmlFile = async (filePath) => {
34
- const fileData = await fs.promises.readFile(filePath, 'utf-8');
35
-
36
- return parser.parse(fileData);
37
- };
38
-
39
- /**
40
- * Build xml from js object and write it to file
41
- * @param {String} filePath
42
- * @param {String} fileData
43
- */
44
- const buildXmlFile = async (filePath, fileData) => {
45
- const xmlFileData = builder.build(fileData);
46
-
47
- const { dir } = path.parse(filePath);
48
-
49
- if (!await pathExists(dir)) {
50
- await fs.promises.mkdir(dir, {
51
- recursive: true
52
- });
53
- }
54
-
55
- await fs.promises.writeFile(filePath, xmlFileData, 'utf-8');
56
- };
57
-
58
- module.exports = {
59
- loadXmlFile,
60
- buildXmlFile
61
- };