-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.ts
1073 lines (852 loc) · 28.9 KB
/
transform.ts
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as path from "@std/path";
//import * as yaml from "@std/yaml";
import Handlebars from "npm:handlebars";
import { CodeMeta } from "./codemeta.ts";
import { gitOrgOrPerson, gitReleaseHash } from "./gitcmds.ts";
export function getFormatFromExt(
filename: string | undefined,
defaultFormat: string
): string {
if (filename !== undefined) {
//NOTE: We need to handle special case files like README.md, INSTALL.md
switch (filename) {
case "README.md":
return "readme.md";
case "INSTALL.md":
return "install.md";
case "Makefile":
return "Makefile";
}
switch (path.extname(filename)) {
case ".cff":
return "cff";
case ".ts":
return "ts";
case ".js":
return "js"
case ".go":
return "go";
case ".py":
return "py";
case ".md":
return "md";
case ".hbs":
return "hbs";
case ".tmpl":
return "pdtmpl";
case ".pdtmpl":
return "pdtmpl";
case ".sh":
return "sh";
case ".ps1":
return "ps1";
}
}
return defaultFormat;
}
export function isSupportedFormat(format: string | undefined): boolean {
if (format === undefined) {
return false;
}
return ["cff", "ts", "js", "go", "py", "md", "hbs", "pdtmpl", "sh", "ps1", "readme.md", "install.md", "Makefile"].indexOf(format) > -1;
}
// FIXME: need to handle the special case renderings for README.md,
// INSTALL.md and the installer scripts.
export async function transform(
cm: CodeMeta,
format: string,
isDeno: boolean
): Promise<string | undefined> {
if (!isSupportedFormat(format)) {
return undefined;
}
let obj: { [key: string]: any } = cm.toObject();
obj["project_name"] = path.basename(Deno.cwd());
obj["releaseHash"] = await gitReleaseHash();
if (obj['dateModified'] === undefined || obj['dateModified'] === '') {
const d = new Date();
const year = `${d.getFullYear()}`;
const month = `${d.getMonth() + 1}`.padStart(2, '0');
const day = `${d.getDate() + 1}`.padStart(2, '0');
obj['dateModified'] = `${year}-${month}-${day}`;
}
(obj['releaseDate'] === undefined) ? obj['releaseDate'] = obj['dateModified'] : '';
obj['git_org_or_person'] = await gitOrgOrPerson();
let licenseText: string = "";
try {
licenseText = await Deno.readTextFile("LICENSE");
} catch (err) {
console.log(`warning: missing license file, ${err}`);
licenseText = "";
}
if (licenseText !== undefined && licenseText !== "") {
obj["licenseText"] = licenseText;
}
if (cm.codeRepository !== "") {
obj["repositoryLink"] = cm.codeRepository.replace("git+https", "https");
}
switch (format) {
case "readme.md":
return renderTemplate(obj, readmeMdText);
case "install.md":
return renderTemplate(obj, installMdText);
case "Makefile":
if (isDeno) { return renderTemplate(obj, denoMakefileText); };
return renderTemplate(obj, goMakefileText);
case "cff":
return renderTemplate(obj, cffTemplateText);
case "ts":
return renderTemplate(obj, tsTemplateText);
case "js":
return renderTemplate(obj, tsTemplateText);
case "go":
return renderTemplate(obj, goTemplateText);
case "py":
return renderTemplate(obj, pyTemplateText);
case "md":
return renderTemplate(obj, mdTemplateText);
case "sh":
return renderTemplate(obj, shInstallerText);
case "ps1":
return renderTemplate(obj, ps1InstallerText);
case "hbs":
return renderTemplate(obj, hbsTemplateText)?.replace(
"$$content$$",
"{{{content}}}",
);
case "pdtmpl": // render as Pandoc template
return renderTemplate(obj, hbsTemplateText)?.replace(
"$$content$$",
"${body}",
);
default:
return undefined;
}
return undefined;
}
export function renderTemplate(obj: {[key: string]: any}, tmpl: string): string | undefined {
const template = Handlebars.compile(tmpl);
if (template === undefined) {
console.log(`templates failed to compile, ${tmpl}`);
return undefined;
}
return template(obj);
}
const cffTemplateText = `
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
type: software
{{#if name}}title: {{name}}{{/if}}
{{#if description}}abstract: "{{description}}"{{/if}}
{{#if author}}authors:
{{#each author}}
- family-names: {{familyName}}
given-names: {{givenName}}{{#if id}}
orcid: {{id}}{{/if}}{{#if email}}
email: {{email}}{{/if}}
{{/each}}{{/if}}
{{#if maintainer}}contacts:
{{#each maintainer}}
- family-names: {{familyName}}
given-names: {{givenName}}{{#if id}}
orcid: {{id}}{{/if}}{{#if email}}
email: {{email}}{{/if}}
{{/each}}{{/if}}
{{#if codeRepository}}repository-code: "{{codeRepository}}"{{/if}}
{{#if version}}version: {{version}}{{/if}}
{{#if datePublished}}date-released: {{datePublished}}{{/if}}
{{#if identifier}}doi: {{identifier}}{{/if}}
{{#if license}}license-url: "{{license}}"{{/if}}{{#if keywords}}
keywords:
{{#each keywords}}
- {{.}}
{{/each}}{{/if}}
`;
const tsTemplateText = `// {{name}} version and license information.
export const version = '{{version}}',
releaseDate = '{{releaseDate}}',
releaseHash = '{{releaseHash}}'{{#if licenseText}},
licenseText = ` + "`" + `
{{licenseText}}
` + "`{{/if}};";
const pyTemplateText = `# {{name}} version and license information.
export const version = '{{version}}',
releaseDate = '{{releaseDate}}',
releaseHash = '{{releaseHash}}'{{#if licenseText}},
licenseText = '''
{{licenseText}}
'''{{/if}};
`;
const goTemplateText = `package {{name}}
import (
"strings"
)
const (
// Version number of release
Version = "{{version}}"
// ReleaseDate, the date version.go was generated
ReleaseDate = "{{releaseDate}}"
// ReleaseHash, the Git hash when version.go was generated
ReleaseHash = "{{releaseHash}}"
{{#if licenseText}}
LicenseText = ` + "`" + `
{{licenseText}}
` + "`" + `{{/if}}
)
// FmtHelp lets you process a text block with simple curly brace markup.
func FmtHelp(src string, appName string, version string, releaseDate string, releaseHash string) string {
m := map[string]string {
"{app_name}": appName,
"{version}": version,
"{release_date}": releaseDate,
"{release_hash}": releaseHash,
}
for k, v := range m {
if strings.Contains(src, k) {
src = strings.ReplaceAll(src, k, v)
}
}
return src
}
`;
const mdTemplateText = `---
{{#if name}}title: {{name}}{{/if}}
{{#if description}}abstract: "{{description}}"{{/if}}
{{#if author}}authors:
{{#each author}}
- {{#if name}}name: {{name}}{{else}}family_name: {{familyName}}
given_name: {{givenName}}{{/if}}{{#if id}}
id: {{id}}{{/if}}
{{/each}}{{/if}}
{{#if contributor}}contributor:
{{#each contributor}}
- {{#if name}}name: {{name}}{{else}}family_name: {{familyName}}
given_name: {{givenName}}{{/if}}{{#if id}}
id: {{id}}{{/if}}
{{/each}}{{/if}}
{{#if maintainer}}maintainer:
{{#each maintainer}}
- {{#if name}}name: {{name}}{{else}}family_name: {{familyName}}
given_name: {{givenName}}{{/if}}{{#if id}}
id: {{id}}{{/if}}
{{/each}}{{/if}}
{{#if codeRepository}}repository_code: {{codeRepository}}{{/if}}
{{#if version}}version: {{version}}{{/if}}
{{#if license}}license_url: {{license}}{{/if}}
{{#if operatingSystem}}operating_system:
{{#each operatingSystem}}
- {{.}}
{{/each}}{{/if}}
{{#if programmingLanguage}}programming_language:
{{#each programmingLanguage}}
- {{.}}
{{/each}}{{/if}}
{{#if keywords}}keywords:
{{#each keywords}}
- {{.}}
{{/each}}{{/if}}
{{#if datePublished}}date_released: {{datePublished}}{{/if}}
---
About this software
===================
## {{name}} {{version}}
{{#if releaseNotes}}{{releaseNotes}}{{/if}}
{{#if author}}
### Authors
{{#each author}}
- {{#if name}}{{ name }}{{else}}{{givenName}} {{familyName}}{{/if}}{{#if id}}, <{{id}}>{{/if}}{{/each}}{{/if}}
{{#if contributor}}
### Contributors
{{#each contributor}}
- {{#if name}}{{ name }}{{else}}{{givenName}} {{familyName}}{{/if}}{{#if id}}, <{{id}}>{{/if}}{{/each}}{{/if}}
{{#if maintainer}}
### Maintainers
{{#each maintainer}}
- {{#if name}}{{ name }}{{else}}{{givenName}} {{familyName}}{{/if}}{{#if id}}, <{{id}}>{{/if}}{{/each}}{{/if}}
{{#if description}}{{description}}{{/if}}
{{#if license}}- License: <{{license}}>{{/if}}
{{#if codeRepository}}- GitHub: <{{codeRepository}}>{{/if}}
{{#if issueTracker}}- Issues: <{{issueTracker}}>{{/if}}
{{#if programmingLanguage}}
### Programming languages
{{#each programmingLanguage}}
- {{.}}
{{/each}}{{/if}}
{{#if operatingSystem}}
### Operating Systems
{{#each operatingSystem}}
- {{.}}
{{/each}}{{/if}}
{{#if softwareRequirements}}
### Software Requirements
{{#each softwareRequirements}}
- {{.}}
{{/each}}{{/if}}
`;
const hbsTemplateText = `<!DOCTYPE html>
<html lang="en-US">
<head>
<title>{{project_name}}</title>
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="index.html">README</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="user_manual.html">User Manual</a></li>
<li><a href="about.html">About</a></li>
<li><a href="search.html">Search</a></li>
{{#if repositoryLink}} <li><a href="{{repositoryLink}}">GitHub</a></li>{{/if}}
</ul>
</nav>
<section>
$$content$$
</section>
</body>
</html>`;
const shInstallerText = `#!/bin/sh
#
# Set the package name and version to install
#
PACKAGE="{{name}}"
VERSION="{{version}}"
GIT_GROUP="{{git_org_or_person}}"
RELEASE="https://github.com/$$GIT_GROUP/$$PACKAGE/releases/tag/v$$VERSION"
if [ "$$PKG_VERSION" != "" ]; then
VERSION="$$\{PKG_VERSION\}"
echo "$$\{PKG_VERSION} used for version v$$\{VERSION\}"
fi
#
# Get the name of this script.
#
INSTALLER="$$(basename "$$0")"
#
# Figure out what the zip file is named
#
OS_NAME="$$(uname)"
MACHINE="$$(uname -m)"
case "$$OS_NAME" in
Darwin)
OS_NAME="macOS"
;;
GNU/Linux)
OS_NAME="Linux"
;;
esac
if [ "$$1" != "" ]; then
VERSION="$$1"
echo "Version set to v$$\{VERSION\}"
fi
ZIPFILE="$$PACKAGE-v$$VERSION-$$OS_NAME-$$MACHINE.zip"
#
# Check to see if this zip file has been downloaded.
#
DOWNLOAD_URL="https://github.com/$$GIT_GROUP/$$PACKAGE/releases/download/v$$VERSION/$$ZIPFILE"
if ! curl -L -o "$$HOME/Downloads/$$ZIPFILE" "$$DOWNLOAD_URL"; then
echo "Curl failed to get $$DOWNLOAD_URL"
fi
cat<<EOT
Retrieved $$DOWNLOAD_URL
Saved as $$HOME/Downloads/$$ZIPFILE
EOT
if [ ! -d "$$HOME/Downloads" ]; then
mkdir -p "$$HOME/Downloads"
fi
if [ ! -f "$$HOME/Downloads/$$ZIPFILE" ]; then
cat<<EOT
To install $$PACKAGE you need to download
$$ZIPFILE
from
$$RELEASE
You can do that with your web browser. After
that you should be able to re-run $$INSTALLER
EOT
exit 1
fi
START="$$(pwd)"
mkdir -p "$$HOME/.$$PACKAGE/installer"
cd "$$HOME/.$$PACKAGE/installer" || exit 1
unzip "$$HOME/Downloads/$$ZIPFILE" "bin/*" "man/*"
#
# Copy the application into place
#
mkdir -p "$$HOME/bin"
EXPLAIN_OS_POLICY="yes"
find bin -type f >.binfiles.tmp
while read -r APP; do
V=$$("./$$APP" --version)
if [ "$$V" = "" ]; then
EXPLAIN_OS_POLICY="yes"
fi
mv "$$APP" "$$HOME/bin/"
done <.binfiles.tmp
rm .binfiles.tmp
#
# Make sure $$HOME/bin is in the path
#
case :$$PATH: in
*:$$HOME/bin:*)
;;
*)
# shellcheck disable=SC2016
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.bashrc"
# shellcheck disable=SC2016
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.zshrc"
;;
esac
# shellcheck disable=SC2031
if [ "$$EXPLAIN_OS_POLICY" = "no" ]; then
cat <<EOT
You need to take additional steps to complete installation.
Your operating system security policied needs to "allow"
running programs from $$PACKAGE.
Example: on macOS you can type open the programs in finder.
open $$HOME/bin
Find the program(s) and right click on the program(s)
installed to enable them to run.
EOT
fi
#
# Copy the manual pages into place
#
EXPLAIN_MAN_PATH="no"
for SECTION in 1 2 3 4 5 6 7; do
if [ -d "man/man$$\{SECTION\}" ]; then
EXPLAIN_MAN_PATH="yes"
mkdir -p "$$HOME/man/man$$\{SECTION\}"
find "man/man$$\{SECTION\}" -type f | while read -r MAN; do
cp -v "$$MAN" "$$HOME/man/man$$\{SECTION\}/"
done
fi
done
if [ "$$EXPLAIN_MAN_PATH" = "yes" ]; then
cat <<EOT
The man pages have been installed at '$$HOME/man'. You
need to have that location in your MANPATH for man to
find the pages. E.g. For the Bash shell add the
following to your following to your '$$HOME/.bashrc' file.
export MANPATH="$$HOME/man:$$MANPATH"
EOT
fi
rm -fR "$$HOME/.$$PACKAGE/installer"
cd "$$START" || exit 1
`;
const ps1InstallerText = `#!/usr/bin/env pwsh
# Generated with codemeta-ps1-installer.tmpl, see https://github.com/caltechlibrary/codemeta-pandoc-examples
#
# Set the package name and version to install
#
param(
[Parameter()]
[String]$$VERSION = "$version$"
)
[String]$$PKG_VERSION = [Environment]::GetEnvironmentVariable("PKG_VERSION")
if ($$PKG_VERSION) {
$$VERSION = "$$\{PKG_VERSION\}"
Write-Output "Using '$$\{PKG_VERSION\}' for version value '$$\{VERSION\}'"
}
$$PACKAGE = "{{name}}"
$$GIT_GROUP = "{{git_org_or_person}}"
$$RELEASE = "https://github.com/$$\{GIT_GROUP\}/$$\{PACKAGE\}/releases/tag/v$$\{VERSION\}"
$$SYSTEM_TYPE = Get-ComputerInfo -Property CsSystemType
if ($$SYSTEM_TYPE.CsSystemType.Contains("ARM64")) {
$$MACHINE = "arm64"
} else {
$$MACHINE = "x86_64"
}
# FIGURE OUT Install directory
$$BIN_DIR = "$$\{Home\}\\bin"
Write-Output "$$\{PACKAGE\} v$$\{VERSION\} will be installed in $$\{BIN_DIR\}"
#
# Figure out what the zip file is named
#
$$ZIPFILE = "$$\{PACKAGE\}-v$$\{VERSION\}-Windows-$$\{MACHINE\}.zip"
Write-Output "Fetching Zipfile $$\{ZIPFILE\}"
#
# Check to see if this zip file has been downloaded.
#
$$DOWNLOAD_URL = "https://github.com/$$\{GIT_GROUP\}/$$\{PACKAGE\}/releases/download/v$$\{VERSION\}/$$\{ZIPFILE\}"
Write-Output "Download URL $$\{DOWNLOAD_URL\}"
if (!(Test-Path $$BIN_DIR)) {
New-Item $$BIN_DIR -ItemType Directory | Out-Null
}
curl.exe -Lo "$$\{ZIPFILE\}" "$$\{DOWNLOAD_URL\}"
#if ([System.IO.File]::Exists($$ZIPFILE)) {
if (!(Test-Path $$ZIPFILE)) {
Write-Output "Failed to download $$\{ZIPFILE\} from $$\{DOWNLOAD_URL\}"
} else {
tar.exe xf "$$\{ZIPFILE\}" -C "$$\{Home\}"
#Remove-Item $$ZIPFILE
$$User = [System.EnvironmentVariableTarget]::User
$$Path = [System.Environment]::GetEnvironmentVariable('Path', $$User)
if (!(";$$\{Path\};".ToLower() -like "*;$$\{BIN_DIR\};*".ToLower())) {
[System.Environment]::SetEnvironmentVariable('Path', "$$\{Path\};$$\{BIN_DIR\}", $$User)
$$Env:Path += ";$$\{BIN_DIR\}"
}
Write-Output "$$\{PACKAGE\} was installed successfully to $$\{BIN_DIR\}"
}
`;
const readmeMdText = `
# {{name}} {{version}}
{{{description}}}
{{#if releaseNotes}}
## Release Notes
- version: {{version}}
{{#if developmentStatus}}- status: {{developmentStatus}}{{/if}}
{{#if datePublished}}- released: {{datePublished}}{{/if}}
{{releaseNotes}}
{{/if}}
{{#if author}}
### Authors
{{#each author}}
- {{#if familyName}}{{familyName}}, {{givenName}}{{else}}{{name}}{{/if}}
{{/each}}
{{/if}}
{{#if contributor}}
### Contributors
{{#each contributor}}
- {{#if familyName}}{{familyName}}, {{givenName}}{{else}}{{name}}{{/if}}
{{/each}}
{{/if}}
{{#if maintainer}}
### Maintainers
{{#each maintainer}}
- {{#if familyName}}{{familyName}}, {{givenName}}{{else}}{{name}}{{/if}}
{{/each}}
{{/if}}
{{#if softwareRequirements}}
## Software Requirements
{{#each softwareRequirements}}
- {{.}}
{{/each}}
{{/if}}
{{#if runtimePlatform}}Uses: {{runtimePlatform}}{{/if}}
## Related resources
{{#if installUrl}}-[Install]({{installUrl}}){{/if}}
{{#if downloadUrl}}- [Download]({{downloadUrl}}){{/if}}
{{#if issueTracker}}- [Getting Help, Reporting bugs]({{issueTracker}}){{/if}}
{{#if license}}- [LICENSE]({{license}}){{/if}}
- [Installation](INSTALL.md)
- [About](about.md)
`;
const installMdText = `Installation for development of **{{name}}**
===========================================
**{{name}}** {{description}}
Quick install with curl or irm
------------------------------
There is an experimental installer.sh script that can be run with the following command to install latest table release. This may work for macOS, Linux and if you’re using Windows with the Unix subsystem. This would be run from your shell (e.g. Terminal on macOS).
~~~shell
curl https://{{git_org_or_person}}.github.io/{{name}}/installer.sh | sh
~~~
This will install the programs included in {{name}} in your `+"`$HOME/bin`"+` directory.
If you are running Windows 10 or 11 use the Powershell command below.
~~~ps1
irm https://{{git_org_or_person}}.github.io/{{mame}}/installer.ps1 | iex
~~~
Installing from source
----------------------
### Required software
{{#each softwareRequirements}}
- {{.}}
{{/each}}
### Steps
1. git clone https://github.com/{{git_org_or_person}}/{{name}}
2. Change directory into the `+"`"+`{{name}}`+"`"+` directory
3. Make to build, test and install
~~~shell
git clone https://github.com/{{git_org_or_person}}/{{name}}
cd {{name}}
make
make test
make install
~~~
`;
export const denoMakefileText = `#
# Simple Makefile for Deno based Projects built under POSIX.
#
PROJECT = {{name}}
PACKAGE = {{name}}
PROGRAMS = <PROGRAM_LIST_GOES_HERE>
GIT_GROUP = {{git_org_or_person}}
VERSION = $(shell grep '"version":' codemeta.json | cut -d\" -f 4)
BRANCH = $(shell git branch | grep '* ' | cut -d\ -f 2)
PACKAGE = $(shell ls -1 *.ts | grep -v 'version.ts')
MAN_PAGES_1 = $(shell ls -1 *.1.md | sed -E 's/\.1.md/.1/g')
MAN_PAGES_3 = $(shell ls -1 *.3.md | sed -E 's/\.3.md/.3/g')
MAN_PAGES_7 = $(shell ls -1 *.7.md | sed -E 's/\.7.md/.7/g')
RELEASE_DATE=$(shell date +'%Y-%m-%d')
RELEASE_HASH=$(shell git log --pretty=format:%h -n 1)
HTML_PAGES = $(shell ls -1 *.html) # $(shell ls -1 *.md | grep -v 'nav.md' | sed -E 's/.md/.html/g')
DOCS = $(shell ls -1 *.?.md)
OS = $(shell uname)
EXT =
ifeq ($(OS), Windows)
EXT = .exe
endif
PREFIX = $(HOME)
build: version.ts CITATION.cff about.md bin compile installer.sh installer.ps1
bin: .FORCE
mkdir -p bin
compile: .FORCE
deno task build
check: .FORCE
deno task check
version.ts: codemeta.json
deno task version.ts
format: $(shell ls -1 *.ts | grep -v version.ts | grep -v deps.ts)
$(shell ls -1 *.ts | grep -v version.ts): .FORCE
deno fmt $@
man: $(MAN_PAGES_1) # $(MAN_PAGES_3) $(MAN_PAGES_7)
$(MAN_PAGES_1): .FORCE
mkdir -p man/man1
pandoc [email protected] --from markdown --to man -s >man/man1/$@
CITATION.cff: codemeta.json
deno task CITATION.cff
about.md: codemeta.json
deno task about.md
status:
git status
save:
if [ "$(msg)" != "" ]; then git commit -am "$(msg)"; else git commit -am "Quick Save"; fi
git push origin $(BRANCH)
website: $(HTML_PAGES) .FORCE
make -f website.mak
#publish: website .FORCE
# ./publish.bash
htdocs: .FORCE
deno task htdocs
deno task transpile
test: .FORCE
deno task test
deno task editor_test.ts
install: build
@echo "Installing programs in $(PREFIX)/bin"
@for FNAME in $(PROGRAMS); do if [ -f "./bin/$\${FNAME}$(EXT)" ]; then mv -v "./bin/$\${FNAME}$(EXT)" "$(PREFIX)/bin/$\${FNAME}$(EXT)"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/bin is in your PATH"
@echo "Installing man page in $(PREFIX)/man"
@mkdir -p $(PREFIX)/man/man1
@for FNAME in $(MAN_PAGES_1); do if [ -f "./man/man1/$\${FNAME}" ]; then cp -v "./man/man1/$\${FNAME}" "$(PREFIX)/man/man1/$\${FNAME}"; fi; done
@mkdir -p $(PREFIX)/man/man3
@for FNAME in $(MAN_PAGES_3); do if [ -f "./man/man3/$\${FNAME}" ]; then cp -v "./man/man3/$\${FNAME}" "$(PREFIX)/man/man3/$\${FNAME}"; fi; done
@mkdir -p $(PREFIX)/man/man7
@for FNAME in $(MAN_PAGES_7); do if [ -f "./man/man7/$\${FNAME}" ]; then cp -v "./man/man7/$\${FNAME}" "$(PREFIX)/man/man7/$\${FNAME}"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/man is in your MANPATH"
uninstall: .FORCE
@echo "Removing programs in $(PREFIX)/bin"
@for FNAME in $(PROGRAMS); do if [ -f "$(PREFIX)/bin/$\${FNAME}$(EXT)" ]; then rm -v "$(PREFIX)/bin/$\${FNAME}$(EXT)"; fi; done
@echo "Removing man pages in $(PREFIX)/man"
@for FNAME in $(MAN_PAGES_1); do if [ -f "$(PREFIX)/man/man1/$\${FNAME}" ]; then rm -v "$(PREFIX)/man/man1/$\${FNAME}"; fi; done
@for FNAME in $(MAN_PAGES_3); do if [ -f "$(PREFIX)/man/man3/$\${FNAME}" ]; then rm -v "$(PREFIX)/man/man3/$\${FNAME}"; fi; done
@for FNAME in $(MAN_PAGES_7); do if [ -f "$(PREFIX)/man/man7/$\${FNAME}" ]; then rm -v "$(PREFIX)/man/man7/$\${FNAME}"; fi; done
installer.sh: .FORCE
cmt codemeta.json installer.sh
chmod 775 installer.sh
git add -f installer.sh
installer.ps1: .FORCE
cmt codemeta.json installer.ps1
chmod 775 installer.ps1
git add -f installer.ps1
clean:
if [ -d bin ]; then rm -fR bin/*; fi
if [ -d dist ]; then rm -fR dist/*; fi
release: clean build man website distribute_docs dist/Linux-x86_64 dist/Linux-aarch64 dist/macOS-x86_64 dist/macOS-arm64 dist/Windows-x86_64 dist/Windows-arm64
echo "Ready to do ./release.bash"
setup_dist: .FORCE
@rm -fR dist
@mkdir -p dist
distribute_docs: website man setup_dist
@cp README.md dist/
@cp LICENSE dist/
@cp codemeta.json dist/
@cp CITATION.cff dist/
@cp INSTALL.md dist/
@cp -vR man dist/
@for DNAME in $(DOCS); do cp -vR $$DNAME dist/; done
dist/Linux-x86_64: .FORCE
@mkdir -p dist/bin
deno task dist_linux_x86_64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Linux-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
dist/Linux-aarch64: .FORCE
@mkdir -p dist/bin
deno task dist_linux_aarch64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Linux-aarch64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
dist/macOS-x86_64: .FORCE
@mkdir -p dist/bin
deno task dist_macos_x86_64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-macOS-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
dist/macOS-arm64: .FORCE
@mkdir -p dist/bin
deno task dist_macos_aarch64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-macOS-arm64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
dist/Windows-x86_64: .FORCE
@mkdir -p dist/bin
deno task dist_windows_x86_64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Windows-x86_64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
dist/Windows-arm64: .FORCE
@mkdir -p dist/bin
#deno task dist_windows_aarch64 <-- switch to native when Rust/Deno supports Windows ARM64
deno task dist_windows_x86_64
@cd dist && zip -r $(PROJECT)-v$(VERSION)-Windows-arm64.zip LICENSE codemeta.json CITATION.cff *.md bin/*
@rm -fR dist/bin
.FORCE:
`;
export const goMakefileText = `#
# Simple Makefile for Golang based Projects built under POSIX.
#
PROJECT = {{name}}
GIT_GROUP = {{git_org_or_person}}
PROGRAMS = <PROGRAM_LISTS_GOES_HERE>
RELEASE_DATE = $(shell date +%Y-%m-%d)
RELEASE_HASH=$(shell git log --pretty=format:'%h' -n 1)
MAN_PAGES_1 = $(shell ls -1 *.1.md | sed -E 's/\.1.md/.1/g')
MAN_PAGES_3 = $(shell ls -1 *.3.md | sed -E 's/\.3.md/.3/g')
MAN_PAGES_7 = $(shell ls -1 *.7.md | sed -E 's/\.7.md/.7/g')
HTML_PAGES = $(shell find . -type f | grep -E '\.html$')
DOCS = $(shell ls -1 *.?.md)
PACKAGE = $(shell ls -1 *.go)
VERSION = $(shell grep '"version":' codemeta.json | cut -d\" -f 4)
BRANCH = $(shell git branch | grep '* ' | cut -d\ -f 2)
OS = $(shell uname)
#PREFIX = /usr/local/bin
PREFIX = $(HOME)
ifneq ($(prefix),)
PREFIX = $(prefix)
endif
EXT =
ifeq ($(OS), Windows)
EXT = .exe
endif
build: version.go $(PROGRAMS) man CITATION.cff about.md installer.sh installer.ps1
version.go: .FORCE
cmt codemeta.json version.go
hash: .FORCE
git log --pretty=format:'%h' -n 1
man: $(MAN_PAGES_1) # $(MAN_PAGES_3) $(MAN_PAGES_7)
$(MAN_PAGES_1): .FORCE
mkdir -p man/man1
pandoc [email protected] --from markdown --to man -s >man/man1/$@
$(MAN_PAGES_3): .FORCE
mkdir -p man/man3
pandoc [email protected] --from markdown --to man -s >man/man3/$@
$(MAN_PAGES_7): .FORCE
mkdir -p man/man7
pandoc [email protected] --from markdown --to man -s >man/man7/$@
$(PROGRAMS): $(PACKAGE)
@mkdir -p bin
go build -o "bin/$@$(EXT)" cmd/$@/*.go
@./bin/$@ -help >[email protected]
$(MAN_PAGES): .FORCE
mkdir -p man/man1
pandoc [email protected] --from markdown --to man -s >man/man1/$@
CITATION.cff: codemeta.json
cmt codemeta.json CITATION.cff
about.md: codemeta.json $(PROGRAMS)
cmt codemeta.json about.md
installer.sh: .FORCE
cmt codemeta.json installer.sh
installer.ps1: .FORCE
cmt codemeta.json installer.ps1
test: $(PACKAGE)
go test
website: clean-website .FORCE
make -f website.mak
status:
git status
save:
@if [ "$(msg)" != "" ]; then git commit -am "$(msg)"; else git commit -am "Quick Save"; fi
git push origin $(BRANCH)
refresh:
git fetch origin
git pull origin $(BRANCH)
#publish: build website .FORCE
# ./publish.bash
clean:
@if [ -f version.go ]; then rm version.go; fi
@if [ -d bin ]; then rm -fR bin; fi
@if [ -d dist ]; then rm -fR dist; fi
@if [ -d man ]; then rm -fR man; fi
@if [ -d testout ]; then rm -fR testout; fi
clean-website:
@for FNAME in $(HTML_PAGES); do if [ -f "$\${FNAME}" ]; then rm "$\${FNAME}"; fi; done
install: build
@echo "Installing programs in $(PREFIX)/bin"
@for FNAME in $(PROGRAMS); do if [ -f "./bin/$\${FNAME}$(EXT)" ]; then mv -v "./bin/$\${FNAME}$(EXT)" "$(PREFIX)/bin/$\${FNAME}$(EXT)"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/bin is in your PATH"
@echo "Installing man page in $(PREFIX)/man"
@mkdir -p $(PREFIX)/man/man1
@for FNAME in $(MAN_PAGES_1); do if [ -f "./man/man1/$\${FNAME}" ]; then cp -v "./man/man1/$\${FNAME}" "$(PREFIX)/man/man1/$\${FNAME}"; fi; done
@mkdir -p $(PREFIX)/man/man3
@for FNAME in $(MAN_PAGES_3); do if [ -f "./man/man3/$\${FNAME}" ]; then cp -v "./man/man3/$\${FNAME}" "$(PREFIX)/man/man3/$\${FNAME}"; fi; done
@mkdir -p $(PREFIX)/man/man7
@for FNAME in $(MAN_PAGES_7); do if [ -f "./man/man7/$\${FNAME}" ]; then cp -v "./man/man7/$\${FNAME}" "$(PREFIX)/man/man7/$\${FNAME}"; fi; done
@echo ""
@echo "Make sure $(PREFIX)/man is in your MANPATH"