Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
735afe9982 | |||
6b2bc43d79 | |||
1d1406bb2b | |||
fc50e669a5 | |||
60c6cb3bcd | |||
a799374399 | |||
281a31f5f7 | |||
74e2c1a3fd | |||
91b8b3b570 | |||
e5bbf2dc03 | |||
48bdc40932 | |||
805139d2ca | |||
7c1aec3497 | |||
bfcd194a09 | |||
c901bc3b0c | |||
ad5d10979d |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
output/
|
14
README.md
14
README.md
@ -14,9 +14,15 @@ Synopsis: `isidore <command> [options]`
|
|||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
- `new <dir> <name>`: create a new project directory `<dir>` with project name
|
- `new [args] <dir>`: create a new project.
|
||||||
`<name>`.
|
- `<dir>`: new project directory.
|
||||||
- `build`: build the website (default).
|
- `-i`: interactive mode.
|
||||||
|
- `build [args]`: build the website.
|
||||||
|
- `-j<n>`: number of jobs to run concurrently. With `0` it compiles all files
|
||||||
|
at once.
|
||||||
|
- `-v`: run with verbose output.
|
||||||
|
- `serve`, `server [args]`: run an HTTP server of the output (default port 8080).
|
||||||
|
- `-p <port>`: port number to bind server to.
|
||||||
- `clean`: cleans build files.
|
- `clean`: cleans build files.
|
||||||
- `help`: show help information.
|
- `help`: show help information.
|
||||||
- `version`: show Isidore version number.
|
- `version`: show Isidore version number.
|
||||||
@ -47,7 +53,7 @@ please take a look at what needs to be done in the [roadmap](/ROADMAP.md), or
|
|||||||
check if there are any to-do comments in the code:
|
check if there are any to-do comments in the code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
grep -r "TODO" src/
|
grep "TODO" isidore.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## License & Copyright
|
## License & Copyright
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
- New project subcommand
|
- New project subcommand
|
||||||
- Basic project compilation
|
- Basic project compilation
|
||||||
- v0.2
|
- v0.2
|
||||||
- Don't compile already compiled files
|
|
||||||
- Multi-thread compiling
|
- Multi-thread compiling
|
||||||
|
- Helper functions & variables
|
||||||
- v0.3
|
- v0.3
|
||||||
- Markdown support
|
- Markdown support
|
||||||
|
1
example/.isidore-version
Normal file
1
example/.isidore-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.1.0
|
5
example/config.php
Normal file
5
example/config.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
$site_name = "New Project";
|
||||||
|
$site_author = "Nicolás A. Ortega Froysa";
|
||||||
|
$site_url = "http://example.com/";
|
||||||
|
?>
|
23
example/site/blog.html.php
Normal file
23
example/site/blog.html.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
$title = "Blog";
|
||||||
|
include("templates/header.html.php");
|
||||||
|
?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Welcome to my blog page! Here's a list of my current entries:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<?php
|
||||||
|
foreach(glob("site/blog/*.cfg.php") as $i)
|
||||||
|
{
|
||||||
|
include($i);
|
||||||
|
$entry_file = substr($i, 4, -8) . '.html';
|
||||||
|
echo "<li><a href='$entry_file'>$blog_date - $blog_title</a></li>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
include("templates/footer.html.php");
|
||||||
|
?>
|
4
example/site/blog/000-first.cfg.php
Normal file
4
example/site/blog/000-first.cfg.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
$blog_title = "My First Post";
|
||||||
|
$blog_date = "2022-11-07";
|
||||||
|
?>
|
9
example/site/blog/000-first.html.php
Normal file
9
example/site/blog/000-first.html.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
include("site/blog/000-first.cfg.php");
|
||||||
|
$title = $blog_title;
|
||||||
|
include("templates/header.html.php");
|
||||||
|
?>
|
||||||
|
<p>My first blog post.</p>
|
||||||
|
<?php
|
||||||
|
include("templates/footer.html.php");
|
||||||
|
?>
|
10
example/site/index.html.php
Normal file
10
example/site/index.html.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
$title = "Home";
|
||||||
|
include("templates/header.html.php");
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
Hello, World! This is an example page.
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
include("templates/footer.html.php");
|
||||||
|
?>
|
1
example/site/static-file.txt
Normal file
1
example/site/static-file.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
A test file.
|
2
example/templates/footer.html.php
Normal file
2
example/templates/footer.html.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
</body>
|
||||||
|
</html>
|
7
example/templates/header.html.php
Normal file
7
example/templates/header.html.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><?= $title ?> | <?= $site_name?></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1><?= $title ?></h1>
|
148
isidore.sh
148
isidore.sh
@ -26,6 +26,11 @@ ISIDORE_AUTHOR_NAME=""
|
|||||||
PROG_NAME=$0
|
PROG_NAME=$0
|
||||||
PROJECT_NAME="Isidore"
|
PROJECT_NAME="Isidore"
|
||||||
|
|
||||||
|
SOURCE_DIR="site/"
|
||||||
|
OUTPUT_DIR="output/"
|
||||||
|
TEMPLATE_DIR="templates/"
|
||||||
|
PROJECT_CONFIG_FILE="config.php"
|
||||||
|
|
||||||
##
|
##
|
||||||
# Create the configuration file. This function is called if it does not already
|
# Create the configuration file. This function is called if it does not already
|
||||||
# exist.
|
# exist.
|
||||||
@ -87,9 +92,11 @@ function print_help()
|
|||||||
print_usage
|
print_usage
|
||||||
echo -e "\nCOMMANDS:
|
echo -e "\nCOMMANDS:
|
||||||
new [-i] <dir>
|
new [-i] <dir>
|
||||||
Create a new Isidore project (use interactive mode with '-i')
|
Create a new Isidore project
|
||||||
build
|
build [-v] [-j<n>]
|
||||||
Build the project rooted in the current directory
|
Build the project rooted in the current directory
|
||||||
|
serve | server [-p <port>]
|
||||||
|
Serve a local HTTP server of the output directory
|
||||||
clean
|
clean
|
||||||
Clean the built files
|
Clean the built files
|
||||||
version
|
version
|
||||||
@ -103,7 +110,7 @@ function print_help()
|
|||||||
##
|
##
|
||||||
function check_in_project()
|
function check_in_project()
|
||||||
{
|
{
|
||||||
if ! [ -f "./config.php" ] || ! [ -f "./.isidore-version" ]
|
if ! [ -f "$PROJECT_CONFIG_FILE" ] || ! [ -f "./.isidore-version" ]
|
||||||
then
|
then
|
||||||
echo "ERROR: You are not currently in the root of an Isidore project."
|
echo "ERROR: You are not currently in the root of an Isidore project."
|
||||||
exit 1
|
exit 1
|
||||||
@ -121,9 +128,9 @@ function new_project()
|
|||||||
{
|
{
|
||||||
echo "$PROJECT_NAME v$ISIDORE_VERSION"
|
echo "$PROJECT_NAME v$ISIDORE_VERSION"
|
||||||
|
|
||||||
NEW_PROJECT_DIR=$1
|
local NEW_PROJECT_DIR=$1
|
||||||
NEW_PROJECT_NAME="New Project"
|
local NEW_PROJECT_NAME="New Project"
|
||||||
NEW_PROJECT_URL="http://example.com/"
|
local NEW_PROJECT_URL="http://example.com/"
|
||||||
if [ $2 == 1 ]
|
if [ $2 == 1 ]
|
||||||
then
|
then
|
||||||
echo -n "Project name: "
|
echo -n "Project name: "
|
||||||
@ -132,19 +139,19 @@ function new_project()
|
|||||||
read NEW_PROJECT_URL
|
read NEW_PROJECT_URL
|
||||||
fi
|
fi
|
||||||
mkdir $NEW_PROJECT_DIR
|
mkdir $NEW_PROJECT_DIR
|
||||||
mkdir -p $NEW_PROJECT_DIR/site/
|
mkdir -p $NEW_PROJECT_DIR/$SOURCE_DIR
|
||||||
mkdir -p $NEW_PROJECT_DIR/templates/
|
mkdir -p $NEW_PROJECT_DIR/$TEMPLATE_DIR
|
||||||
echo \
|
echo \
|
||||||
"<?php
|
"<?php
|
||||||
\$site_name = \"$NEW_PROJECT_NAME\";
|
\$site_name = \"$NEW_PROJECT_NAME\";
|
||||||
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
|
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
|
||||||
\$site_url = \"$NEW_PROJECT_URL\";
|
\$site_url = \"$NEW_PROJECT_URL\";
|
||||||
?>" >> $NEW_PROJECT_DIR/config.php
|
?>" >> $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE
|
||||||
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
|
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
|
||||||
|
|
||||||
echo "New project created."
|
echo "New project created."
|
||||||
[ $2 == 0 ] &&
|
[ $2 == 0 ] &&
|
||||||
echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file."
|
echo "Consider taking a look at the $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE file."
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -153,43 +160,76 @@ function new_project()
|
|||||||
function clean_project()
|
function clean_project()
|
||||||
{
|
{
|
||||||
check_in_project
|
check_in_project
|
||||||
if [ -d "./output/" ]
|
if [ -d "$OUTPUT_DIR" ]
|
||||||
then
|
then
|
||||||
rm -r ./output/
|
rm -r $OUTPUT_DIR
|
||||||
fi
|
fi
|
||||||
echo "Project cleaned."
|
echo "Project cleaned."
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
# Build the project.
|
# Build the project.
|
||||||
|
#
|
||||||
|
# Params:
|
||||||
|
# $1 - Verbose flag
|
||||||
|
# $2 - Maximum number of jobs to run
|
||||||
##
|
##
|
||||||
function build_project()
|
function build_project()
|
||||||
{
|
{
|
||||||
check_in_project
|
check_in_project
|
||||||
|
|
||||||
mkdir -p ./output/
|
mkdir -p $OUTPUT_DIR
|
||||||
WORKDESK="/tmp/isidore-workdesk"
|
|
||||||
CFG_HEADER_FILE="$WORKDESK/config-header.php"
|
for i in $(find $SOURCE_DIR -type d)
|
||||||
mkdir -p $WORKDESK
|
|
||||||
for i in $(find site/ -name '*.php')
|
|
||||||
do
|
do
|
||||||
echo "<?php include getcwd() . '/config.php'; ?>" > $CFG_HEADER_FILE
|
mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}}
|
||||||
mkdir -p $WORKDESK/${i%/*}
|
|
||||||
cat $CFG_HEADER_FILE $i > $WORKDESK/$i
|
|
||||||
# the 4 offset is to avoid including `site/`
|
|
||||||
: ${i:4}
|
|
||||||
OUT_DIR="./output/${_%/*}"
|
|
||||||
mkdir -p $OUT_DIR
|
|
||||||
: ${i: :-4}
|
|
||||||
OUT_FILE="$OUT_DIR/${_##*/}"
|
|
||||||
php $WORKDESK/$i > $OUT_FILE
|
|
||||||
done
|
done
|
||||||
|
|
||||||
rm -r $WORKDESK
|
# number of current jobs
|
||||||
|
local NUM_JOBS="\j"
|
||||||
|
|
||||||
|
for i in $(find site -type f -regextype posix-extended -not -regex '.*\.(cfg|CFG)\.(php|PHP)')
|
||||||
|
do
|
||||||
|
while (( $2 != 0 )) && (( ${NUM_JOBS@P} >= $2 ))
|
||||||
|
do
|
||||||
|
wait -n
|
||||||
|
done
|
||||||
|
|
||||||
|
# parallel block
|
||||||
|
(
|
||||||
|
if [[ $i =~ .*\.(php|PHP) ]]
|
||||||
|
then
|
||||||
|
: ${i:${#SOURCE_DIR}}
|
||||||
|
local OUT_FILE="$OUTPUT_DIR/${_: :-4}"
|
||||||
|
if [ $1 == 1 ]
|
||||||
|
then
|
||||||
|
echo "Building $OUT_FILE ..."
|
||||||
|
fi
|
||||||
|
cat $PROJECT_CONFIG_FILE $i | php > $OUT_FILE
|
||||||
|
else
|
||||||
|
local OUT_FILE="$OUTPUT_DIR/${i:${#SOURCE_DIR}}"
|
||||||
|
if [ $1 == 1 ]
|
||||||
|
then
|
||||||
|
echo "Copying $OUT_FILE ..."
|
||||||
|
fi
|
||||||
|
cp $i $OUT_FILE
|
||||||
|
fi
|
||||||
|
) &
|
||||||
|
done
|
||||||
|
|
||||||
|
# wait for jobs to finish
|
||||||
|
wait -n
|
||||||
}
|
}
|
||||||
|
|
||||||
set_config_vars
|
set_config_vars
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]
|
||||||
|
then
|
||||||
|
echo "No subcommand was specified. Use the 'help' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
new)
|
new)
|
||||||
if [ $# -lt 2 ]
|
if [ $# -lt 2 ]
|
||||||
@ -210,15 +250,59 @@ case $1 in
|
|||||||
then
|
then
|
||||||
NEW_DIR="$i"
|
NEW_DIR="$i"
|
||||||
else
|
else
|
||||||
echo "Unknown argument for new '$i'. Use the 'help' command."
|
echo "Unknown argument for new '$i'. Use the 'help' subcommand."
|
||||||
print_usage
|
print_usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
new_project $NEW_DIR $INTERACTIVE;;
|
new_project $NEW_DIR $INTERACTIVE;;
|
||||||
build)
|
build)
|
||||||
build_project;;
|
VERBOSE=0
|
||||||
|
JOBS=1
|
||||||
|
for i in ${@:2}
|
||||||
|
do
|
||||||
|
case $i in
|
||||||
|
-v)
|
||||||
|
VERBOSE=1;;
|
||||||
|
-j*)
|
||||||
|
if ! [[ "$i" =~ ^-j[0-9]+$ ]]
|
||||||
|
then
|
||||||
|
echo "Argument '$i' badly formatted. Should be '-j<n>' where <n> is a number."
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
JOBS=${i:2};;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument for build '$i'. Use the 'help' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
build_project $VERBOSE $JOBS;;
|
||||||
|
serve|server)
|
||||||
|
PORT=8080
|
||||||
|
shift
|
||||||
|
while getopts "p:" opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
p)
|
||||||
|
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]
|
||||||
|
then
|
||||||
|
echo "Invalid port $OPTARG. Please enter a number."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
PORT=$OPTARG;;
|
||||||
|
?)
|
||||||
|
echo "Invalid argument $OPTARG. Use the 'help' subcommand."
|
||||||
|
print_usage
|
||||||
|
exit 1;;
|
||||||
|
:)
|
||||||
|
echo "Option -$OPTARG requires an argument."
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
php -S localhost:$PORT -t $OUTPUT_DIR/;;
|
||||||
clean)
|
clean)
|
||||||
clean_project;;
|
clean_project;;
|
||||||
help)
|
help)
|
||||||
@ -226,7 +310,7 @@ case $1 in
|
|||||||
version)
|
version)
|
||||||
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
|
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
|
||||||
*)
|
*)
|
||||||
echo "Unknown command $1. Use the 'help' command."
|
echo "Unknown command $1. Use the 'help' subcommand."
|
||||||
print_usage
|
print_usage
|
||||||
exit 1;;
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user