Skip to content

Commit

Permalink
Automatically fix composer.json type
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Oct 26, 2021
1 parent 466ce19 commit eef725e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/tasks/PropertiesFromComposerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,22 @@ public function main()
$this->prefix = 'composer';
}

$json = json_decode(file_get_contents($this->file), true);
$fileText = file_get_contents($this->file);
$json = json_decode($fileText, true);

// Verify project.type
if (array_key_exists('type', $json)) {
if (!array_key_exists($json['type'], $this->types)) {
$this->throwError('Invalid Joomla Extension Type: ' . $json['type']);
$type = str_replace('.', '-', $json['type']);
if ($type != $json['type']) {
file_put_contents($this->file, str_replace($json['type'], $type, $fileText));
$json['type'] = $type;
$this->log('composer.json has been updated, be sure to review the changes', Project::MSG_WARN);
}

if (str_replace('.', '-', $json[''])) {
if (!array_key_exists($json['type'], $this->types)) {
$this->throwError('Invalid Joomla Extension Type: ' . $json['type']);
}
}
} else {
$this->throwError('Missing composer property: Unable to determine Joomla type');
Expand Down

0 comments on commit eef725e

Please sign in to comment.