我正在开发一个模块,其中有一个子模块用于扫描条形码,它需要这、quagga。目前,您必须手动下载库并将其放入库dir中。如果我将它作为依赖项添加到模块中,则不首先安装它就无法安装它。
在安装子模块时,我可以让composer或其他东西将git下载到库吗?
编辑: libraries.yml
form:
version: VERSION
css:
layout:
css/commerce_pos_barcode_scanning.css: {}
js:
js/commerce_pos_barcode_scanning.js: {}
dependencies:
- core/jquery
- core/drupal
- commerce_pos/quagga
quagga:
remote: https://github.com/serratus/quaggaJS.git
version: 1.0.0
license:
name: MIT
url: https://github.com/serratus/quaggaJS/blob/master/LICENSE
gpl-compatible: yes
js:
/libraries/webrtc/adapter-latest.js: {}
/libraries/quagga/quagga.min.js: {}install.yml
function commerce_pos_barcode_scanning_requirements($phase) {
$requirements = [];
if ($phase == 'install' || $phase == 'runtime') {
$path = 'libraries/quagga/quagga.min.js';
if (!file_exists($path)) {
$requirements['commerce_pos_barcode_scanning'] = [
'title' => t('POS Barcode Scanning'),
'description' => t('To scan barcodes, you need to install the quagga JavaScript library. How To'),
'severity' => REQUIREMENT_WARNING,
];
}
else {
$requirements['commerce_pos_barcode_scanning'] = [
'title' => t('POS Barcode Scanning'),
'severity' => REQUIREMENT_OK,
'value' => t('quagga JavaScript library has been configured.'),
];
}
}
return $requirements;
}发布于 2020-02-13 07:01:23
您可以编辑文件composer.js
找到"web/libraries/{$name}": ["type:drupal-library"],更改为
"web/libraries/{$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset",
"vendor:npm-asset",
"vendor:bower-asset",
],添加存储库
{
"type": "package",
"package": {
"name": "serratus/quaggaJS",
"version": "0.12.1",
"type": "drupal-library",
"source": {
"url": "https://github.com/serratus/quaggaJS.git",
"type": "git",
"reference": "master"
},
"dist": {
"url": "https://github.com/serratus/quaggaJS/zipball/master/serratus-quaggaJS-v0.12.1-14-g862df88.zip",
"type": "zip"
},
"require": {
"composer/installers": "^1.0.20"
}
}
}并运行composer require "serratus/quaggaJS"
发布于 2020-02-14 08:47:43
要自动完成这一任务,人们只需自己配置项目的composer.json。因此,我建议再解释一次,如何通过drupal.org上的项目页面上的Composer或模块的文档来完成这一任务。
另一种不可取的方法是提供Drush命令来下载库。就像语义UI API做的那样。在GitLab上浏览他们的代码。该命令尚未移植到D8。但我想你会明白的。也许也值得一看他们的8.x-1.x分支。看看他们是如何在D8中解决的。
下面的代码是7.x-1.x。SEMANTIC_UI_DOWNLOAD_URL导致GitHub上的Zip文件。
$args = func_get_args();if ($args) { $path = $args;}$path{//我们对库模块有依赖关系,所以不需要检查//TODO:有方法获取库目录的路径吗?//如果它是站点特定的?例如:站点/domain.com/库?$path = drush_get_context('DRUSH_DRUPAL_ROOT')。'/sites/all/libraries/semantic_ui';} //创建路径,如果它还不存在的话。添加了防止//任何错误尝试或黑客攻击的substr检查!if (substr($path,-11) == 'semantic_ui‘& !is_dir($path)) { drush_mkdir($path);} if (is_dir($path ).{drush_log(‘语义Ui已经出现在@path。不需要下载。’、数组(@path‘=> $path)、'ok');}$path (drush_op('chdir',$path)& drush_shell_exec('wget’)。SEMANTIC_UI_DOWNLOAD_URL。‘-O semantic_ui.zip’&& drush_shell_exec('unzip semantic_ui.zip') && drush_shell_exec('rm -rf semantic_ui.zip') & drush_shell_exec('mv Semantic - Ui -master/*‘)和drush_shell_exec('rm -rf语义-Ui-master’){drush_log(‘最新语义Ui库已下载到@path’),数组(@path‘=> $path)、“成功”);}drush_log{dt(‘Drush无法下载语义Ui库到@path’、数组(@path‘=> $path)、'error');}
https://drupal.stackexchange.com/questions/291049
复制相似问题