forked from jpstacey/drush-m2c
-
Notifications
You must be signed in to change notification settings - Fork 2
/
m2c.drush.inc
103 lines (90 loc) · 2.02 KB
/
m2c.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @file
* Drush make to Composer (m2c)
*/
/**
* Implements hook_drush_help().
*/
function m2c_drush_help($section) {
switch($section) {
case 'drush:m2c':
return dt("Drush make to Composer file conversion");
break;
}
}
/**
* Implements hook_drush_command().
*/
function m2c_drush_command() {
$items = array();
$items['m2c'] = array(
'description' => 'Convert a Drush makefile to composer format, on standard output',
'arguments' => array(
'makefile' => 'Makefile location',
),
'options' => array(
'add-drupal-repositories' => 'Add drupal project repositories (defaults to FALSE)',
),
'aliases' => array('make2composer'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
return $items;
}
/**
* Implements hook_command_validate().
*
* Check makefile location provided, and that it exists.
*/
function drush_m2c_validate($makefile = NULL) {
if (!$makefile) {
drush_set_error("DRUSH_M2C_NO_MAKEFILE", "You must specify a makefile.");
return;
}
if (!file_exists($makefile)) {
drush_set_error("DRUSH_M2C_NO_MAKEFILE", "Makefile does not exist: '$makefile'.");
return;
}
}
/**
* Drush command callback.
*/
function drush_m2c($makefile) {
drush_include_engine("parsers", "default");
$composer = m2c_parsers_default_m2c(
m2c_parsers_default_internal($makefile)
);
$json = json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
// Replace tabs with spaces.
$json = preg_replace("~\\t~", ' ', $json);
print $json;
}
/**
* Implements hook_drush_engine_type_info().
*/
function m2c_drush_engine_type_info() {
return array(
'hacks' => array(),
'parsers' => array(),
);
}
/**
* Implements hook_drush_engine_ENGINE().
*/
function m2c_drush_engine_hacks() {
return array(
'make' => array(
'description' => "Hacks",
),
);
}
/**
* Implements hook_drush_engine_ENGINE().
*/
function m2c_drush_engine_parsers() {
return array(
'default' => array(
'description' => "Parsers",
),
);
}