@scandipwa/magento-scripts 2.0.3 → 2.0.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.
- package/.eslintrc +6 -1
- package/exec.js +75 -39
- package/index.js +87 -46
- package/lib/commands/cleanup.js +18 -21
- package/lib/commands/cli.js +138 -73
- package/lib/commands/execute.js +5 -5
- package/lib/commands/import-db.js +21 -24
- package/lib/commands/link.js +17 -20
- package/lib/commands/logs.js +91 -91
- package/lib/commands/start.js +229 -191
- package/lib/commands/status.js +64 -50
- package/lib/commands/stop.js +14 -11
- package/lib/config/check-configuration-file.js +33 -28
- package/lib/config/cma-config.js +4 -4
- package/lib/config/config.js +40 -18
- package/lib/config/dependencies-for-platforms.js +33 -3
- package/lib/config/docker.js +259 -157
- package/lib/config/get-magento-version-config.js +45 -38
- package/lib/config/get-port-config.js +30 -44
- package/lib/config/get-project-configuration.js +8 -8
- package/lib/config/index.js +51 -42
- package/lib/config/magento/required-php-extensions/index.js +33 -19
- package/lib/config/magento/required-php-extensions/magento-2.3.js +2 -2
- package/lib/config/magento/required-php-extensions/magento-2.4.js +2 -2
- package/lib/config/magento-config.js +4 -4
- package/lib/config/php-config.js +8 -6
- package/lib/config/port-config.js +62 -43
- package/lib/config/save-config.js +6 -6
- package/lib/config/scandipwa-versions.js +2 -2
- package/lib/config/services/composer/versions/composer-1.js +2 -2
- package/lib/config/services/composer/versions/composer-2.js +2 -2
- package/lib/config/services/composer/versions/index.js +1 -1
- package/lib/config/services/elasticsearch/base-repo.js +1 -1
- package/lib/config/services/elasticsearch/default-es-env.js +4 -1
- package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +17 -14
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.10.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.12.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.16.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.17.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.6.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.7.js +4 -4
- package/lib/config/services/elasticsearch/versions/elasticsearch-7.9.js +4 -4
- package/lib/config/services/elasticsearch/versions/index.js +9 -9
- package/lib/config/services/maildev/index.js +5 -2
- package/lib/config/services/mariadb/versions/index.js +1 -1
- package/lib/config/services/mariadb/versions/mariadb-10.2.js +3 -3
- package/lib/config/services/mariadb/versions/mariadb-10.3.js +3 -3
- package/lib/config/services/mariadb/versions/mariadb-10.4.js +3 -3
- package/lib/config/services/nginx/versions/index.js +1 -1
- package/lib/config/services/nginx/versions/nginx-1.18.js +5 -4
- package/lib/config/services/php/base-repo.js +1 -1
- package/lib/config/services/php/extensions/apcu.js +3 -3
- package/lib/config/services/php/extensions/bcmath.js +2 -2
- package/lib/config/services/php/extensions/curl.js +3 -6
- package/lib/config/services/php/extensions/gd.js +4 -3
- package/lib/config/services/php/extensions/index.js +9 -8
- package/lib/config/services/php/extensions/intl.js +3 -5
- package/lib/config/services/php/extensions/opcache.js +3 -5
- package/lib/config/services/php/extensions/pdo_mysql.js +2 -2
- package/lib/config/services/php/extensions/soap.js +3 -5
- package/lib/config/services/php/extensions/sodium.js +3 -5
- package/lib/config/services/php/extensions/xdebug.js +5 -3
- package/lib/config/services/php/extensions/xsl.js +3 -5
- package/lib/config/services/php/extensions/zip.js +3 -5
- package/lib/config/services/php/versions/index.js +1 -1
- package/lib/config/services/php/versions/php-7.2.js +13 -9
- package/lib/config/services/php/versions/php-7.3.js +13 -9
- package/lib/config/services/php/versions/php-7.4.js +13 -9
- package/lib/config/services/php/versions/php-8.1.js +13 -9
- package/lib/config/services/redis/index.js +1 -1
- package/lib/config/services/redis/redis-5.0.js +2 -2
- package/lib/config/services/redis/redis-6.0.js +2 -2
- package/lib/config/services/redis/redis-6.2.js +2 -2
- package/lib/config/services/ssl-terminator/index.js +6 -5
- package/lib/config/services/varnish/index.js +1 -1
- package/lib/config/services/varnish/varnish-6-0.js +7 -5
- package/lib/config/services/varnish/varnish-6-6.js +7 -5
- package/lib/config/services/varnish/varnish-7-0.js +7 -5
- package/lib/config/system-config.js +55 -32
- package/lib/config/templates/mariadb.template.cnf +2 -0
- package/lib/config/versions/index.js +48 -27
- package/lib/config/versions/magento-2.2.10.js +22 -15
- package/lib/config/versions/magento-2.3.0.js +22 -15
- package/lib/config/versions/magento-2.3.1.js +22 -15
- package/lib/config/versions/magento-2.3.2-p1.js +22 -15
- package/lib/config/versions/magento-2.3.2-p2.js +22 -15
- package/lib/config/versions/magento-2.3.2.js +22 -15
- package/lib/config/versions/magento-2.3.3-p1.js +22 -15
- package/lib/config/versions/magento-2.3.3.js +22 -15
- package/lib/config/versions/magento-2.3.4-p1.js +22 -15
- package/lib/config/versions/magento-2.3.4-p2.js +22 -15
- package/lib/config/versions/magento-2.3.4.js +22 -15
- package/lib/config/versions/magento-2.3.5-p1.js +22 -15
- package/lib/config/versions/magento-2.3.5-p2.js +22 -15
- package/lib/config/versions/magento-2.3.5.js +27 -15
- package/lib/config/versions/magento-2.3.6-p1.js +22 -15
- package/lib/config/versions/magento-2.3.6.js +22 -15
- package/lib/config/versions/magento-2.3.7-p1.js +22 -15
- package/lib/config/versions/magento-2.3.7-p2.js +22 -15
- package/lib/config/versions/magento-2.3.7-p3.js +22 -15
- package/lib/config/versions/magento-2.3.7-p4.js +22 -15
- package/lib/config/versions/magento-2.3.7.js +22 -15
- package/lib/config/versions/magento-2.4.0-p1.js +22 -15
- package/lib/config/versions/magento-2.4.0.js +22 -15
- package/lib/config/versions/magento-2.4.1-p1.js +23 -16
- package/lib/config/versions/magento-2.4.1.js +23 -16
- package/lib/config/versions/magento-2.4.2-p1.js +23 -16
- package/lib/config/versions/magento-2.4.2-p2.js +23 -16
- package/lib/config/versions/magento-2.4.2.js +23 -16
- package/lib/config/versions/magento-2.4.3-p1.js +23 -16
- package/lib/config/versions/magento-2.4.3-p2.js +23 -16
- package/lib/config/versions/magento-2.4.3-p3.js +23 -16
- package/lib/config/versions/magento-2.4.3.js +23 -16
- package/lib/config/versions/magento-2.4.4-p1.js +23 -16
- package/lib/config/versions/magento-2.4.4-p2.js +23 -16
- package/lib/config/versions/magento-2.4.4.js +23 -16
- package/lib/config/versions/magento-2.4.5-p1.js +23 -16
- package/lib/config/versions/magento-2.4.5.js +23 -17
- package/lib/config/xml-parser.js +21 -20
- package/lib/errors/known-error.js +8 -6
- package/lib/errors/unknown-error.js +8 -6
- package/lib/tasks/cache/create-cache-folder.js +10 -10
- package/lib/tasks/cache/index.js +1 -1
- package/lib/tasks/cache/remove-cache-folder.js +9 -9
- package/lib/tasks/cleanup.js +22 -24
- package/lib/tasks/cli/create-bashrc-config.js +19 -11
- package/lib/tasks/cli/index.js +10 -13
- package/lib/tasks/composer/index.js +20 -15
- package/lib/tasks/composer/local-auth-json.js +32 -18
- package/lib/tasks/database/connect-to-database.js +71 -51
- package/lib/tasks/database/create-magento-database.js +7 -7
- package/lib/tasks/database/create-magento-user.js +33 -20
- package/lib/tasks/database/default-magento-database.js +1 -1
- package/lib/tasks/database/default-magento-user.js +2 -2
- package/lib/tasks/database/dump-theme-config.js +16 -12
- package/lib/tasks/database/fix-db.js +62 -52
- package/lib/tasks/database/import-dump-to-database.js +122 -85
- package/lib/tasks/database/import-remote-db/index.js +16 -18
- package/lib/tasks/database/import-remote-db/ssh/database-dump-command.js +2 -2
- package/lib/tasks/database/import-remote-db/ssh/index.js +34 -35
- package/lib/tasks/database/import-remote-db/ssh/readymage.js +41 -38
- package/lib/tasks/database/import-remote-db/ssh/regular-server.js +44 -46
- package/lib/tasks/database/index.js +1 -1
- package/lib/tasks/database/magento-tables.js +3 -3
- package/lib/tasks/database/restore-theme-config.js +26 -19
- package/lib/tasks/docker/api.d.ts +1 -1
- package/lib/tasks/docker/api.js +31 -33
- package/lib/tasks/docker/containers/container-api.d.ts +49 -14
- package/lib/tasks/docker/containers/container-api.js +112 -83
- package/lib/tasks/docker/containers/index.js +3 -3
- package/lib/tasks/docker/containers/tasks.js +171 -99
- package/lib/tasks/docker/convert-composer-home-to-composer-cache-volume.js +34 -25
- package/lib/tasks/docker/convert-legacy-volumes.js +91 -55
- package/lib/tasks/docker/convert-mysql-to-mariadb.js +178 -147
- package/lib/tasks/docker/image/image-api.d.ts +2 -3
- package/lib/tasks/docker/image/image-api.js +41 -34
- package/lib/tasks/docker/image/index.js +2 -2
- package/lib/tasks/docker/index.js +26 -21
- package/lib/tasks/docker/network/index.js +3 -3
- package/lib/tasks/docker/network/network-api.d.ts +11 -8
- package/lib/tasks/docker/network/network-api.js +53 -61
- package/lib/tasks/docker/network/tasks.js +41 -31
- package/lib/tasks/docker/project-image-builder.js +175 -92
- package/lib/tasks/docker/system/index.js +2 -2
- package/lib/tasks/docker/system/system-api.d.ts +2 -2
- package/lib/tasks/docker/system/system-api.js +16 -19
- package/lib/tasks/docker/volume/index.js +3 -3
- package/lib/tasks/docker/volume/tasks.js +63 -46
- package/lib/tasks/docker/volume/volume-api.d.ts +8 -5
- package/lib/tasks/docker/volume/volume-api.js +59 -76
- package/lib/tasks/execute.js +91 -55
- package/lib/tasks/file-system/create-mariadb-config.js +18 -10
- package/lib/tasks/file-system/create-nginx-config.js +18 -19
- package/lib/tasks/file-system/create-php-config.js +12 -8
- package/lib/tasks/file-system/create-php-debug-config.js +23 -18
- package/lib/tasks/file-system/create-php-fpm-config.js +14 -9
- package/lib/tasks/file-system/create-phpstorm-config/database-config.js +144 -112
- package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +69 -45
- package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +69 -70
- package/lib/tasks/file-system/create-phpstorm-config/index.js +28 -24
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +9 -9
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +23 -23
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +22 -19
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +26 -16
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +14 -15
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +43 -34
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/inspection-tools-config.js +14 -6
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +9 -9
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +53 -47
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +41 -12
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +33 -30
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +35 -38
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +14 -15
- package/lib/tasks/file-system/create-phpstorm-config/keys.js +10 -10
- package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +33 -25
- package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +28 -25
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +53 -32
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +7 -7
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +37 -27
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +53 -31
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +42 -30
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +33 -20
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +3 -3
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +27 -16
- package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +14 -13
- package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +52 -34
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +41 -33
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +39 -27
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +34 -30
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +32 -22
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +32 -22
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +32 -22
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +42 -31
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +45 -33
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +32 -22
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +22 -19
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +35 -21
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +31 -22
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +38 -28
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +5 -5
- package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +3 -2
- package/lib/tasks/file-system/create-ssl-terminator-config.js +46 -34
- package/lib/tasks/file-system/create-varnish-config.js +20 -23
- package/lib/tasks/file-system/create-vscode-config.js +66 -49
- package/lib/tasks/file-system/index.js +29 -25
- package/lib/tasks/import-dump.js +54 -45
- package/lib/tasks/link.js +24 -23
- package/lib/tasks/magento/enable-magento-composer-plugins.js +213 -149
- package/lib/tasks/magento/index.js +1 -1
- package/lib/tasks/magento/install-magento-project.js +158 -97
- package/lib/tasks/magento/remove-magento.js +30 -24
- package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +27 -15
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +23 -10
- package/lib/tasks/magento/setup-magento/create-admin.js +21 -13
- package/lib/tasks/magento/setup-magento/delete-admin-users.js +5 -5
- package/lib/tasks/magento/setup-magento/delete-customers.js +16 -10
- package/lib/tasks/magento/setup-magento/delete-orders.js +16 -10
- package/lib/tasks/magento/setup-magento/disable-2fa.js +11 -8
- package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +7 -7
- package/lib/tasks/magento/setup-magento/disable-page-builder.js +5 -4
- package/lib/tasks/magento/setup-magento/flush-redis-config.js +14 -8
- package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +21 -17
- package/lib/tasks/magento/setup-magento/index-products.js +4 -6
- package/lib/tasks/magento/setup-magento/index.js +54 -47
- package/lib/tasks/magento/setup-magento/install-magento.js +112 -79
- package/lib/tasks/magento/setup-magento/migrate-database.js +115 -96
- package/lib/tasks/magento/setup-magento/set-base-url.js +35 -21
- package/lib/tasks/magento/setup-magento/set-deployment-mode.js +15 -13
- package/lib/tasks/magento/setup-magento/set-mail-config.js +20 -14
- package/lib/tasks/magento/setup-magento/set-url-rewrite.js +13 -9
- package/lib/tasks/magento/setup-magento/upgrade-magento.js +30 -22
- package/lib/tasks/magento/setup-magento/urn-highlighter.js +11 -11
- package/lib/tasks/magento/setup-magento/varnish-config.js +42 -32
- package/lib/tasks/magento/setup-magento/waiting-for-redis.js +6 -8
- package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +108 -65
- package/lib/tasks/magento/uninstall-magento.js +19 -16
- package/lib/tasks/php/php-container.d.ts +19 -0
- package/lib/tasks/php/php-container.js +50 -46
- package/lib/tasks/php/update-env-php.js +50 -30
- package/lib/tasks/project-config/index.js +12 -8
- package/lib/tasks/requirements/composer-credentials.js +215 -112
- package/lib/tasks/requirements/docker/context.js +49 -37
- package/lib/tasks/requirements/docker/index.js +123 -89
- package/lib/tasks/requirements/docker/install-on-mac.js +21 -14
- package/lib/tasks/requirements/docker/install.js +63 -52
- package/lib/tasks/requirements/docker/performance.js +40 -24
- package/lib/tasks/requirements/docker/permissions.js +27 -17
- package/lib/tasks/requirements/docker/running-status.js +79 -66
- package/lib/tasks/requirements/docker/version.js +14 -11
- package/lib/tasks/requirements/index.js +33 -29
- package/lib/tasks/requirements/node-version.js +8 -8
- package/lib/tasks/requirements/php-version.js +14 -11
- package/lib/tasks/requirements/platform.js +42 -26
- package/lib/tasks/requirements/rosetta.js +15 -12
- package/lib/tasks/start.js +172 -148
- package/lib/tasks/status/index.js +155 -88
- package/lib/tasks/stop.js +22 -18
- package/lib/tasks/theme/build-theme.js +50 -33
- package/lib/tasks/theme/install-theme.js +31 -18
- package/lib/tasks/theme/link-theme.js +27 -21
- package/lib/tasks/theme/retrieve-theme-data.js +24 -18
- package/lib/tasks/theme/setup-themes.js +87 -59
- package/lib/tasks/theme/symlink-theme.js +44 -22
- package/lib/util/CSA-theme.js +23 -21
- package/lib/util/analytics.js +130 -75
- package/lib/util/arch.js +22 -18
- package/lib/util/clean-object.js +15 -10
- package/lib/util/config-file-validator.js +63 -54
- package/lib/util/config-php-json.js +34 -16
- package/lib/util/connection-string.js +41 -27
- package/lib/util/console-block.js +112 -65
- package/lib/util/database.js +56 -33
- package/lib/util/deepmerge.d.ts +1 -1
- package/lib/util/deepmerge.js +19 -28
- package/lib/util/dockerfile-builder/build-instructions.js +159 -143
- package/lib/util/dockerfile-builder/index.js +47 -73
- package/lib/util/dockerfile-builder/types.d.ts +2 -1
- package/lib/util/download-file.js +28 -16
- package/lib/util/env-php-json.js +42 -16
- package/lib/util/exec-async-command.d.ts +9 -9
- package/lib/util/exec-async-command.js +82 -59
- package/lib/util/exec-async.d.ts +2 -0
- package/lib/util/exec-async.js +12 -5
- package/lib/util/execute-in-container.js +22 -27
- package/lib/util/execute-sudo-command.js +11 -15
- package/lib/util/get-brew-bin-path.js +27 -23
- package/lib/util/get-installed-magento-version.js +22 -16
- package/lib/util/get-jsonfile-data.js +14 -9
- package/lib/util/install-dependencies-task.js +53 -41
- package/lib/util/instance-metadata.js +44 -29
- package/lib/util/ip.js +16 -12
- package/lib/util/is-running-root.js +6 -3
- package/lib/util/is-wsl.js +10 -10
- package/lib/util/macos-version.js +12 -11
- package/lib/util/magento-task.js +14 -9
- package/lib/util/match-filesystem.js +22 -16
- package/lib/util/move-file.js +40 -25
- package/lib/util/nginx-logs-parser.js +50 -39
- package/lib/util/open-browser.js +8 -5
- package/lib/util/os-platform.js +40 -32
- package/lib/util/path-exists-sync.js +10 -6
- package/lib/util/path-exists.js +6 -6
- package/lib/util/php-task.js +11 -10
- package/lib/util/portscanner.js +97 -85
- package/lib/util/prefix.js +31 -22
- package/lib/util/resolve-configuration-with-overrides.js +30 -15
- package/lib/util/rmdir-safe.js +15 -11
- package/lib/util/run-composer.js +16 -16
- package/lib/util/run-container-image.js +9 -4
- package/lib/util/run-magento.js +16 -17
- package/lib/util/run-php.js +16 -21
- package/lib/util/safe-regex-extract.js +8 -12
- package/lib/util/set-config.js +24 -15
- package/lib/util/sleep.js +7 -2
- package/lib/util/systemctl.js +62 -44
- package/lib/util/wait-for-it.js +42 -33
- package/lib/util/wait-for-logs.js +42 -35
- package/lib/util/xdg-open-exists.js +19 -19
- package/package.json +7 -3
- package/tsconfig.json +24 -0
- package/typings/context.d.ts +76 -34
- package/typings/index.d.ts +44 -19
- package/typings/override.d.ts +14 -0
- package/typings/phpstorm.d.ts +19 -19
- package/.prettierrc +0 -3
- package/lib/util/get-php-for-phpbrew.js +0 -30
- package/lib/util/request.js +0 -0
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const UnknownError = require('../errors/unknown-error')
|
|
3
|
-
const pathExists = require('./path-exists')
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const UnknownError = require('../errors/unknown-error')
|
|
3
|
+
const pathExists = require('./path-exists')
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @type {<T>(fileData: string) => Promise<T | null>}
|
|
7
|
+
*/
|
|
5
8
|
const getJsonfileData = async (filePath) => {
|
|
6
|
-
const fileExists = await pathExists(filePath)
|
|
9
|
+
const fileExists = await pathExists(filePath)
|
|
7
10
|
|
|
8
11
|
if (!fileExists) {
|
|
9
|
-
return null
|
|
12
|
+
return null
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
try {
|
|
13
|
-
return JSON.parse(await fs.promises.readFile(filePath, 'utf-8'))
|
|
16
|
+
return JSON.parse(await fs.promises.readFile(filePath, 'utf-8'))
|
|
14
17
|
} catch (e) {
|
|
15
|
-
throw new UnknownError(
|
|
18
|
+
throw new UnknownError(
|
|
19
|
+
`Ooops! Something went wrong when trying to json parse ${filePath} file!\n\n${e}`
|
|
20
|
+
)
|
|
16
21
|
}
|
|
17
|
-
}
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
module.exports = getJsonfileData
|
|
24
|
+
module.exports = getJsonfileData
|
|
@@ -1,100 +1,112 @@
|
|
|
1
|
-
const os = require('os')
|
|
2
|
-
const logger = require('@scandipwa/scandipwa-dev-utils/logger')
|
|
3
|
-
const sleep = require('./sleep')
|
|
4
|
-
const { execCommandTask } = require('./exec-async-command')
|
|
5
|
-
const dependenciesForPlatforms = require('../config/dependencies-for-platforms')
|
|
6
|
-
const KnownError = require('../errors/known-error')
|
|
1
|
+
const os = require('os')
|
|
2
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger')
|
|
3
|
+
const sleep = require('./sleep')
|
|
4
|
+
const { execCommandTask } = require('./exec-async-command')
|
|
5
|
+
const dependenciesForPlatforms = require('../config/dependencies-for-platforms')
|
|
6
|
+
const KnownError = require('../errors/known-error')
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Install dependencies
|
|
10
10
|
* @param {object} options
|
|
11
11
|
* @param {keyof dependenciesForPlatforms} options.platform Platform
|
|
12
12
|
* @param {string[]} options.dependenciesToInstall List of dependencies to install
|
|
13
|
-
* @param {boolean} options.useMacNativeEnvironment Use Mac native environment
|
|
13
|
+
* @param {boolean} [options.useMacNativeEnvironment] Use Mac native environment
|
|
14
14
|
* @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
|
|
15
15
|
*/
|
|
16
16
|
const installDependenciesTask = (options) => ({
|
|
17
17
|
task: async (ctx, task) => {
|
|
18
|
-
const { dependenciesToInstall, platform } = options
|
|
19
|
-
task.title = `Installing ${platform} dependencies
|
|
20
|
-
let cmd
|
|
18
|
+
const { dependenciesToInstall, platform } = options
|
|
19
|
+
task.title = `Installing ${platform} dependencies`
|
|
20
|
+
let cmd
|
|
21
21
|
if (os.platform() === 'darwin') {
|
|
22
|
-
cmd = dependenciesForPlatforms[platform].installCommand(
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
cmd = dependenciesForPlatforms[platform].installCommand(
|
|
23
|
+
dependenciesToInstall.join(' '),
|
|
24
|
+
{
|
|
25
|
+
native: options.useMacNativeEnvironment
|
|
26
|
+
}
|
|
27
|
+
)
|
|
25
28
|
} else {
|
|
26
|
-
cmd = dependenciesForPlatforms[platform].installCommand(
|
|
29
|
+
cmd = dependenciesForPlatforms[platform].installCommand(
|
|
30
|
+
dependenciesToInstall.join(' ')
|
|
31
|
+
)
|
|
27
32
|
}
|
|
28
|
-
const installCommand = logger.style.code(cmd)
|
|
29
|
-
const dependenciesWordFormatter = `dependenc${
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
const installCommand = logger.style.code(cmd)
|
|
34
|
+
const dependenciesWordFormatter = `dependenc${
|
|
35
|
+
dependenciesToInstall.length > 1 ? 'ies' : 'y'
|
|
36
|
+
}`
|
|
37
|
+
task.title = `Installing missing dependencies: ${logger.style.code(
|
|
38
|
+
dependenciesToInstall.join(', ')
|
|
39
|
+
)}`
|
|
40
|
+
task.output = `Missing ${dependenciesWordFormatter} ${logger.style.code(
|
|
41
|
+
dependenciesToInstall.join(' ')
|
|
42
|
+
)} detected!`
|
|
32
43
|
|
|
33
|
-
let promptSkipper = false
|
|
44
|
+
let promptSkipper = false
|
|
34
45
|
const timer = async () => {
|
|
35
46
|
for (let i = 5 * 60; i !== 0; i--) {
|
|
36
|
-
await sleep(1000)
|
|
47
|
+
await sleep(1000)
|
|
37
48
|
if (promptSkipper) {
|
|
38
|
-
return null
|
|
49
|
+
return null
|
|
39
50
|
}
|
|
40
|
-
task.title = `Checking ${platform} dependencies (${i} sec left...)
|
|
51
|
+
task.title = `Checking ${platform} dependencies (${i} sec left...)`
|
|
41
52
|
}
|
|
42
|
-
task.cancelPrompt()
|
|
43
|
-
return 'timeout'
|
|
44
|
-
}
|
|
53
|
+
task.cancelPrompt()
|
|
54
|
+
return 'timeout'
|
|
55
|
+
}
|
|
45
56
|
|
|
46
57
|
const installAnswer = await Promise.race([
|
|
47
58
|
task.prompt({
|
|
48
59
|
type: 'Select',
|
|
49
|
-
message: `Do you want to install missing ${
|
|
60
|
+
message: `Do you want to install missing ${dependenciesWordFormatter} now?`,
|
|
50
61
|
name: 'installAnswer',
|
|
51
62
|
choices: [
|
|
52
63
|
{
|
|
53
64
|
name: 'install',
|
|
54
|
-
message: `Install ${
|
|
65
|
+
message: `Install ${dependenciesWordFormatter} now!`
|
|
55
66
|
},
|
|
56
67
|
{
|
|
57
68
|
name: 'not-install',
|
|
58
|
-
message: `Install ${
|
|
69
|
+
message: `Install ${dependenciesWordFormatter} later, when I feel it.`
|
|
59
70
|
}
|
|
60
71
|
]
|
|
61
72
|
}),
|
|
62
73
|
timer()
|
|
63
|
-
])
|
|
74
|
+
])
|
|
64
75
|
|
|
65
|
-
promptSkipper = true
|
|
76
|
+
promptSkipper = true
|
|
66
77
|
|
|
67
78
|
if (installAnswer === 'timeout') {
|
|
68
79
|
throw new KnownError(`Timeout!
|
|
69
80
|
|
|
70
|
-
To install missing ${
|
|
81
|
+
To install missing ${dependenciesWordFormatter} manually, run the following command: ${installCommand}`)
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
if (installAnswer === 'not-install') {
|
|
74
|
-
task.skip(
|
|
75
|
-
|
|
85
|
+
task.skip(
|
|
86
|
+
`User chose to skip installation of ${dependenciesWordFormatter}`
|
|
87
|
+
)
|
|
88
|
+
return
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
if (installAnswer === 'install') {
|
|
79
92
|
// on macos we don't need sudo permissions to install dependencies, so every other platform required to do that
|
|
80
93
|
if (platform !== 'darwin') {
|
|
81
|
-
task.output = `Enter your sudo password! It's needed for ${
|
|
82
|
-
task.output = logger.style.command(
|
|
94
|
+
task.output = `Enter your sudo password! It's needed for ${dependenciesWordFormatter} installation.`
|
|
95
|
+
task.output = logger.style.command(
|
|
96
|
+
`>[sudo] password for ${os.userInfo().username}:`
|
|
97
|
+
)
|
|
83
98
|
}
|
|
84
99
|
|
|
85
100
|
return task.newListr(
|
|
86
101
|
execCommandTask(cmd, {
|
|
87
|
-
callback: (t) => {
|
|
88
|
-
task.output = t;
|
|
89
|
-
},
|
|
90
102
|
pipeInput: true
|
|
91
103
|
})
|
|
92
|
-
)
|
|
104
|
+
)
|
|
93
105
|
}
|
|
94
106
|
},
|
|
95
107
|
options: {
|
|
96
108
|
bottomBar: 10
|
|
97
109
|
}
|
|
98
|
-
})
|
|
110
|
+
})
|
|
99
111
|
|
|
100
|
-
module.exports = installDependenciesTask
|
|
112
|
+
module.exports = installDependenciesTask
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
const logger = require('@scandipwa/scandipwa-dev-utils/logger')
|
|
1
|
+
const logger = require('@scandipwa/scandipwa-dev-utils/logger')
|
|
2
2
|
|
|
3
|
-
const WEB_LOCAL_LOCATION_TITLE = `Location on ${
|
|
4
|
-
const WEB_LOCATION_TITLE = 'Location on the Web'
|
|
5
|
-
const WEB_ADMIN_LOCATION_TITLE = 'Panel location'
|
|
6
|
-
const WEB_ADMIN_CREDENTIALS_TITLE = 'Panel credentials'
|
|
7
|
-
const WEB_MAILDEV_LOCATION_TITLE = 'Panel location'
|
|
3
|
+
const WEB_LOCAL_LOCATION_TITLE = `Location on ${logger.style.misc('localhost')}`
|
|
4
|
+
const WEB_LOCATION_TITLE = 'Location on the Web'
|
|
5
|
+
const WEB_ADMIN_LOCATION_TITLE = 'Panel location'
|
|
6
|
+
const WEB_ADMIN_CREDENTIALS_TITLE = 'Panel credentials'
|
|
7
|
+
const WEB_MAILDEV_LOCATION_TITLE = 'Panel location'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @param {{ title: string, text: string }} param0
|
|
11
|
+
*/
|
|
9
12
|
const mapDataStyle = ({ title, text }) => ({
|
|
10
13
|
title,
|
|
11
14
|
text: logger.style.link(text),
|
|
12
15
|
link: text
|
|
13
|
-
})
|
|
16
|
+
})
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* @param {import("../../typings/context").ListrContext} ctx
|
|
17
|
-
* @return {{ frontend: { title: string, text: string }[], admin: { title: string,
|
|
20
|
+
* @return {{ frontend: { title: string, text: string }[], admin: { title: string, text: string }[], maildev: { title: string, text: string }[] }}
|
|
18
21
|
*/
|
|
19
22
|
const getInstanceMetadata = (ctx) => {
|
|
20
23
|
const {
|
|
@@ -23,64 +26,76 @@ const getInstanceMetadata = (ctx) => {
|
|
|
23
26
|
magentoConfiguration,
|
|
24
27
|
overridenConfiguration: { host, ssl }
|
|
25
28
|
}
|
|
26
|
-
} = ctx
|
|
29
|
+
} = ctx
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* @type {{ title: string, text: string }[]}
|
|
30
33
|
*/
|
|
31
|
-
const frontend = []
|
|
34
|
+
const frontend = []
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* @type {{ title: string, text: string }[]}
|
|
35
38
|
*/
|
|
36
|
-
const admin = []
|
|
39
|
+
const admin = []
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* @type {{ title: string, text: string }[]}
|
|
40
43
|
*/
|
|
41
|
-
const maildev = []
|
|
44
|
+
const maildev = []
|
|
42
45
|
|
|
43
|
-
const isNgrok = host.endsWith('ngrok.io')
|
|
46
|
+
const isNgrok = host.endsWith('ngrok.io')
|
|
44
47
|
|
|
45
48
|
if (isNgrok) {
|
|
46
49
|
frontend.push({
|
|
47
50
|
title: WEB_LOCAL_LOCATION_TITLE,
|
|
48
|
-
text: `${ssl.enabled ? 'https' : 'http'}://localhost${
|
|
49
|
-
|
|
51
|
+
text: `${ssl.enabled ? 'https' : 'http'}://localhost${
|
|
52
|
+
ssl.enabled || ports.sslTerminator === 80
|
|
53
|
+
? ''
|
|
54
|
+
: `:${ports.sslTerminator}`
|
|
55
|
+
}/`
|
|
56
|
+
})
|
|
50
57
|
frontend.push({
|
|
51
58
|
title: WEB_LOCATION_TITLE,
|
|
52
59
|
text: `${ssl.enabled ? 'https' : 'http'}://${host}/`
|
|
53
|
-
})
|
|
60
|
+
})
|
|
54
61
|
} else {
|
|
55
62
|
frontend.push({
|
|
56
63
|
title: WEB_LOCATION_TITLE,
|
|
57
|
-
text: `${ssl.enabled ? 'https' : 'http'}://${host}${
|
|
58
|
-
|
|
64
|
+
text: `${ssl.enabled ? 'https' : 'http'}://${host}${
|
|
65
|
+
ssl.enabled || ports.sslTerminator === 80
|
|
66
|
+
? ''
|
|
67
|
+
: `:${ports.sslTerminator}`
|
|
68
|
+
}/`
|
|
69
|
+
})
|
|
59
70
|
}
|
|
60
71
|
|
|
61
|
-
const webLocation = frontend.find((u) => u.title === WEB_LOCATION_TITLE)
|
|
72
|
+
const webLocation = frontend.find((u) => u.title === WEB_LOCATION_TITLE)
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
if (webLocation) {
|
|
75
|
+
admin.push({
|
|
76
|
+
title: WEB_ADMIN_LOCATION_TITLE,
|
|
77
|
+
text: logger.style.link(`${webLocation.text}admin`)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
67
80
|
|
|
68
81
|
admin.push({
|
|
69
82
|
title: WEB_ADMIN_CREDENTIALS_TITLE,
|
|
70
|
-
text: `${logger.style.misc(
|
|
71
|
-
|
|
83
|
+
text: `${logger.style.misc(
|
|
84
|
+
magentoConfiguration.user
|
|
85
|
+
)} - ${logger.style.misc(magentoConfiguration.password)}`
|
|
86
|
+
})
|
|
72
87
|
|
|
73
88
|
maildev.push({
|
|
74
89
|
title: WEB_MAILDEV_LOCATION_TITLE,
|
|
75
90
|
text: `http://${host}:${ports.maildevWeb}/`
|
|
76
|
-
})
|
|
91
|
+
})
|
|
77
92
|
|
|
78
93
|
return {
|
|
79
94
|
admin,
|
|
80
95
|
frontend: frontend.map(mapDataStyle),
|
|
81
96
|
maildev: maildev.map(mapDataStyle)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
84
99
|
|
|
85
100
|
module.exports = {
|
|
86
101
|
getInstanceMetadata,
|
|
@@ -90,4 +105,4 @@ module.exports = {
|
|
|
90
105
|
WEB_ADMIN_LOCATION_TITLE,
|
|
91
106
|
WEB_ADMIN_CREDENTIALS_TITLE
|
|
92
107
|
}
|
|
93
|
-
}
|
|
108
|
+
}
|
package/lib/util/ip.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
const { request } = require('smol-request')
|
|
1
|
+
const { request } = require('smol-request')
|
|
2
2
|
|
|
3
|
-
const ipRegex =
|
|
3
|
+
const ipRegex =
|
|
4
|
+
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} text
|
|
8
|
+
*/
|
|
9
|
+
const isIpAddress = (text) => ipRegex.test(text)
|
|
6
10
|
|
|
7
11
|
const externalIpProviders = [
|
|
8
12
|
'http://api.ipify.org/',
|
|
@@ -16,24 +20,24 @@ const externalIpProviders = [
|
|
|
16
20
|
'http://ipecho.net/plain',
|
|
17
21
|
'http://diagnostic.opendns.com/myip',
|
|
18
22
|
'http://trackip.net/ip'
|
|
19
|
-
]
|
|
23
|
+
]
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Get an external IP address
|
|
23
27
|
* @returns {Promise<string>}
|
|
24
28
|
*/
|
|
25
29
|
const getExternalIpAddress = async () => {
|
|
26
|
-
let ip
|
|
30
|
+
let ip
|
|
27
31
|
|
|
28
32
|
for (const ipProvider of externalIpProviders) {
|
|
29
33
|
try {
|
|
30
34
|
const response = await request(ipProvider, {
|
|
31
35
|
responseType: 'text'
|
|
32
|
-
})
|
|
36
|
+
})
|
|
33
37
|
|
|
34
38
|
if (response.status === 200) {
|
|
35
|
-
ip = response.data
|
|
36
|
-
break
|
|
39
|
+
ip = response.data
|
|
40
|
+
break
|
|
37
41
|
}
|
|
38
42
|
} catch (e) {
|
|
39
43
|
//
|
|
@@ -41,14 +45,14 @@ const getExternalIpAddress = async () => {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
if (!ip) {
|
|
44
|
-
throw new Error('External IP address is not available!')
|
|
48
|
+
throw new Error('External IP address is not available!')
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
return ip
|
|
48
|
-
}
|
|
51
|
+
return ip
|
|
52
|
+
}
|
|
49
53
|
|
|
50
54
|
module.exports = {
|
|
51
55
|
ipRegex,
|
|
52
56
|
isIpAddress,
|
|
53
57
|
getExternalIpAddress
|
|
54
|
-
}
|
|
58
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
const os = require('os')
|
|
1
|
+
const os = require('os')
|
|
2
2
|
|
|
3
|
-
const isRunningRoot = () =>
|
|
3
|
+
const isRunningRoot = () =>
|
|
4
|
+
['linux', 'darwin'].includes(os.platform()) &&
|
|
5
|
+
process.getuid &&
|
|
6
|
+
process.getuid() === 0 // UID 0 is always root
|
|
4
7
|
|
|
5
|
-
module.exports = isRunningRoot
|
|
8
|
+
module.exports = isRunningRoot
|
package/lib/util/is-wsl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const os = require('os')
|
|
2
|
-
const fs = require('fs')
|
|
1
|
+
const os = require('os')
|
|
2
|
+
const fs = require('fs')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Checks if process is running in wsl mode
|
|
@@ -7,24 +7,24 @@ const fs = require('fs');
|
|
|
7
7
|
*/
|
|
8
8
|
const getIsWsl = async () => {
|
|
9
9
|
if (process.platform !== 'linux') {
|
|
10
|
-
return false
|
|
10
|
+
return false
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
if (typeof process.env.WSL_DISTRO_NAME === 'string') {
|
|
14
|
-
return true
|
|
14
|
+
return true
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (os.release().toLowerCase().includes('microsoft')) {
|
|
18
|
-
return true
|
|
18
|
+
return true
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
try {
|
|
22
|
-
const procVersion = await fs.promises.readFile('/proc/version', 'utf8')
|
|
22
|
+
const procVersion = await fs.promises.readFile('/proc/version', 'utf8')
|
|
23
23
|
|
|
24
|
-
return procVersion.toLowerCase().includes('microsoft')
|
|
24
|
+
return procVersion.toLowerCase().includes('microsoft')
|
|
25
25
|
} catch (e) {
|
|
26
|
-
return false
|
|
26
|
+
return false
|
|
27
27
|
}
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
module.exports = getIsWsl
|
|
30
|
+
module.exports = getIsWsl
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
const semver = require('semver')
|
|
2
|
-
const macosVersion = require('macos-version')
|
|
3
|
-
const { execAsyncSpawn } = require('./exec-async-command')
|
|
1
|
+
const semver = require('semver')
|
|
2
|
+
const macosVersion = require('macos-version')
|
|
3
|
+
const { execAsyncSpawn } = require('./exec-async-command')
|
|
4
4
|
|
|
5
5
|
const getMacOSVersion = async () => {
|
|
6
|
-
const { code, result } = await execAsyncSpawn('sw_vers -productVersion',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
6
|
+
const { code, result } = await execAsyncSpawn('sw_vers -productVersion', {
|
|
7
|
+
withCode: true
|
|
8
|
+
})
|
|
10
9
|
|
|
11
10
|
if (code !== 0) {
|
|
12
|
-
return macosVersion()
|
|
11
|
+
return macosVersion()
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const { version } = semver.coerce(result) || {}
|
|
15
|
+
|
|
16
|
+
return version
|
|
17
|
+
}
|
|
17
18
|
|
|
18
19
|
module.exports = {
|
|
19
20
|
getMacOSVersion
|
|
20
|
-
}
|
|
21
|
+
}
|
package/lib/util/magento-task.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const UnknownError = require('../errors/unknown-error')
|
|
2
|
+
const runMagentoCommand = require('./run-magento')
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @param {String} command
|
|
@@ -11,20 +12,24 @@ const magentoTask = (command, options = {}) => ({
|
|
|
11
12
|
task: async (ctx, task) => {
|
|
12
13
|
try {
|
|
13
14
|
await runMagentoCommand(ctx, command, {
|
|
14
|
-
callback: !ctx.verbose
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
callback: !ctx.verbose
|
|
16
|
+
? undefined
|
|
17
|
+
: (t) => {
|
|
18
|
+
task.output = t
|
|
19
|
+
},
|
|
17
20
|
throwNonZeroCode: true
|
|
18
|
-
})
|
|
21
|
+
})
|
|
19
22
|
} catch (e) {
|
|
20
|
-
if (options.onError) {
|
|
21
|
-
options.onError(e)
|
|
23
|
+
if (e instanceof UnknownError && options.onError) {
|
|
24
|
+
options.onError(e)
|
|
22
25
|
}
|
|
26
|
+
|
|
27
|
+
throw e
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
options: {
|
|
26
31
|
bottomBar: 10
|
|
27
32
|
}
|
|
28
|
-
})
|
|
33
|
+
})
|
|
29
34
|
|
|
30
|
-
module.exports = magentoTask
|
|
35
|
+
module.exports = magentoTask
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const pathExists = require('./path-exists')
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const pathExists = require('./path-exists')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Check file system structure to detect possible unfinished installation
|
|
@@ -9,25 +9,31 @@ const pathExists = require('./path-exists');
|
|
|
9
9
|
*/
|
|
10
10
|
const matchFilesystem = async (cwd, structure) => {
|
|
11
11
|
if (Array.isArray(structure)) {
|
|
12
|
-
const ok = (
|
|
13
|
-
.
|
|
12
|
+
const ok = (
|
|
13
|
+
await Promise.all(
|
|
14
|
+
structure.map((str) => pathExists(path.join(cwd, str)))
|
|
15
|
+
)
|
|
16
|
+
).every((value) => value === true)
|
|
14
17
|
|
|
15
|
-
return ok
|
|
18
|
+
return ok
|
|
16
19
|
}
|
|
17
20
|
if (typeof structure === 'object') {
|
|
18
|
-
const ok = (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const ok = (
|
|
22
|
+
await Promise.all(
|
|
23
|
+
Object.entries(structure).map(([key, value]) => {
|
|
24
|
+
if (typeof value === 'boolean') {
|
|
25
|
+
return pathExists(path.join(cwd, key))
|
|
26
|
+
}
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
return matchFilesystem(path.join(cwd, key), value)
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
).every((value) => value === true)
|
|
26
32
|
|
|
27
|
-
return ok
|
|
33
|
+
return ok
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
return pathExists(path.join(cwd, structure))
|
|
31
|
-
}
|
|
36
|
+
return pathExists(path.join(cwd, structure))
|
|
37
|
+
}
|
|
32
38
|
|
|
33
|
-
module.exports = matchFilesystem
|
|
39
|
+
module.exports = matchFilesystem
|
package/lib/util/move-file.js
CHANGED
|
@@ -1,38 +1,53 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
1
|
+
const fs = require('fs')
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @param {{ from: string, to: string }} param0
|
|
5
|
+
*/
|
|
3
6
|
const moveFile = async ({ from, to }) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @returns {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
const copy = () =>
|
|
11
|
+
new Promise((resolve, reject) => {
|
|
12
|
+
const readStream = fs.createReadStream(from)
|
|
13
|
+
const writeStream = fs.createWriteStream(to)
|
|
14
|
+
/**
|
|
15
|
+
* @param {Error} e
|
|
16
|
+
*/
|
|
17
|
+
const onError = async (e) => {
|
|
18
|
+
await fs.promises.unlink(to)
|
|
19
|
+
reject(e)
|
|
20
|
+
}
|
|
11
21
|
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
readStream.on('error', onError)
|
|
23
|
+
writeStream.on('error', onError)
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
readStream.on('close', async () => {
|
|
26
|
+
try {
|
|
27
|
+
await fs.promises.unlink(from)
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e instanceof Error) {
|
|
30
|
+
onError(e)
|
|
31
|
+
return
|
|
32
|
+
} else if (typeof e === 'string') {
|
|
33
|
+
onError(new Error(e))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
resolve()
|
|
37
|
+
})
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
readStream.pipe(writeStream)
|
|
40
|
+
})
|
|
26
41
|
|
|
27
42
|
try {
|
|
28
|
-
await fs.promises.rename(from, to)
|
|
43
|
+
await fs.promises.rename(from, to)
|
|
29
44
|
} catch (e) {
|
|
30
45
|
if (e && e.code === 'EXDEV') {
|
|
31
|
-
await copy()
|
|
46
|
+
await copy()
|
|
32
47
|
} else {
|
|
33
|
-
throw e
|
|
48
|
+
throw e
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
|
-
}
|
|
51
|
+
}
|
|
37
52
|
|
|
38
|
-
module.exports = moveFile
|
|
53
|
+
module.exports = moveFile
|