forked from pattern-lab/patternlab-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.php
More file actions
135 lines (97 loc) · 5.27 KB
/
Copy pathbuilder.php
File metadata and controls
135 lines (97 loc) · 5.27 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*!
* Pattern Lab Builder CLI - v0.7.12
*
* Copyright (c) 2013-2014 Dave Olsen, http://dmolsen.com
* Licensed under the MIT license
*
*/
/*******************************
* General Set-up
*******************************/
// check to see if json_decode exists. might be disabled in installs of PHP 5.5
if (!function_exists("json_decode")) {
print "Please check that your version of PHP includes the JSON extension. It's required for Pattern Lab to run. Aborting.\n";
exit;
}
// auto-load classes
require(__DIR__.'/lib/autoload.php');
/*******************************
* Console Set-up
*******************************/
$console = new PatternLab\Console;
// set-up the generate command and options
$console->setCommand("g","generate","Generate Pattern Lab","The generate command generates an entire site a single time. By default it removes old content in public/, compiles the patterns and moves content from source/ into public/");
$console->setCommandOption("g","p","patternsonly","Generate only the patterns. Does NOT clean public/.","To generate only the patterns:");
$console->setCommandOption("g","n","nocache","Set the cacheBuster value to 0.","To turn off the cacheBuster:");
$console->setCommandOption("g","c","enablecss","Generate CSS for each pattern. Resource intensive.","To run and generate the CSS for each pattern:");
// set-up an alias for the generate command
$console->setCommand("b","build","Alias for the generate command","Alias for the generate command. Please refer to it's help for full options.");
// set-up the watch command and options
$console->setCommand("w","watch","Watch for changes and regenerate","The watch command builds Pattern Lab, watches for changes in source/ and regenerates Pattern Lab when there are any.");
$console->setCommandOption("w","p","patternsonly","Watches only the patterns. Does NOT clean public/.","To watch and generate only the patterns:");
$console->setCommandOption("w","n","nocache","Set the cacheBuster value to 0.","To turn off the cacheBuster:");
$console->setCommandOption("w","r","autoreload","Turn on the auto-reload service.","To turn on auto-reload:");
// set-up the snapshot command and options
$console->setCommand("s","snapshot","Take a snapshot of public/","The snapshot command copies the current state of public/ and puts it in snapshots/v*/.");
$console->setCommandOption("s","d:","dir:","Optional directory path","To add an optional directory path instead of the defaul v*/ path:","example-path/");
// set-up the fetch command and options
$console->setCommand("f:","fetch:","Fetch a starter kit","The fetch command grabs a starter kit from GitHub and puts it into source/.");
$console->setCommandSample("f","Install a starter kit:","github-org/github-repo");
$console->setCommandSample("f","Install a tagged version of a starter kit:","github-org/github-repo#tag");
// set-up the version command
$console->setCommand("v","version","Print the version number","The version command prints out the current version of Pattern Lab.");
// set-up the help command
$console->setCommand("h:","help:","Print the help for a given command","The help command prints out the help for a given flag. Just use -h with another command and it will tell you all of the options.");
/*******************************
* Figure out what to run
*******************************/
// get what was passed on the command line
$console->getArguments();
if ($console->findCommand("h|help")) {
$helpCommand = $console->findCommandValue("h|help");
$helpCommand = str_replace("-","",$helpCommand);
$helpCommand = (strlen($helpCommand) == 1) ? $helpCommand : $console->findCommandShort($helpCommand);
$helpCommand ? $console->writeHelpCommand($helpCommand) : $console->writeHelp();
} else if ($command = $console->getCommand()) {
// run commands
// load Pattern Lab's config, if first time set-up move files appropriately too
PatternLab\Config::loadOptions();
// set-up required vars
$enableCSS = $console->findCommandOption("c|enablecss");
$moveStatic = ($console->findCommandOption("p|patternsonly")) ? false : true;
$noCacheBuster = $console->findCommandOption("n|nocache");
$autoReload = $console->findCommandOption("r|autoreload");
if (($command == "g") || ($command == "b")) {
// load the generator
$g = new PatternLab\Generator();
$g->generate($enableCSS,$moveStatic,$noCacheBuster);
$g->printSaying();
} else if ($command == "w") {
// CSS feature should't be used with watch
$enableCSS = false;
// load the generator
$g = new PatternLab\Generator();
$g->generate($enableCSS,$moveStatic,$noCacheBuster);
// load the watcher
$w = new PatternLab\Watcher();
$w->watch($autoReload,$moveStatic,$noCacheBuster);
} else if ($command == "s") {
// run the snapshot command
$snapshotDir = $console->findCommandOptionValue("d|dir");
$s = new PatternLab\Snapshot();
$s->takeSnapshot($snapshotDir);
} else if ($command == "f") {
// run the snapshot command
$starterKit = $console->findCommandValue("f|fetch");
$sk = new PatternLab\StarterKit();
$sk->fetch($starterKit);
} else if ($command == "v") {
// write out the version number
print "You're running v".PatternLab\Config::$options["v"]." of the PHP version of Pattern Lab.\n";
exit;
}
} else {
// write the generic help
$console->writeHelp();
}