Repository navigation
Expand file tree
/
Copy pathautomate.php
More file actions
98 lines (93 loc) · 3.41 KB
/
Copy pathautomate.php
File metadata and controls
98 lines (93 loc) · 3.41 KB
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
<?php
/**
* Automate is a package generator for css and js files
* This gets the files from a repository file and based on a automate.json the program knows what components needs to download
*/
class automate{
private $file;
private $rep;
private $dir;
/**
* Automate configurtations
* @param [string] $jsonFile config file of the application, automate.json
* @param string $repositoryFile file with the links for the packages
*/
function __construct($jsonFile, $repositoryFile = 'automate.rep') {
$this->rep = $repositoryFile;
$this->file = $jsonFile;
}
/**
* This creates a package file system that can be implemented in any app
* @param [string] $name the name of the package
* @param [string] $version the version of the package
* @param [string] $type the type of the package can be js css or package
* @param [array $files list of files in this package
* @return [array] array of packages
*/
function createRep($name, $version, $type, $files) {
$package = new stdClass();
$package->name = $name;
$package->version = $version;
$package->files = $files;
$package->type = $type;
$this->repository[] = $package;
}
/**
* return list of packages
* @return [array] list of packages
*/
function getRep(){
var_dump($this->repository);
}
/**
* generate a file repository, this file is a json of the list of packages available to all apps
* @return [type] [description]
*/
function generateRep(){
$gen = json_encode($this->repository);
file_put_contents($this->rep, $gen);
}
/**
* get my app config, this method get's my config file for this specific app, in this app i config the folder for where the packages go and the list of my needed packages
* @return [type] [description]
*/
function getConfig(){
$conf = file_get_contents($this->file);
$conf = json_decode($conf);
$this->dir = $conf->config->dir;
$requires = $conf->require;
foreach ($requires as $req => $key) {
$this->get_pack($req,$key);
}
}
/**
* install packages, this method get's the packages that i want, search for them in the repository file and if find install
* @param [string] $name Name of the packages that i want
* @param [string] $version Version of the package that i want
* @return [type] [description]
*/
function get_pack($name, $version){
$rep = json_decode(file_get_contents($this->rep));
for($i = 0; $i < sizeof($rep); $i++) {
if($rep[$i]->name == $name) {
if($rep[$i]->version == $version) {
$files = $rep[$i]->files;
$type = $rep[$i]->type;
foreach($files as $file){
$f = file_get_contents($file);
mkdir($this->dir."/".$type);
file_put_contents($this->dir."/".$type."/".$name.".js", $f);
}
}
}
}
}
}
$a = new automate("automate.json", "config/automate.rep");
/*
$a->createRep("angularjs", "1.4.2", array("https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"));
$a->createRep("jquery", "1", array("https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"));
$a->createRep("jquery", "2", array("https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"));
$a->generateRep();
*/
$a->getConfig();