Skip to content

Commit 110ad05

Browse files
committed
wip
2 parents 3a13e59 + 862930e commit 110ad05

File tree

10 files changed

+133
-73
lines changed

10 files changed

+133
-73
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
github: :vendor_name
2-
custom: :author_homepage

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Security Policy
22

3-
If you discover any security related issues, please email :author_email instead of using the issue tracker.
3+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <:author_email>
3+
Copyright (c) :vendor_name <[email protected]>
44

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

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# :package_description
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_name/:package_name.svg?style=flat-square)](https://packagist.org/packages/:vendor_name/:package_name)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/:vendor_name/:package_name/Tests?label=tests)](https://github.com/:vendor_name/:package_name/actions?query=workflow%3ATests+branch%3Amaster)
5-
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_name/:package_name.svg?style=flat-square)](https://packagist.org/packages/:vendor_name/:package_name)
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/run-tests?label=tests)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3ATests+branch%3Amaster)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/Check%20&%20fix%20styling?label=code%20style)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
67

78
---
89
This package can be used as to scaffold a Laravel package. Follow these steps to get started:
@@ -28,14 +29,14 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh
2829
You can install the package via composer:
2930

3031
```bash
31-
composer require :vendor_name/:package_name
32+
composer require vendor_slug/package_slug
3233
```
3334

3435
## Usage
3536

3637
```php
37-
$skeleton = new Spatie\Skeleton();
38-
echo $skeleton->echoPhrase('Hello, Spatie!');
38+
$skeleton = new VendorName\Skeleton();
39+
echo $skeleton->echoPhrase('Hello, VendorName!');
3940
```
4041

4142
## Testing

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": ":vendor_name/:package_name",
2+
"name": "vendor_slug/package_slug",
33
"description": ":package_description",
44
"keywords": [
55
":vendor_name",
6-
":package_name"
6+
"package_slug"
77
],
8-
"homepage": "https://github.com/:vendor_name/:package_name",
8+
"homepage": "https://github.com/vendor_slug/package_slug",
99
"license": "MIT",
1010
"authors": [
1111
{
1212
"name": ":author_name",
13-
"email": ":author_email",
13+
"email": "[email protected]",
1414
"role": "Developer"
1515
}
1616
],
@@ -25,12 +25,12 @@
2525
},
2626
"autoload": {
2727
"psr-4": {
28-
"Spatie\\Skeleton\\": "src"
28+
"VendorName\\Skeleton\\": "src"
2929
}
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"Spatie\\Skeleton\\Tests\\": "tests"
33+
"VendorName\\Skeleton\\Tests\\": "tests"
3434
}
3535
},
3636
"scripts": {

configure-skeleton.sh

Lines changed: 91 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,133 @@
44

55
script_name=$(basename "$0")
66

7-
ask_question(){
7+
ask_question() {
88
# ask_question <question> <default>
99
local ANSWER
1010
read -r -p "$1 ($2): " ANSWER
1111
echo "${ANSWER:-$2}"
1212
}
1313

14-
confirm(){
14+
confirm() {
1515
# confirm <question> (default = N)
1616
local ANSWER
1717
read -r -p "$1 (y/N): " -n 1 ANSWER
1818
echo " "
1919
[[ "$ANSWER" =~ ^[Yy]$ ]]
2020
}
2121

22+
slugify() {
23+
# slugify <input> <separator>
24+
# Jack, Jill & Clémence LTD => jack-jill-clemence-ltd
25+
# inspiration: https://github.com/pforret/bashew/blob/master/template/normal.sh
26+
separator="$2"
27+
[[ -z "$separator" ]] && separator="-"
28+
# shellcheck disable=SC2020
29+
echo "$1" |
30+
tr '[:upper:]' '[:lower:]' |
31+
tr 'àáâäæãåāçćčèéêëēėęîïííīįìłñńôöòóœøōõßśšûüùúūÿžźż' 'aaaaaaaaccceeeeeeeiiiiiiilnnoooooooosssuuuuuyzzz' |
32+
awk '{
33+
gsub(/[\[\]@#$%^&*;,.:()<>!?\/+=_]/," ",$0);
34+
gsub(/^ */,"",$0);
35+
gsub(/ *$/,"",$0);
36+
gsub(/ */,"-",$0);
37+
gsub(/[^a-z0-9\-]/,"");
38+
print;
39+
}' |
40+
sed "s/-/$separator/g"
41+
}
42+
43+
titlecase() {
44+
# titlecase <input> <separator>
45+
# Jack, Jill & Clémence LTD => JackJillClemenceLtd
46+
separator="${2:-}"
47+
echo "$1" |
48+
tr '[:upper:]' '[:lower:]' |
49+
tr 'àáâäæãåāçćčèéêëēėęîïííīįìłñńôöòóœøōõßśšûüùúūÿžźż' 'aaaaaaaaccceeeeeeeiiiiiiilnnoooooooosssuuuuuyzzz' |
50+
awk '{ gsub(/[\[\]@#$%^&*;,.:()<>!?\/+=_-]/," ",$0); print $0; }' |
51+
awk '{
52+
for (i=1; i<=NF; ++i) {
53+
$i = toupper(substr($i,1,1)) tolower(substr($i,2))
54+
};
55+
print $0;
56+
}' |
57+
sed "s/ /$separator/g"
58+
}
59+
2260
git_name=$(git config user.name)
2361
author_name=$(ask_question "Author name" "$git_name")
2462

2563
git_email=$(git config user.email)
2664
author_email=$(ask_question "Author email" "$git_email")
2765

28-
homepage_temp=$(echo $author_email | awk -F '@' '{print $NF}')
29-
homepage_guess=${homepage_temp//[[:blank:]]/}
30-
author_homepage=$(ask_question "Author homepage" "$homepage_guess")
31-
32-
username_guess=${author_name//[[:blank:]]/}
66+
username_guess=$(git config remote.origin.url | cut -d: -f2-)
67+
username_guess=$(dirname "$username_guess")
68+
username_guess=$(basename "$username_guess")
3369
author_username=$(ask_question "Author username" "$username_guess")
3470

71+
vendor_name=$(ask_question "Vendor name" "$author_username")
72+
vendor_slug=$(slugify "$vendor_name")
73+
VendorName=$(titlecase "$vendor_name" "")
74+
3575
current_directory=$(pwd)
3676
folder_name=$(basename "$current_directory")
3777

38-
vendor_name_unsantized=$(ask_question "Vendor name" "$author_name")
3978
package_name=$(ask_question "Package name" "$folder_name")
40-
package_description=$(ask_question "Package description" "$package_name")
79+
package_slug=$(slugify "$package_name" "_")
4180

42-
# convert my-class-title to MyClassTitle - RODO: use to subsctitute ./src/*
43-
class_name=$(echo "$package_name" | sed 's/[-_]/ /g' | awk '{for(j=1;j<=NF;j++){ $j=toupper(substr($j,1,1)) substr($j,2) }}1' | sed 's/[[:space:]]//g')
81+
ClassName=$(titlecase "$package_name")
82+
ClassName=$(ask_question "Class Name" "$ClassName")
83+
package_description=$(ask_question "Package description" "This is my package $ClassName")
4484

45-
vendor_name_lower_case=`echo "$vendor_name_unsantized" | tr '[:upper:]' '[:lower:]'`
46-
vendor_name="$(tr '[:lower:]' '[:upper:]' <<< ${vendor_name_lower_case:0:1})${vendor_name_lower_case:1}"
85+
echo -e "------"
86+
echo -e "Author : $author_name ($author_username, $author_email)"
87+
echo -e "Vendor : $vendor_name ($vendor_slug)"
88+
echo -e "Package : $package_slug <$package_description>"
89+
echo -e "Namespace : $VendorName\\$ClassName"
90+
echo -e "ClassName : $ClassName"
91+
echo -e "------"
4792

48-
echo
49-
echo -e "Author: $author_name ($author_username, $author_email) - $author_homepage"
50-
echo -e "Package: $package_name <$package_description>"
93+
files=$(grep -E -r -l -i ":author|:vendor|:package|:short|spatie|[email protected]|vendor_slug|skeleton|Skeleton" --exclude-dir=vendor ./* ./.github/* | grep -v "$script_name")
5194

52-
echo
53-
echo "This script will replace the above values in all files in the project directory."
54-
if ! confirm "Modify files?" ; then
95+
echo "This script will replace the above values in all relevant files in the project directory."
96+
97+
if ! confirm "Modify files?"; then
5598
$safe_exit 1
5699
fi
57100

58-
echo
59-
files=$(grep -E -r -l -i ":author|:package|spatie|skeleton|:vendor_name" --exclude-dir=vendor ./* ./.github/* | grep -v "$script_name")
60-
61-
for file in $files ; do
62-
echo "Customising file $file"
63-
temp_file="$file.temp"
64-
< "$file" \
65-
sed "s/:author_name/$author_name/g" \
66-
| sed "s/:author_username/$author_username/g" \
67-
| sed "s/:author_email/$author_email/g" \
68-
| sed "s/:author_homepage/$author_homepage/g" \
69-
| sed "s/:package_name/$package_name/g" \
70-
| sed "s/Spatie/$vendor_name/g" \
71-
| sed "s/Skeleton/$class_name/g" \
72-
| sed "s/:vendor_name/$vendor_name_lower_case/g" \
73-
| sed "s/:package_description/$package_description/g" \
74-
| sed "/^\*\*Note:\*\* Run/d" \
75-
> "$temp_file"
76-
rm -f "$file"
77-
new_file=`echo $file | sed -e "s/Skeleton/${class_name}/g"`
78-
mv "$temp_file" "$new_file"
101+
files_regex=":author|:vendor|:package|:short|spatie|[email protected]|vendor_slug|skeleton|Skeleton"
102+
grep -E -r -l -i "$files_regex" --exclude-dir=vendor ./* ./.github/* \
103+
| grep -v "$script_name" \
104+
| while read -r file ; do
105+
new_file="$file"
106+
new_file="${new_file//Skeleton/$ClassName}"
107+
new_file="${new_file//skeleton/$package_slug}"
108+
new_file="${new_file//laravel_/}"
109+
echo "adapting file $file -> $new_file"
110+
temp_file="$file.temp"
111+
< "$file" \
112+
sed "s/:author_name/$author_name/g" \
113+
| sed "s/:author_username/$author_username/g" \
114+
| sed "s/[email protected]/$author_email/g" \
115+
| sed "s/:vendor_name/$vendor_name/g" \
116+
| sed "s/vendor_slug/$vendor_slug/g" \
117+
| sed "s/VendorName/$VendorName/g" \
118+
| sed "s/:package_name/$package_name/g" \
119+
| sed "s/package_slug/$package_slug/g" \
120+
| sed "s/skeleton/$package_slug/g" \
121+
| sed "s/Skeleton/$ClassName/g" \
122+
| sed "s/:package_description/$package_description/g" \
123+
| sed "/^\[\]\(delete\) /d" \
124+
> "$temp_file"
125+
rm -f "$file"
126+
mv "$temp_file" "$new_file"
79127
done
80128

81-
echo "Replaced all values and Renamed the files"
82-
83-
if confirm "Execute composer install and phpunit test" ; then
129+
if confirm "Execute composer install and phpunit test"; then
84130
composer install && ./vendor/bin/phpunit
85131
fi
86132

87-
if confirm 'Let this script delete itself (since you only need it once)?' ; then
133+
if confirm 'Let this script delete itself (since you only need it once)?'; then
88134
echo "Delete $0 !"
89-
rm -- "$0"
135+
sleep 1 && rm -- "$0"
90136
fi

phpunit.xml.dist

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
verbose="true"
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
executionOrder="random"
15+
failOnWarning="true"
16+
failOnRisky="true"
17+
failOnEmptyTestSuite="true"
18+
beStrictAboutOutputDuringTests="true"
19+
verbose="true"
1220
>
1321
<testsuites>
14-
<testsuite name="Spatie Test Suite">
22+
<testsuite name="VendorName Test Suite">
1523
<directory>tests</directory>
1624
</testsuite>
1725
</testsuites>

src/SkeletonClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Spatie\Skeleton;
3+
namespace VendorName\Skeleton;
44

55
class SkeletonClass
66
{

tests/ExampleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Spatie\Skeleton\Tests;
3+
namespace VendorName\Skeleton\Tests;
44

55
use PHPUnit\Framework\TestCase;
66

undo_configure.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
echo "## revert to last commit"
3+
git reset head --hard
4+
git clean -f -d
5+
rm -fr vendor
6+
rm composer.lock

0 commit comments

Comments
 (0)