-
Notifications
You must be signed in to change notification settings - Fork 40
/
make.ado
285 lines (224 loc) · 7.64 KB
/
make.ado
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// documentation is written for markdoc package (github.com/haghish/markdoc)
// . markdoc make.ado, mini export(sthlp) replace
/***
_v. 1.1_
make
====
builds package installation files
Syntax
------
> __make__ _pakagename_ [, _options_]
### options
| _option_ | _Description_ |
|:------------------|:-------------------------------------|
| replace | replace existing files |
| toc | generates __stata.toc__ file |
| pkg | generates __packagename.pkg__ file |
| readme | generates __README.md__ file |
| title(_str_) | title of the package |
| version(_str_) | Version of the package |
| description(_str_) | description of the package |
| license(_str_) | license of the package |
| author(_str_) | author of the package |
| affiliation(_str_) | author's affiliation |
| url(_str_) | package or relevant url address |
| email(_str_) | package maintainer's email address |
| install(_str_) | installation files, seperated by ";"|
| ancillary(_str_) | ancillary files, seperated by ";" |
Description
-----------
__make__ generates the required files to make a Stata program
installable. the command is particularly handy for packages
hosted on private websites or GitHub
Example
-------
building the installation files for "mypackage" program
. make mypackage, replace toc pkg readme ///
title(title) version(1.0.0) license("MIT") ///
description(describe the package) ///
author(author name) ///
affiliation(author's affiliation) ///
email(package maintained email) ///
url(relevant URL) ///
install("a.ado;a.sthlp;b.ado;b.sthlp") ///
ancillary("x.dta;y.dta")
Author
------
E. F. Haghish
University of Göttingen
_haghish@med.uni-goesttingen.de_
[https://github.com/haghish](https://github.com/haghish)
License
-------
MIT License
- - -
This help file was dynamically produced by
[MarkDoc Literate Programming package](http://www.haghish.com/markdoc/)
***/
*cap prog drop make
prog make
syntax [anything] [, ///
toc ///
pkg ///
readme ///
replace ///
title(str) ///
Version(str) ///
Description(str) ///
license(str) ///
AUThor(str) ///
affiliation(str) ///
url(str) ///
email(str) ///
ancillary(str) ///
install(str) ///
]
//title of the package
//local anything : di `anything'
local capital : di ustrupper("`anything'")
//make the temporary files
tempfile toctmp pkgtmp readtmp
tempname hitch knot tocfile pkgfile readmefile
// Creating the TOC file
// -------------------------------------------------------
qui file open `tocfile' using "`toctmp'", write replace
if !missing("`version'") {
file write `tocfile' "v `version'" _n
}
if !missing("`author'") {
file write `tocfile' "d Materials by `author'" _n
}
if !missing("`affiliation'") {
file write `tocfile' "d `affiliation'" _n
}
if !missing("`email'") {
file write `tocfile' "d `email'" _n
}
if !missing("`url'") {
file write `tocfile' "d `url'" _n
}
file write `tocfile' _n
*file write `tocfile' "d '`capital''" _n(2)
if !missing("`description'") {
file write `tocfile' "d '`anything'': `description'" _n(2)
}
file write `tocfile' "p `anything'" _n
// Creating the PKG file
// -------------------------------------------------------
qui file open `pkgfile' using `"`pkgtmp'"', write replace
if !missing("`version'") {
file write `pkgfile' "v `version'" _n
}
if !missing("`title'") {
file write `pkgfile' "d '`capital'': `title'" _n
}
else file write `pkgfile' "d '`capital''" _n
if !missing("`description'") {
file write `pkgfile' "d " _n "d `description'" _n
}
//date
local today : di %td_CYND date("$S_DATE", "DMY")
file write `pkgfile' "d " _n
file write `pkgfile' "d Distribution-Date: `today'" _n
if !missing("`license'") {
file write `pkgfile' "d License:" " `license'" _n
}
file write `pkgfile' "d " _n
//if install and ancillary are empty, list all files
if missing("`install'") & missing("`ancillary'") {
//local install : dir . files "*" //the files are manually selected
tokenize `"`install'"'
while `"`macval(1)'"' != "" {
if `"`macval(1)'"' != ".DS_Store" ///
& substr(`"`macval(1)'"', -4,.) != ".pkg" ///
& substr(`"`macval(1)'"', -4,.) != ".toc" ///
& `"`macval(1)'"' != "README.md" ///
& `"`macval(1)'"' != "readme.md" ///
& `"`macval(1)'"' != "index.md" ///
& `"`macval(1)'"' != "index.html" ///
& `"`macval(1)'"' != "license.md" ///
& `"`macval(1)'"' != "dependency.do" ///
& `"`macval(1)'"' != "params.json" ///
& `"`macval(1)'"' != ".gitignore" ///
{
file write `pkgfile' `"F `1'"' _n
}
macro shift
}
}
if !missing("`install'") {
// get the file names install option
tokenize `"`install'"', parse(";")
preserve
qui clear
qui generate str files = ""
qui set obs 1000
local start = 0
while !missing("`1'") {
if "`1'" != ";" {
local start = `start' + 1
qui replace files = `"`1'"' in `start'
}
macro shift
}
qui drop if files==""
qui sort files
forval m = 1/`start' {
local n : di files[`m']
file write `pkgfile' `"F `n'"' _n
//check whether the file is unique
githubcheckfilename "`anything'", filename("`n'")
}
restore
}
if !missing("`ancillary'") {
// get the file names ancillary option
tokenize `"`ancillary'"', parse(";")
while !missing("`1'") {
if "`1'" != ";" {
file write `pkgfile' `"f `1'"' _n
//check whether the file is unique
githubcheckfilename "`anything'", filename("`n'")
}
macro shift
}
}
// Creating the README.md file
// -------------------------------------------------------
qui file open `readmefile' using "`readtmp'", write replace
if !missing("`version'") {
file write `readmefile' "_v. `version'_ " _n(2)
}
file write `readmefile' "`" "`anything'" "` "
if !missing("`title'") {
file write `readmefile' ": `title'"
}
local len = length(" `anything' : `title' ")
file write `readmefile' _n _dup(`len') "=" _n(2)
if !missing("`description'") {
file write `readmefile' "Description" _n
file write `readmefile' "-----------" _n(2)
file write `readmefile' "`description'" _n
}
if !missing("`license'") {
file write `readmefile' _n "### License" _n
file write `readmefile' "`license'" _n
}
if !missing("`author'") {
file write `readmefile' _n "Author" _n
file write `readmefile' "------" _n(2)
file write `readmefile' "**`author'** " _n
if !missing("`affiliation'") file write `readmefile' "`affiliation' " _n
if !missing("`email'") file write `readmefile' "`email' " _n
if !missing("`url'") file write `readmefile' "<`url'> " _n
}
//close and copy the files
file close `tocfile'
file close `pkgfile'
file close `readmefile'
if !missing("`toc'") quietly copy "`toctmp'" "stata.toc", `replace'
if !missing("`pkg'") quietly copy "`pkgtmp'" "`anything'.pkg", `replace'
if !missing("`readme'") quietly copy "`readtmp'" "README.md", `replace'
end
// make "test"
//, install("githubdependency.ado;githublist.ado;githubmake.ado")