forked from masak/proto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-new-project
executable file
·241 lines (197 loc) · 6.69 KB
/
create-new-project
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
#
# NAME
# create-new-project - a project stubber for proto
#
# SYNOPSIS
#
# # Create project for installation by proto: (without leading '# ')
# read -p "Git username: " GITUSER
# read -p "Project name: " PROJECT
# export GITUSER PROJECT
# cd /tmp # (or your preferred directory)
# git clone git://github.com/masak/proto.git proto
# cd proto
# ./proto
# ./create-new-project
# ./proto install $PROJECT
# ./proto test $PROJECT
# ./proto update $PROJECT
#
# DESCRIPTION
# Implements proto's PIONEER plan in code
#
# BUGS
# 1. The 'cat >>modules.list <<EOF' causes two problems:
# 1a. Subsequent 'git pull' in proto cannot merge remote modules.list
# changes with the local change, needing manual intervention.
# 1b. Creating the same project multiple times also appends the project
# information to modules.list multiple times, needing manual fixing.
cat <<EOF
Hi, this is 'create-new-project', a project stubber for the 'proto' installer.
Choose the collaboration site you would like to use.
1. Github (http://github.com)
2. Gitorious (http://gitorious.org)
3. GoogleCode (TODO)
4. CPAN (TODO)
EOF
read -p "Your choice (1 or 2): " SITE
if [ "$SITE" == "1" ] ; then
CREATEURL=https://github.com/signup/free
LOGINURL=https://github.com/login
NEWREPOURL=http://github.com/repositories/new
HOMENICK=github
elif [ "$SITE" == "2" ] ; then
CREATEURL=http://gitorious.org/users/new
LOGINURL=http://gitorious.org/login
NEWREPOURL=http://gitorious.org/projects/new
HOMENICK=gitorious
else
echo -e "\nYou managed to not select either 1 or 2, so I give up.\n"
exit 1;
fi
cat <<EOF
You first need to have done the following:
1. Create a collaboration account <$CREATEURL>
2. Log in <$LOGINURL>
3. Create a project repository <$NEWREPOURL>
4. Enter your Project Name,
Description, Homepage etc
and click Create.
This script will then take care of the next steps.
If 'Create' worked, continue here, otherwise type Control-C to exit.
EOF
# Skip these reads if they were already done as in SYNOPSIS above.
if [ -z "$GITUSER" -a -z "$PROJECT" ]
then
read -p "Username used in steps 1..4 above: " GITUSER
read -p "Project : " PROJECT
export GITUSER PROJECT
else
echo "Using '$GITUSER' as username and '$PROJECT' as project."
read -p "After you've followed the steps above, press Enter..."
fi
if [ "$SITE" == "1" ] ; then
[email protected]:$GITUSER/$PROJECT.git
PUBLICURL=http://github.com/$GITUSER/$PROJECT/tree/master
elif [ "$SITE" == "2" ] ; then
[email protected]:$PROJECT/mainline.git
PUBLICURL=http://gitorious.org/projects/$PROJECT
fi
# Begin with some steps from "Create New Repository" at github.com
PROJECTBASE=/tmp/$PROJECT
rm -rf $PROJECTBASE # ensure a clean start every time
#mkdir $PROJECTBASE
mkdir -p $PROJECTBASE/lib/Example $PROJECTBASE/t
#git init
#GIT_DIR=$PROJECTBASE/.git git init
# The project should consist mainly of Perl modules.
# Module files contain classes, roles, grammars and documentation.
#mkdir lib/Example
#mkdir $PROJECTBASE/lib/Example
#cat >lib/Example/Hello.pm <<EOF
cat >$PROJECTBASE/lib/Example/Hello.pm <<EOF
class Example::Hello
{
method greet { return "hello" }
method place { return "world" }
}
=begin pod
=head1 NAME
Example::Hello - canonical "hello, world!" example for proto
=head1 AUTHOR
$GITUSER ($GITUSER at $HOMENICK and @example.com)
=end pod
EOF
# Include a test suite to improve your karma (and your code quality)
# Beware the \ escapes for bash:
cat >$PROJECTBASE/t/01-simple.t <<EOF
use Example::Hello;
use Test;
plan 3;
my Example::Hello \$greeter .= new;
isa_ok( \$greeter, 'Example::Hello', 'create object' );
is( \$greeter.greet, 'hello', 'greet' );
is( \$greeter.place, 'world', 'place' );
EOF
# Create a Makefile.in like this example from mathw's form project.
# note the \$ escaping to play nicely with bash.
cat >$PROJECTBASE/Makefile.in <<EOF
PERL6=<PERL6>
PERL6LIB=<PERL6LIB>
SOURCES=lib/Example/Hello.pm
PIRS=\$(SOURCES:.pm=.pir)
all: \$(PIRS) lib/Test.pir
%.pir: %.pm
\$(PERL6) --target=pir --output=\$@ \$<
clean:
rm -f \$(PIRS)
realclean: clean
rm Makefile
test: all
PERL6LIB=\$(PERL6LIB) prove -e '\$(PERL6)' -r --nocolor t/
help:
@echo ''
@echo 'You can make the following targets:'
@echo ''
@echo 'all - default, precompile .pm to .pir for speed'
@echo 'clean - removes .pir and backup~ files'
@echo 'realclean - clean and also remove Makefile'
@echo 'test - verify that the code works as specified'
@echo 'help - this text.'
@echo ''
EOF
# The above 'Makefile.in' needs something active to transform it into
# a Makefile. Copy the Configure.pm6 from proto and invoke it by the
# following Configure (Perl 6) script:
cp lib/Configure.pm6 $PROJECTBASE/lib
cat >$PROJECTBASE/Configure <<EOF
# Configure - Makefile builder - see documentation in lib/Configure.pm6
use v6; BEGIN { @*INC.unshift('lib'); }; use Configure;
EOF
# Notify proto about dependencies on other modules. The installer will
# ensure that PERL6LIB can also find the content of their lib
# directories so that 'use thatmodule;' Just Works.
#cat >deps.proto <<EOF
cat >$PROJECTBASE/deps.proto <<EOF
# project dependencies
EOF
# Some steps from "New Project" guidelines at github or gitorious.
(
cd $PROJECTBASE
git init
git add deps.proto Makefile.in Configure.pl lib/Configure.pm
git add lib/Example/* t/*
git commit -m "created by proto's create-new-project"
git remote add origin $REMOTEURL
git push origin master
)
if [ "$?" != "0" ]; then echo 'Cannot git push. Start again.'; exit 1; fi
# Add these lines to proto's modules.list
cat >>projects.list <<EOF
$PROJECT:
home: $HOMENICK
owner: $GITUSER
EOF
cat <<EOF
5. If there were NO errors above, your repository on $HOMENICK should be
ready. In your browser click on the repository link or
$PUBLICURL
6. Ask a proto maintainer to add these lines to 'modules.list', or simply
edit your local copy:
$PROJECT:
home: $HOMENICK
owner: $GITUSER
7. Then you should be able to install and test your project:
./proto install $PROJECT
./proto test $PROJECT
Now create-new-project is finished, and your work really starts :)
8. Replace $PROJECT/lib/Example/Hello.pm with your module file(s)
and update SOURCES in $PROJECT/Makefile.in accordingly.
Run 'perl6 Configure.pl' after each change to Makefile.in.
9. Add README, LICENCE and other instructions.
10. Revise and extend $PROJECT/t/01-simple.t as well, and run
'make test' after every change that affects execution of your code.
11. Use 'git push' early and often.
On behalf of the 'proto' developers, this script wishes you a good day.
EOF