Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit b5769cc

Browse files
committed
laying in Pattern Lab 2
1 parent 34d3ab2 commit b5769cc

File tree

9 files changed

+319
-9
lines changed

9 files changed

+319
-9
lines changed

.gitignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.DS_Store
2+
export/*
23
public/*
3-
source/*
4-
config.ini
5-
latest-change.txt
6-
*-ck.js
7-
*.sass-cache/
4+
source/styleguide/*
5+
vendor/*

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013-14 Brad Frost, http://bradfrostweb.com & Dave Olsen, http://dmolsen.com
3+
Copyright (c) 2016 Brad Frost, http://bradfrostweb.com & Dave Olsen, http://dmolsen.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

composer.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "pattern-lab/edition-mustache-standard",
3+
"description": "The Standard Edition of Pattern Lab for Mustache. Installs all Mustache-related dependencies.",
4+
"keywords": ["pattern lab", "mustache"],
5+
"homepage": "http://patternlab.io",
6+
"license": "MIT",
7+
"type": "project",
8+
"authors": [
9+
{
10+
"name": "Dave Olsen",
11+
"email": "[email protected]",
12+
"homepage": "http://dmolsen.com",
13+
"role": "Lead Developer"
14+
}
15+
],
16+
"support": {
17+
"issues": "https://github.com/pattern-lab/patternlab-php/issues",
18+
"wiki": "http://patternlab.io/docs/",
19+
"source": "https://github.com/pattern-lab/patternlab-php/releases"
20+
},
21+
"autoload": {
22+
"psr-0": {
23+
"PatternLab": "core/src/"
24+
}
25+
},
26+
"require": {
27+
"php": ">=5.3.6",
28+
"pattern-lab/core": "^2.0.0",
29+
"pattern-lab/patternengine-mustache": "^2.0.0",
30+
"pattern-lab/styleguidekit-mustache-default": "^3.0.0"
31+
},
32+
"scripts": {
33+
"server": "php core/console --server",
34+
"generate": "php core/console --generate",
35+
"watch": "php core/console --watch",
36+
"start": "php core/console --server --with-watch",
37+
"post-install-cmd": [
38+
"PatternLab\\Installer::postInstallCmd"
39+
],
40+
"post-update-cmd": [
41+
"PatternLab\\Installer::postUpdateCmd"
42+
],
43+
"post-root-package-install": [
44+
"PatternLab\\Installer::setProjectInstall",
45+
"PatternLab\\Installer::getSuggestedStarterKits",
46+
"PatternLab\\Installer::getConfigOverrides"
47+
],
48+
"post-package-install": [
49+
"PatternLab\\Installer::postPackageInstall"
50+
],
51+
"post-package-update": [
52+
"PatternLab\\Installer::postPackageUpdate"
53+
],
54+
"pre-package-uninstall": [
55+
"PatternLab\\Installer::prePackageUninstall"
56+
]
57+
},
58+
"extra": {
59+
"patternlab": {
60+
"starterKitSuggestions": [
61+
"pattern-lab/starterkit-mustache-demo",
62+
"pattern-lab/starterkit-mustache-base"
63+
]
64+
}
65+
}
66+
}

config/README config/.gitkeep

File renamed without changes.

core/console

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*!
4+
* Pattern Lab Builder CLI
5+
*
6+
* Copyright (c) 2016 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
*/
10+
11+
use \PatternLab\Config;
12+
use \PatternLab\Console;
13+
use \PatternLab\Dispatcher;
14+
use \PatternLab\Timer;
15+
16+
// check to see if json_decode exists. might be disabled in installs of PHP 5.5
17+
if (!function_exists("json_decode")) {
18+
print "Please check that your version of PHP includes the JSON extension. It's required for Pattern Lab to run. Aborting.\n";
19+
exit;
20+
}
21+
22+
// set-up the project base directory
23+
$baseDir = __DIR__.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR;
24+
25+
// auto-load classes
26+
if (file_exists($baseDir."vendor".DIRECTORY_SEPARATOR."autoload.php")) {
27+
require($baseDir."vendor".DIRECTORY_SEPARATOR."autoload.php");
28+
} else {
29+
print "it doesn't appear that pattern lab has been set-up yet...\n";
30+
print "please install pattern lab's dependencies by typing: composer install...\n";
31+
exit;
32+
}
33+
34+
// start the timer
35+
Timer::start();
36+
37+
// load the options
38+
Console::init();
39+
Config::init($baseDir);
40+
41+
// initialize the dispatcher & note that the config has been loaded
42+
Dispatcher::init();
43+
Dispatcher::getInstance()->dispatch("config.configLoadEnd");
44+
45+
// run the console
46+
Console::run();

core/server/router.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*!
4+
* Router for the PHP Server
5+
*
6+
* Copyright (c) 2016 Dave Olsen
7+
* Licensed under the MIT license
8+
*
9+
*/
10+
11+
use \PatternLab\Config;
12+
13+
// set-up the project base directory
14+
$baseDir = __DIR__."/../../";
15+
16+
// auto-load classes
17+
if (file_exists($baseDir."vendor/autoload.php")) {
18+
require($baseDir."vendor/autoload.php");
19+
} else {
20+
print "it doesn't appear that pattern lab has been set-up yet...\n";
21+
print "please install pattern lab's dependencies by typing: php core/bin/composer.phar install...\n";
22+
exit;
23+
}
24+
25+
// load the options and be quiet about it
26+
Config::init($baseDir, false);
27+
28+
if (($_SERVER["SCRIPT_NAME"] == "") || ($_SERVER["SCRIPT_NAME"] == "/")) {
29+
30+
require("index.html");
31+
32+
} else if (file_exists(Config::getOption("publicDir").$_SERVER["SCRIPT_NAME"])) {
33+
34+
return false;
35+
36+
} else {
37+
38+
header("HTTP/1.0 404 Not Found");
39+
print "file doesn't exist.";
40+
41+
}

core/src/PatternLab/Installer.php

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
3+
/*!
4+
* Installer Class
5+
*
6+
* Copyright (c) 2016 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* References the InstallerUtil class that is included in pattern-lab/core
10+
*
11+
*/
12+
13+
namespace PatternLab;
14+
15+
use \Composer\Script\Event;
16+
use \Composer\Installer\PackageEvent;
17+
use \PatternLab\InstallerUtil;
18+
19+
class Installer {
20+
21+
protected static $installerInfo = array("projectInstall" => false, "packagesRemove" => false, "suggestedStarterKits" => array(), "configOverrides" => array(), "patternLabPackages" => array());
22+
23+
/**
24+
* Get any config overrides that may exist for the edition
25+
* @param {Object} a script event object from composer
26+
*/
27+
public static function getConfigOverrides(Event $event) {
28+
29+
$extra = $event->getComposer()->getPackage()->getExtra();
30+
if (isset($extra["patternlab"]) && isset($extra["patternlab"]["config"]) && is_array($extra["patternlab"]["config"])) {
31+
self::$installerInfo["configOverrides"] = $extra["patternlab"]["config"];
32+
}
33+
34+
}
35+
36+
/**
37+
* Get the package info from each patternlab-* package's composer.json
38+
* @param {String} the type of event fired during the composer install
39+
* @param {Object} a script event object from composer
40+
*/
41+
public static function getPackageInfo($type, $event) {
42+
43+
$package = ($type == "update") ? $event->getOperation()->getTargetPackage() : $event->getOperation()->getPackage();
44+
$packageType = $package->getType();
45+
$packageExtra = $package->getExtra();
46+
$packageInfo = array();
47+
48+
// make sure we're only evaluating pattern lab packages
49+
if (strpos($packageType,"patternlab-") !== false) {
50+
51+
$packageInfo["name"] = $package->getName();
52+
$packageInfo["type"] = $packageType;
53+
$packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package);
54+
$packageInfo["pathDist"] = $packageInfo["pathBase"].DIRECTORY_SEPARATOR."dist".DIRECTORY_SEPARATOR;
55+
$packageInfo["extra"] = (isset($packageExtra["patternlab"])) ? $packageExtra["patternlab"] : array();
56+
57+
self::$installerInfo["packages"][] = $packageInfo;
58+
59+
}
60+
61+
}
62+
63+
/**
64+
* Get the suggested starter kits from the root package composer.json
65+
* @param {Object} a script event object from composer
66+
*/
67+
public static function getSuggestedStarterKits(Event $event) {
68+
69+
$extra = $event->getComposer()->getPackage()->getExtra();
70+
if (isset($extra["patternlab"]) && isset($extra["patternlab"]["starterKitSuggestions"]) && is_array($extra["patternlab"]["starterKitSuggestions"])) {
71+
self::$installerInfo["suggestedStarterKits"] = $extra["patternlab"]["starterKitSuggestions"];
72+
}
73+
74+
}
75+
76+
/**
77+
* Run the centralized postInstallCmd
78+
* @param {Object} a script event object from composer
79+
*/
80+
public static function postInstallCmd(Event $event) {
81+
82+
InstallerUtil::postInstallCmd(self::$installerInfo, $event);
83+
84+
}
85+
86+
/**
87+
* Run the centralized postUpdateCmd
88+
* @param {Object} a script event object from composer
89+
*/
90+
public static function postUpdateCmd(Event $event) {
91+
92+
InstallerUtil::postUpdateCmd(self::$installerInfo, $event);
93+
94+
}
95+
96+
/**
97+
* Clean-up when a package is removed
98+
* @param {Object} a script event object from composer
99+
*/
100+
public static function postPackageInstall(PackageEvent $event) {
101+
102+
self::getPackageInfo("install", $event);
103+
104+
}
105+
106+
/**
107+
* Clean-up when a package is removed
108+
* @param {Object} a script event object from composer
109+
*/
110+
public static function postPackageUpdate(PackageEvent $event) {
111+
112+
self::getPackageInfo("update", $event);
113+
114+
}
115+
116+
/**
117+
* Clean-up when a package is removed
118+
* @param {Object} a script event object from composer
119+
*/
120+
public static function prePackageUninstall(PackageEvent $event) {
121+
122+
// make sure the postUpdateCmd doesnt actually do anything
123+
self::setPackagesRemove();
124+
125+
// get the basic package info
126+
$package = $event->getOperation()->getPackage();
127+
$packageType = $package->getType();
128+
$packageInfo = array();
129+
130+
// make sure we're only evaluating pattern lab packages. remove attributes related to them.
131+
if (strpos($packageType,"patternlab-") !== false) {
132+
133+
$packageInfo["name"] = $package->getName();
134+
$packageInfo["type"] = $packageType;
135+
$packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package);
136+
137+
InstallerUtil::packageRemove($packageInfo);
138+
139+
}
140+
141+
}
142+
143+
/**
144+
* Set the packages remove boolean to true
145+
*/
146+
public static function setPackagesRemove() {
147+
148+
self::$installerInfo["packagesRemove"] = true;
149+
150+
}
151+
152+
/**
153+
* Set the project install boolean to true
154+
* @param {Object} a script event object from composer
155+
*/
156+
public static function setProjectInstall(Event $event) {
157+
158+
self::$installerInfo["projectInstall"] = true;
159+
160+
}
161+
162+
}

public/README

-3
This file was deleted.

source/README source/.gitkeep

File renamed without changes.

0 commit comments

Comments
 (0)