Created
January 5, 2012 00:15
-
-
Save sunvisor/1562996 to your computer and use it in GitHub Desktop.
The Script build xFrameworkPX with ExtJS 4 Application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/** | |
* Create xFrameworkPX / Ext JS 4 Application | |
* xFrameworkPX / Ext JS 4 アプリケーションの骨組みを作ります | |
* File: buildPxApp.php | |
* Auther: sunvisor | |
* Date: 2011-09-30 | |
* Copyright (C) Sunvisor 2011 All right reserved. | |
**/ | |
// ショートハンド | |
define('DS', DIRECTORY_SEPARATOR); | |
define('HOME', getenv('HOME')); | |
// 開発のためのUserDir | |
define('USERDIR', HOME . DS . 'devsite'); | |
// ExtJSテンプレートの場所 | |
define('SOURCE_DIR', USERDIR . DS . 'ext4app' . DS . 'webapp'); | |
// PXのテンプレートの場所 | |
define('PXLIB', USERDIR . DS . 'PXTemplate'); | |
// パラメーター処理 | |
$param = getopt("p:b:d:x:t:"); | |
if( !isset($param['p']) ){ | |
showUsage($argv[0], USERDIR, SOURCE_DIR, PXLIB, EXTJS); | |
} else { | |
if( !isset($param['b']) ) | |
$param['b'] = USERDIR; | |
if( !isset($param['d']) ) | |
$param['d'] = strtolower($param['p']); | |
if( !isset($param['t']) ) | |
$param['t'] = SOURCE_DIR; | |
if( !isset($param['x']) ) | |
$param['x'] = PXLIB; | |
run($param); | |
} | |
function showUsage($cmdname, $baseDir, $templateDir, $pxDir, $extDir) | |
{ | |
echo <<<EOF | |
Usage | |
$cmdname -p <project> [-b <base dir>] [-d <dir name>] | |
-p <project> 必須: プロジェクトの名称 | |
-b <base dir> プロジェクトを出力するディレクトリ | |
ここで指定したディレクトリの下に<dir name>のディレクトリができる | |
デフォルトは$baseDir | |
-d <dir name> プロジェクトのディレクトリ名 | |
デフォルトはプロジェクト名を小文字にしたもの | |
-x <px dir> xFrameworkPXのテンプレートが保存してある場所 | |
デフォルトは $pxDir | |
-t <template dir> Ext JS 4 プロジェクトのテンプレートの保存場所 | |
デフォルトは $templateDir | |
EOF; | |
} | |
function run($param) | |
{ | |
echo "Cleating ". $param['p']. " Application.\n"; | |
echo "Application Name: " . $param['p'] . "\n"; | |
echo "Location: ". $param['b'] . DS . $param['d']. "\n\n"; | |
echo " Creating xFrameworkPX Project..."; | |
createPXProject($param); | |
echo "Done\n"; | |
echo " Creating Ext JS Application..."; | |
$webapp = $param['b'] . DS. $param['d'] . DS . 'webapp'; | |
createExtApp($param['p'], $param['t'], $webapp); | |
echo "Done\n"; | |
} | |
/** | |
* createPXProject | |
* xFrameworkPXのプロジェクトを生成します | |
* | |
* @param mixed $param | |
* @access public | |
* @return void | |
*/ | |
function createPXProject($param) | |
{ | |
$dest = $param['b'] . DS . $param['d']; | |
$proj = $param['p']; | |
$dir = $param['d']; | |
$c = "cp -ra " . PXLIB . " " . $dest; | |
exec($c); | |
editHtaccess($dest, $dir); | |
} | |
function editHtaccess($dest, $dir) | |
{ | |
$fileName = $dest.DS . 'public_html' . DS . '.htaccess'; | |
$content = file_get_contents($fileName); | |
$content = str_replace('xFrameworkPX', $dir, $content); | |
file_put_contents($fileName, $content); | |
} | |
/** | |
* createExtApp | |
* アプリケーションをビルドする関数 | |
* | |
* @param string $proj | |
* @param string $source | |
* @param string $dest | |
* @access public | |
* @return void | |
*/ | |
function createExtApp($proj, $source, $dest) | |
{ | |
if( !file_exists($dest) ){ | |
mkdir($dest); | |
} | |
$src = dir($source); | |
$path = $src->path; | |
while( $file = $src->read() ){ | |
$fileName = $path . DS . $file; | |
if( $file == '.' || $file == '..' ) { | |
// no | |
} elseif ( is_dir( $fileName ) ){ | |
createExtApp($proj, $fileName, $dest. DS. $file); | |
} else { | |
$destFile = $dest . DS . $file; | |
echo "Create File: $destFile\n"; | |
buildFile($fileName, $destFile, $proj); | |
} | |
} | |
} | |
/** | |
* buildFile | |
* 一つのファイルをビルドする関数。 | |
* @param string $sourceFile | |
* @param string $destFile | |
* @param string $proj | |
* @access public | |
* @return void | |
*/ | |
function buildFile($sourceFile, $destFile, $proj) | |
{ | |
$content = file_get_contents($sourceFile); | |
$content = str_replace('${PROJ}', $proj, $content); | |
$content = str_replace('${DATE}', date('Y/m/d'), $content); | |
$content = str_replace('${YEAR}', date('Y'), $content); | |
file_put_contents($destFile, $content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment