|
1 | | -function [] = init(year,full_name,args) |
| 1 | +function [] = init(year,first_name,last_name,project_title,args) |
2 | 2 | % Main initialization script |
3 | 3 | % |
4 | 4 | % BSD 3-Clause License |
|
31 | 31 | % OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | 32 | arguments |
33 | 33 | year (1,1) int32 |
34 | | - full_name char |
| 34 | + first_name char |
| 35 | + last_name char |
| 36 | + project_title char |
35 | 37 | args.self_delete (1,1) logical = true; |
36 | 38 | args.reset_test (1,1) logical = true; |
37 | 39 | end |
|
46 | 48 | delete_file('version.txt'); |
47 | 49 |
|
48 | 50 | reset_file('README.md', ... |
49 | | -"# README\n\n" + ... |
| 51 | +"# " + project_title + "\n\n" + ... |
50 | 52 | "\n\n"+... |
51 | 53 | "## Source Template Repository\n\n"+... |
52 | 54 | "Generated from matlab-repo-init\n\n"+... |
|
71 | 73 | 'ignoreWords',[]); |
72 | 74 | reset_file('.cspell.json',jsonencode(cspell_default,PrettyPrint=true)+"\n"); |
73 | 75 |
|
74 | | -rmdir('.vscode','s'); |
75 | | -rmdir('.github/actions','s'); |
| 76 | +rmdir('.vscode','s'); % TODO keep cff schema in settings |
| 77 | +rmdir('.github/actions','s'); % TODO add printed notification |
76 | 78 |
|
77 | 79 | % Set license details |
| 80 | +full_name = [first_name, ' ', last_name]; |
78 | 81 | set_license('LICENSE',year,full_name); |
79 | 82 |
|
| 83 | +% CITATION.cff |
| 84 | +reset_cff(first_name,last_name,project_title); |
| 85 | + |
80 | 86 | if ~args.self_delete |
81 | 87 | return; |
82 | 88 | end |
@@ -108,24 +114,41 @@ function reset_file(name,lines) |
108 | 114 | function set_license(file_name,year,full_name) |
109 | 115 | full_file = fullfile(pwd, file_name); |
110 | 116 |
|
111 | | -[fid, err_msg] = fopen(full_file,'r'); |
112 | | -if fid == -1 |
113 | | - error(['Could not open ', name,' for reading: ',err_msg]); |
114 | | -end |
115 | | -license_text=fread(fid,'*char')'; |
116 | | -fclose(fid); |
| 117 | +license_text=read_to_char(file_name); |
117 | 118 |
|
118 | 119 | upd_license_text = regexprep(license_text,'Copyright \(c\) (.*?)\n', ... |
119 | 120 | ['Copyright (c) ',num2str(year),', ', full_name,'\n']); |
120 | 121 |
|
121 | 122 | [fid, err_msg] = fopen(full_file,'w'); |
122 | 123 | if fid == -1 |
123 | | - error(['Could not open ', name,' for writing: ',err_msg]); |
| 124 | + error(['Could not open ', file_name,' for writing: ',err_msg]); |
124 | 125 | end |
125 | 126 | fprintf(fid,'%s',upd_license_text); |
126 | 127 | fclose(fid); |
127 | 128 | end |
128 | 129 |
|
| 130 | +function reset_cff(first_name,last_name,project_title) |
| 131 | +cff_template = read_to_char('CITATION.cff.template'); |
| 132 | +delete_file('CITATION.cff.template'); |
| 133 | + |
| 134 | +reset_file('CITATION.cff', cff_template + ... |
| 135 | +"title: """ + project_title + """\n" + ... |
| 136 | +"authors:\n" + ... |
| 137 | +" - family-names: " + last_name + "\n" + ... |
| 138 | +" given-names: " + first_name + "\n"... |
| 139 | +); |
| 140 | +end |
| 141 | + |
| 142 | +function read_char = read_to_char(file_name) |
| 143 | +full_file = fullfile(pwd, file_name); |
| 144 | +[fid, err_msg] = fopen(full_file,'r'); |
| 145 | +if fid == -1 |
| 146 | + error(['Could not open ', file_name,' for reading: ',err_msg]); |
| 147 | +end |
| 148 | +read_char = fread(fid,'*char')'; |
| 149 | +fclose(fid); |
| 150 | +end |
| 151 | + |
129 | 152 | function print_info() |
130 | 153 | [fid, ~] = fopen('version.txt','r'); |
131 | 154 | version_str=fread(fid,'*char')'; |
|
0 commit comments