@joshua-dev/create-ts 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,374 @@
1
+ HIPPOCRATIC LICENSE
2
+
3
+ Version 3.0, October 2021
4
+
5
+ https://firstdonoharm.dev/version/3/0/eco-extr-ffd-sv-usta.txt
6
+
7
+ TERMS AND CONDITIONS
8
+
9
+ TERMS AND CONDITIONS FOR USE, COPY, MODIFICATION, PREPARATION OF DERIVATIVE
10
+ WORK, REPRODUCTION, AND DISTRIBUTION:
11
+
12
+ 1. DEFINITIONS:
13
+
14
+ This section defines certain terms used throughout this license agreement.
15
+
16
+ 1.1. “License” means the terms and conditions, as stated herein, for use, copy,
17
+ modification, preparation of derivative work, reproduction, and distribution of
18
+ Software (as defined below).
19
+
20
+ 1.2. “Licensor” means the copyright and/or patent owner or entity authorized by
21
+ the copyright and/or patent owner that is granting the License.
22
+
23
+ 1.3. “Licensee” means the individual or entity exercising permissions granted by
24
+ this License, including the use, copy, modification, preparation of derivative
25
+ work, reproduction, and distribution of Software (as defined below).
26
+
27
+ 1.4. “Software” means any copyrighted work, including but not limited to
28
+ software code, authored by Licensor and made available under this License.
29
+
30
+ 1.5. “Supply Chain” means the sequence of processes involved in the production
31
+ and/or distribution of a commodity, good, or service offered by the Licensee.
32
+
33
+ 1.6. “Supply Chain Impacted Party” or “Supply Chain Impacted Parties” means any
34
+ person(s) directly impacted by any of Licensee’s Supply Chain, including the
35
+ practices of all persons or entities within the Supply Chain prior to a good or
36
+ service reaching the Licensee.
37
+
38
+ 1.7. “Duty of Care” is defined by its use in tort law, delict law, and/or
39
+ similar bodies of law closely related to tort and/or delict law, including
40
+ without limitation, a requirement to act with the watchfulness, attention,
41
+ caution, and prudence that a reasonable person in the same or similar
42
+ circumstances would use towards any Supply Chain Impacted Party.
43
+
44
+ 1.8. “Worker” is defined to include any and all permanent, temporary, and agency
45
+ workers, as well as piece-rate, salaried, hourly paid, legal young (minors),
46
+ part-time, night, and migrant workers.
47
+
48
+ 2. INTELLECTUAL PROPERTY GRANTS:
49
+
50
+ This section identifies intellectual property rights granted to a Licensee.
51
+
52
+ 2.1. Grant of Copyright License: Subject to the terms and conditions of this
53
+ License, Licensor hereby grants to Licensee a worldwide, non-exclusive,
54
+ no-charge, royalty-free copyright license to use, copy, modify, prepare
55
+ derivative work, reproduce, or distribute the Software, Licensor authored
56
+ modified software, or other work derived from the Software.
57
+
58
+ 2.2. Grant of Patent License: Subject to the terms and conditions of this
59
+ License, Licensor hereby grants Licensee a worldwide, non-exclusive, no-charge,
60
+ royalty-free patent license to make, have made, use, offer to sell, sell,
61
+ import, and otherwise transfer Software.
62
+
63
+ 3. ETHICAL STANDARDS:
64
+
65
+ This section lists conditions the Licensee must comply with in order to have
66
+ rights under this License.
67
+
68
+ The rights granted to the Licensee by this License are expressly made subject to
69
+ the Licensee’s ongoing compliance with the following conditions:
70
+
71
+ - 3.1. The Licensee SHALL NOT, whether directly or indirectly, through agents
72
+ or assigns:
73
+ - 3.1.1. Infringe upon any person’s right to life or security of person,
74
+ engage in extrajudicial killings, or commit murder, without lawful cause
75
+ (See Article 3, United Nations Universal Declaration of Human Rights;
76
+ Article 6, International Covenant on Civil and Political Rights)
77
+
78
+ - 3.1.2. Hold any person in slavery, servitude, or forced labor (See Article
79
+ 4, United Nations Universal Declaration of Human Rights; Article 8,
80
+ International Covenant on Civil and Political Rights);
81
+
82
+ - 3.1.3. Contribute to the institution of slavery, slave trading, forced
83
+ labor, or unlawful child labor (See Article 4, United Nations Universal
84
+ Declaration of Human Rights; Article 8, International Covenant on Civil and
85
+ Political Rights);
86
+
87
+ - 3.1.4. Torture or subject any person to cruel, inhumane, or degrading
88
+ treatment or punishment (See Article 5, United Nations Universal
89
+ Declaration of Human Rights; Article 7, International Covenant on Civil and
90
+ Political Rights);
91
+
92
+ - 3.1.5. Discriminate on the basis of sex, gender, sexual orientation, race,
93
+ ethnicity, nationality, religion, caste, age, medical disability or
94
+ impairment, and/or any other like circumstances (See Article 7, United
95
+ Nations Universal Declaration of Human Rights; Article 2, International
96
+ Covenant on Economic, Social and Cultural Rights; Article 26, International
97
+ Covenant on Civil and Political Rights);
98
+
99
+ - 3.1.6. Prevent any person from exercising his/her/their right to seek an
100
+ effective remedy by a competent court or national tribunal (including
101
+ domestic judicial systems, international courts, arbitration bodies, and
102
+ other adjudicating bodies) for actions violating the fundamental rights
103
+ granted to him/her/them by applicable constitutions, applicable laws, or by
104
+ this License (See Article 8, United Nations Universal Declaration of Human
105
+ Rights; Articles 9 and 14, International Covenant on Civil and Political
106
+ Rights);
107
+
108
+ - 3.1.7. Subject any person to arbitrary arrest, detention, or exile (See
109
+ Article 9, United Nations Universal Declaration of Human Rights; Article 9,
110
+ International Covenant on Civil and Political Rights);
111
+
112
+ - 3.1.8. Subject any person to arbitrary interference with a person’s
113
+ privacy, family, home, or correspondence without the express written
114
+ consent of the person (See Article 12, United Nations Universal Declaration
115
+ of Human Rights; Article 17, International Covenant on Civil and Political
116
+ Rights);
117
+
118
+ - 3.1.9. Arbitrarily deprive any person of his/her/their property (See
119
+ Article 17, United Nations Universal Declaration of Human Rights);
120
+
121
+ - 3.1.10. Forcibly remove indigenous peoples from their lands or territories
122
+ or take any action with the aim or effect of dispossessing indigenous
123
+ peoples from their lands, territories, or resources, including without
124
+ limitation the intellectual property or traditional knowledge of indigenous
125
+ peoples, without the free, prior, and informed consent of indigenous
126
+ peoples concerned (See Articles 8 and 10, United Nations Declaration on the
127
+ Rights of Indigenous Peoples);
128
+
129
+ - 3.1.11. Fossil Fuel Divestment: Be an individual or entity, or a
130
+ representative, agent, affiliate, successor, attorney, or assign of an
131
+ individual or entity, on the FFI Solutions Carbon Underground 200 list
132
+ [https://www.ffisolutions.com/research-analytics-index-solutions/research-screening/the-carbon-underground-200/?cn-reloaded=1];
133
+
134
+ - 3.1.12. Ecocide: Commit ecocide:
135
+ - 3.1.12.1. For the purpose of this section, “ecocide” means unlawful or
136
+ wanton acts committed with knowledge that there is a substantial
137
+ likelihood of severe and either widespread or long-term damage to the
138
+ environment being caused by those acts;
139
+
140
+ - 3.1.12.2. For the purpose of further defining ecocide and the terms
141
+ contained in the previous paragraph:
142
+ - 3.1.12.2.1. “Wanton” means with reckless disregard for damage which
143
+ would be clearly excessive in relation to the social and economic
144
+ benefits anticipated;
145
+
146
+ - 3.1.12.2.2. “Severe” means damage which involves very serious adverse
147
+ changes, disruption, or harm to any element of the environment,
148
+ including grave impacts on human life or natural, cultural, or
149
+ economic resources;
150
+
151
+ - 3.1.12.2.3. “Widespread” means damage which extends beyond a limited
152
+ geographic area, crosses state boundaries, or is suffered by an entire
153
+ ecosystem or species or a large number of human beings;
154
+
155
+ - 3.1.12.2.4. “Long-term” means damage which is irreversible or which
156
+ cannot be redressed through natural recovery within a reasonable
157
+ period of time; and
158
+
159
+ - 3.1.12.2.5. “Environment” means the earth, its biosphere, cryosphere,
160
+ lithosphere, hydrosphere, and atmosphere, as well as outer space
161
+
162
+ (See Section II, Independent Expert Panel for the Legal Definition of
163
+ Ecocide, Stop Ecocide Foundation and the Promise Institute for Human
164
+ Rights at UCLA School of Law, June 2021);
165
+
166
+ - 3.1.13. Extractive Industries: Be an individual or entity, or a
167
+ representative, agent, affiliate, successor, attorney, or assign of an
168
+ individual or entity, that engages in fossil fuel or mineral exploration,
169
+ extraction, development, or sale;
170
+
171
+ - 3.1.14. US Tariff Act: Be an individual or entity:
172
+ - 3.1.14.1. which U.S. Customs and Border Protection (CBP) has currently
173
+ issued a Withhold Release Order (WRO) or finding against based on
174
+ reasonable suspicion of forced labor; or
175
+
176
+ - 3.1.14.2. that is a representative, agent, affiliate, successor,
177
+ attorney, or assign of an individual or entity that does business with
178
+ an individual or entity which currently has a WRO or finding from CBP
179
+ issued against it based on reasonable suspicion of forced labor;
180
+
181
+ - 3.1.15. Mass Surveillance: Be a government agency or multinational
182
+ corporation, or a representative, agent, affiliate, successor, attorney,
183
+ or assign of a government or multinational corporation, which participates
184
+ in mass surveillance programs;
185
+
186
+ - 3.1.16. Interfere with Workers' free exercise of the right to organize and
187
+ associate (See Article 20, United Nations Universal Declaration of Human
188
+ Rights; C087 - Freedom of Association and Protection of the Right to
189
+ Organise Convention, 1948 (No. 87), International Labour Organization;
190
+ Article 8, International Covenant on Economic, Social and Cultural Rights);
191
+ and
192
+
193
+ - 3.1.17. Harm the environment in a manner inconsistent with local, state,
194
+ national, or international law.
195
+
196
+ - 3.2. The Licensee SHALL:
197
+ - 3.2.1. Provide equal pay for equal work where the performance of such work
198
+ requires equal skill, effort, and responsibility, and which are performed
199
+ under similar working conditions, except where such payment is made
200
+ pursuant to:
201
+ - 3.2.1.1. A seniority system;
202
+
203
+ - 3.2.1.2. A merit system;
204
+
205
+ - 3.2.1.3. A system which measures earnings by quantity or quality of
206
+ production; or
207
+
208
+ - 3.2.1.4. A differential based on any other factor other than sex, gender,
209
+ sexual orientation, race, ethnicity, nationality, religion, caste, age,
210
+ medical disability or impairment, and/or any other like circumstances
211
+ (See 29 U.S.C.A. § 206(d)(1); Article 23, United Nations Universal
212
+ Declaration of Human Rights; Article 7, International Covenant on
213
+ Economic, Social and Cultural Rights; Article 26, International Covenant
214
+ on Civil and Political Rights); and
215
+
216
+ - 3.2.2. Allow for reasonable limitation of working hours and periodic
217
+ holidays with pay (See Article 24, United Nations Universal Declaration of
218
+ Human Rights; Article 7, International Covenant on Economic, Social and
219
+ Cultural Rights).
220
+
221
+ 4. SUPPLY CHAIN IMPACTED PARTIES:
222
+
223
+ This section identifies additional individuals or entities that a Licensee could
224
+ harm as a result of violating the Ethical Standards section, the condition that
225
+ the Licensee must voluntarily accept a Duty of Care for those individuals or
226
+ entities, and the right to a private right of action that those individuals or
227
+ entities possess as a result of violations of the Ethical Standards section.
228
+
229
+ 4.1. In addition to the above Ethical Standards, Licensee voluntarily accepts a
230
+ Duty of Care for Supply Chain Impacted Parties of this License, including
231
+ individuals and communities impacted by violations of the Ethical Standards. The
232
+ Duty of Care is breached when a provision within the Ethical Standards section
233
+ is violated by a Licensee, one of its successors or assigns, or by an individual
234
+ or entity that exists within the Supply Chain prior to a good or service
235
+ reaching the Licensee.
236
+
237
+ 4.2. Breaches of the Duty of Care, as stated within this section, shall create a
238
+ private right of action, allowing any Supply Chain Impacted Party harmed by the
239
+ Licensee to take legal action against the Licensee in accordance with applicable
240
+ negligence laws, whether they be in tort law, delict law, and/or similar bodies
241
+ of law closely related to tort and/or delict law, regardless if Licensee is
242
+ directly responsible for the harms suffered by a Supply Chain Impacted Party.
243
+ Nothing in this section shall be interpreted to include acts committed by
244
+ individuals outside of the scope of his/her/their employment.
245
+
246
+ 5. NOTICE: This section explains when a Licensee must notify others of the
247
+ License.
248
+
249
+ 5.1. Distribution of Notice: Licensee must ensure that everyone who receives a
250
+ copy of or uses any part of Software from Licensee, with or without changes,
251
+ also receives the License and the copyright notice included with Software (and
252
+ if included by the Licensor, patent, trademark, and attribution notice).
253
+ Licensee must ensure that License is prominently displayed so that any
254
+ individual or entity seeking to download, copy, use, or otherwise receive any
255
+ part of Software from Licensee is notified of this License and its terms and
256
+ conditions. Licensee must cause any modified versions of the Software to carry
257
+ prominent notices stating that Licensee changed the Software.
258
+
259
+ 5.2. Modified Software: Licensee is free to create modifications of the Software
260
+ and distribute only the modified portion created by Licensee, however, any
261
+ derivative work stemming from the Software or its code must be distributed
262
+ pursuant to this License, including this Notice provision.
263
+
264
+ 5.3. Recipients as Licensees: Any individual or entity that uses, copies,
265
+ modifies, reproduces, distributes, or prepares derivative work based upon the
266
+ Software, all or part of the Software’s code, or a derivative work developed by
267
+ using the Software, including a portion of its code, is a Licensee as defined
268
+ above and is subject to the terms and conditions of this License.
269
+
270
+ 6. REPRESENTATIONS AND WARRANTIES:
271
+
272
+ 6.1. Disclaimer of Warranty: TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE
273
+ COMES “AS IS,” WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR SHALL NOT
274
+ BE LIABLE TO ANY PERSON OR ENTITY FOR ANY DAMAGES OR OTHER LIABILITY ARISING
275
+ FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THIS LICENSE, UNDER ANY
276
+ LEGAL CLAIM.
277
+
278
+ 6.2. Limitation of Liability: LICENSEE SHALL HOLD LICENSOR HARMLESS AGAINST ANY
279
+ AND ALL CLAIMS, DEBTS, DUES, LIABILITIES, LIENS, CAUSES OF ACTION, DEMANDS,
280
+ OBLIGATIONS, DISPUTES, DAMAGES, LOSSES, EXPENSES, ATTORNEYS' FEES, COSTS,
281
+ LIABILITIES, AND ALL OTHER CLAIMS OF EVERY KIND AND NATURE WHATSOEVER, WHETHER
282
+ KNOWN OR UNKNOWN, ANTICIPATED OR UNANTICIPATED, FORESEEN OR UNFORESEEN, ACCRUED
283
+ OR UNACCRUED, DISCLOSED OR UNDISCLOSED, ARISING OUT OF OR RELATING TO LICENSEE’S
284
+ USE OF THE SOFTWARE. NOTHING IN THIS SECTION SHOULD BE INTERPRETED TO REQUIRE
285
+ LICENSEE TO INDEMNIFY LICENSOR, NOR REQUIRE LICENSOR TO INDEMNIFY LICENSEE.
286
+
287
+ 7. TERMINATION
288
+
289
+ 7.1. Violations of Ethical Standards or Breaching Duty of Care: If Licensee
290
+ violates the Ethical Standards section or Licensee, or any other person or
291
+ entity within the Supply Chain prior to a good or service reaching the Licensee,
292
+ breaches its Duty of Care to Supply Chain Impacted Parties, Licensee must remedy
293
+ the violation or harm caused by Licensee within 30 days of being notified of the
294
+ violation or harm. If Licensee fails to remedy the violation or harm within 30
295
+ days, all rights in the Software granted to Licensee by License will be null and
296
+ void as between Licensor and Licensee.
297
+
298
+ 7.2. Failure of Notice: If any person or entity notifies Licensee in writing
299
+ that Licensee has not complied with the Notice section of this License, Licensee
300
+ can keep this License by taking all practical steps to comply within 30 days
301
+ after the notice of noncompliance. If Licensee does not do so, Licensee’s
302
+ License (and all rights licensed hereunder) will end immediately.
303
+
304
+ 7.3. Judicial Findings: In the event Licensee is found by a civil, criminal,
305
+ administrative, or other court of competent jurisdiction, or some other
306
+ adjudicating body with legal authority, to have committed actions which are in
307
+ violation of the Ethical Standards or Supply Chain Impacted Party sections of
308
+ this License, all rights granted to Licensee by this License will terminate
309
+ immediately.
310
+
311
+ 7.4. Patent Litigation: If Licensee institutes patent litigation against any
312
+ entity (including a cross-claim or counterclaim in a suit) alleging that the
313
+ Software, all or part of the Software’s code, or a derivative work developed
314
+ using the Software, including a portion of its code, constitutes direct or
315
+ contributory patent infringement, then any patent license, along with all other
316
+ rights, granted to Licensee under this License will terminate as of the date
317
+ such litigation is filed.
318
+
319
+ 7.5. Additional Remedies: Termination of the License by failing to remedy harms
320
+ in no way prevents Licensor or Supply Chain Impacted Party from seeking
321
+ appropriate remedies at law or in equity.
322
+
323
+ 8. MISCELLANEOUS:
324
+
325
+ 8.1. Conditions: Sections 3, 4.1, 5.1, 5.2, 7.1, 7.2, 7.3, and 7.4 are
326
+ conditions of the rights granted to Licensee in the License.
327
+
328
+ 8.2. Equitable Relief: Licensor and any Supply Chain Impacted Party shall be
329
+ entitled to equitable relief, including injunctive relief or specific
330
+ performance of the terms hereof, in addition to any other remedy to which they
331
+ are entitled at law or in equity.
332
+
333
+ 8.3. Severability: If any term or provision of this License is determined to be
334
+ invalid, illegal, or unenforceable by a court of competent jurisdiction, any
335
+ such determination of invalidity, illegality, or unenforceability shall not
336
+ affect any other term or provision of this License or invalidate or render
337
+ unenforceable such term or provision in any other jurisdiction. If the
338
+ determination of invalidity, illegality, or unenforceability by a court of
339
+ competent jurisdiction pertains to the terms or provisions contained in the
340
+ Ethical Standards section of this License, all rights in the Software granted to
341
+ Licensee shall be deemed null and void as between Licensor and Licensee.
342
+
343
+ 8.4. Section Titles: Section titles are solely written for organizational
344
+ purposes and should not be used to interpret the language within each section.
345
+
346
+ 8.5. Citations: Citations are solely written to provide context for the source
347
+ of the provisions in the Ethical Standards.
348
+
349
+ 8.6. Section Summaries: Some sections have a brief italicized description which
350
+ is provided for the sole purpose of briefly describing the section and should
351
+ not be used to interpret the terms of the License.
352
+
353
+ 8.7. Entire License: This is the entire License between the Licensor and
354
+ Licensee with respect to the claims released herein and that the consideration
355
+ stated herein is the only consideration or compensation to be paid or exchanged
356
+ between them for this License. This License cannot be modified or amended except
357
+ in a writing signed by Licensor and Licensee.
358
+
359
+ 8.8. Successors and Assigns: This License shall be binding upon and inure to the
360
+ benefit of the Licensor's and Licensee's respective heirs, successors, and
361
+ assigns.
362
+
363
+ 9. ADDENDA:
364
+
365
+ This License is supplemented by one or more addenda, each of which is
366
+ incorporated by reference and constitutes a legally binding part of this
367
+ License. In the event of any conflict between the terms of this License and
368
+ the terms of an addendum, the terms of the addendum shall control with
369
+ respect to the matters addressed therein.
370
+
371
+ 9.1. Age Verification Compliance Restriction Notice (AGELESS Version 1.1):
372
+ Prohibits exercise of rights granted by this License in any jurisdiction
373
+ where an Age Verification Law (as defined therein) is in effect. See
374
+ AGELESS for full terms.
package/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ Create a TypeScript library from [ts-template](https://codeberg.org/joshua-dev/ts-template).
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## Requirements
4
+
5
+ - Node `^26.0.0`
6
+ - pnpm `>=11`
7
+
8
+ ## Use
9
+
10
+ ```sh
11
+ pnpm create @joshua-dev/ts
12
+ ```
13
+
14
+ The target directory must be empty or contain only `.git`. The generator will
15
+ not delete a non-empty directory.
@@ -0,0 +1,418 @@
1
+ #!/usr/bin/env node
2
+ import path from "node:path";
3
+ import { styleText } from "node:util";
4
+ import { cancel, confirm, intro, isCancel, log, outro, select, spinner, text } from "@clack/prompts";
5
+ import { execa } from "execa";
6
+ import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
7
+ import { findUp } from "find-up";
8
+ import { downloadTemplate } from "giget";
9
+ import { loadJsonFile } from "load-json-file";
10
+ import validatePackageName from "validate-npm-package-name";
11
+ // src/lib/utils.ts
12
+ async function gitConfig(key) {
13
+ try {
14
+ const { stdout } = await execa("git", [
15
+ "config",
16
+ "--get",
17
+ key
18
+ ], { stdio: [
19
+ "ignore",
20
+ "pipe",
21
+ "ignore"
22
+ ] });
23
+ return stdout.trim();
24
+ } catch {
25
+ return "";
26
+ }
27
+ }
28
+ async function detectGitAuthor() {
29
+ const [name, email] = await Promise.all([gitConfig("user.name"), gitConfig("user.email")]);
30
+ if (name !== "" && email !== "") return `${name} <${email}>`;
31
+ return name;
32
+ }
33
+ function sanitizePackageName(value, defaultValue = "") {
34
+ const name = value.toLowerCase().replaceAll(/[\s_]+/g, "-").replaceAll(/[^a-z0-9.-]+/g, "-").replaceAll(/-{2,}/g, "-").replaceAll(/^[._-]+/g, "").replaceAll(/[-.]+$/g, "");
35
+ if (name === "") return defaultValue;
36
+ return name;
37
+ }
38
+ function isErrno(error, code) {
39
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
40
+ }
41
+ function errorMessage(error) {
42
+ if (error instanceof Error) return error.message;
43
+ return String(error);
44
+ }
45
+ // src/lib/install.ts
46
+ async function isPnpmAvailable() {
47
+ try {
48
+ await execa("pnpm", ["--version"], { stdio: "ignore" });
49
+ return true;
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+ async function installDependencies(target) {
55
+ if (!await isPnpmAvailable()) {
56
+ log.warn(`pnpm was not found. Install dependencies with:
57
+ cd ${target}\n pnpm install`);
58
+ return;
59
+ }
60
+ const progress = spinner();
61
+ progress.start("Installing dependencies...");
62
+ try {
63
+ await execa("pnpm", ["install"], { cwd: target });
64
+ progress.stop(styleText("green", "Dependencies installed."));
65
+ } catch (error) {
66
+ progress.error(styleText("red", "Dependency installation failed."));
67
+ throw new Error(`pnpm install failed in ${target}.\n${errorMessage(error)}`, { cause: error });
68
+ }
69
+ }
70
+ // src/etc/constants.ts
71
+ /**
72
+ * The template this generator will download.
73
+ */
74
+ const TEMPLATE_SOURCE = "https://codeberg.org/joshua-dev/ts-template/archive/main.tar.gz";
75
+ /**
76
+ * Source for the SPDX license texts.
77
+ */
78
+ const SPDX_LICENSE_SOURCE = "https://raw.githubusercontent.com/spdx/license-list-data/v3.29.0/text";
79
+ /**
80
+ * Default package name to use in prompts.
81
+ */
82
+ const DEFAULT_PACKAGE_NAME = "my-ts-lib";
83
+ /**
84
+ * Default license to select in prompts.
85
+ */
86
+ const DEFAULT_LICENSE = "Hippocratic-3.0-core";
87
+ // src/lib/project.ts
88
+ const LICENSE_DOWNLOAD_TIMEOUT = 15e3;
89
+ async function packageRoot() {
90
+ const packageJson = await findUp("package.json", { cwd: import.meta.dirname });
91
+ if (packageJson === void 0) throw new Error("Cannot find the package root.");
92
+ return path.dirname(packageJson);
93
+ }
94
+ function isPackageJson(value) {
95
+ return typeof value === "object" && value !== null && !Array.isArray(value);
96
+ }
97
+ function setName(pkg, name) {
98
+ pkg.name = name.trim();
99
+ }
100
+ function setDescription(pkg, description) {
101
+ const value = description.trim();
102
+ if (value === "") {
103
+ delete pkg.description;
104
+ return;
105
+ }
106
+ pkg.description = value;
107
+ }
108
+ function setAuthor(pkg, author) {
109
+ const value = author.trim();
110
+ if (value === "") {
111
+ delete pkg.author;
112
+ return;
113
+ }
114
+ pkg.author = value;
115
+ }
116
+ function setRepository(pkg, repository) {
117
+ const url = repository.trim();
118
+ if (url === "") {
119
+ delete pkg.repository;
120
+ return;
121
+ }
122
+ pkg.repository = {
123
+ type: "git",
124
+ url
125
+ };
126
+ }
127
+ function setLicense(pkg, license) {
128
+ pkg.license = license;
129
+ if (license === "UNLICENSED") pkg.private = true;
130
+ }
131
+ function updatePackageJson(pkg, answers) {
132
+ const next = { ...pkg };
133
+ setName(next, answers.name);
134
+ setDescription(next, answers.description);
135
+ setAuthor(next, answers.author);
136
+ setRepository(next, answers.repository);
137
+ setLicense(next, answers.license);
138
+ return next;
139
+ }
140
+ function serializePackageJson(pkg) {
141
+ return `${JSON.stringify(pkg, null, 2)}\n`;
142
+ }
143
+ async function readPackageJson(file) {
144
+ try {
145
+ const value = await loadJsonFile(file);
146
+ if (!isPackageJson(value)) throw new Error("package.json must contain a JSON object.");
147
+ return value;
148
+ } catch (error) {
149
+ if (isErrno(error, "ENOENT")) throw new Error(`package.json is missing: ${file}`, { cause: error });
150
+ throw error;
151
+ }
152
+ }
153
+ async function updatePackageJsonFile(target, answers) {
154
+ const file = path.join(target, "package.json");
155
+ const pkg = updatePackageJson(await readPackageJson(file), answers);
156
+ await writeFile(file, serializePackageJson(pkg));
157
+ }
158
+ function renderReadme(template, answers) {
159
+ const description = answers.description.trim();
160
+ let license = "";
161
+ if (answers.license !== "UNLICENSED") license = `## License\n\n${answers.license}`;
162
+ return `${template.replaceAll("{{name}}", () => answers.name).replaceAll("{{description}}", () => description).replaceAll("{{license}}", () => license).replaceAll(/\n{3,}/g, "\n\n").trimEnd()}\n`;
163
+ }
164
+ async function readReadmeTemplate() {
165
+ const file = path.join(await packageRoot(), "templates/README.md");
166
+ try {
167
+ return await readFile(file, "utf8");
168
+ } catch (error) {
169
+ if (isErrno(error, "ENOENT")) throw new Error(`README template is missing: ${file}`, { cause: error });
170
+ throw error;
171
+ }
172
+ }
173
+ async function writeReadme(answers) {
174
+ const template = await readReadmeTemplate();
175
+ await writeFile(path.join(answers.target, "README.md"), renderReadme(template, answers));
176
+ }
177
+ function applyLicensePlaceholders(text, id, options) {
178
+ switch (id) {
179
+ case "MIT": return text.replaceAll("<year>", String(options.year)).replaceAll("<copyright holders>", options.copyrightHolder);
180
+ case "BSD-3-Clause": return text.replaceAll("<year>", String(options.year)).replaceAll("<owner>", options.copyrightHolder);
181
+ case "Apache-2.0": return text.replaceAll("[yyyy]", String(options.year)).replaceAll("[name of copyright owner]", options.copyrightHolder);
182
+ default: return text;
183
+ }
184
+ }
185
+ async function readLicenseText(id) {
186
+ const url = `${SPDX_LICENSE_SOURCE}/${id}.txt`;
187
+ const response = await fetch(url, { signal: AbortSignal.timeout(LICENSE_DOWNLOAD_TIMEOUT) }).catch((error) => {
188
+ throw new Error(`Failed to download license text: ${url}\n${errorMessage(error)}`, { cause: error });
189
+ });
190
+ if (!response.ok) throw new Error(`License text is missing: ${url} (HTTP ${response.status})`);
191
+ return response.text();
192
+ }
193
+ async function writeLicense(answers, year = (/* @__PURE__ */ new Date()).getFullYear()) {
194
+ const file = path.join(answers.target, "LICENSE");
195
+ if (answers.license === "UNLICENSED") {
196
+ await rm(file, { force: true });
197
+ return;
198
+ }
199
+ const text = applyLicensePlaceholders(await readLicenseText(answers.license), answers.license, {
200
+ year,
201
+ copyrightHolder: answers.copyrightHolder.trim()
202
+ });
203
+ await writeFile(file, text);
204
+ }
205
+ async function assertTargetEmpty(target) {
206
+ try {
207
+ if (!(await stat(target)).isDirectory()) throw new Error(`Target is not a directory: ${target}`);
208
+ if ((await readdir(target)).some((entry) => entry !== ".git")) throw new Error(`Target directory is not empty: ${target}`);
209
+ } catch (error) {
210
+ if (isErrno(error, "ENOENT")) return;
211
+ throw error;
212
+ }
213
+ }
214
+ async function downloadTemplateTo(target) {
215
+ await mkdir(target, { recursive: true });
216
+ await downloadTemplate(TEMPLATE_SOURCE, {
217
+ dir: target,
218
+ force: true,
219
+ silent: true
220
+ });
221
+ }
222
+ async function generateProject({ answers }) {
223
+ await assertTargetEmpty(answers.target);
224
+ try {
225
+ await downloadTemplateTo(answers.target);
226
+ } catch (error) {
227
+ throw new Error(`Template download failed. Remove ${answers.target} before retrying.\n${errorMessage(error)}`, { cause: error });
228
+ }
229
+ await updatePackageJsonFile(answers.target, answers);
230
+ await writeReadme(answers);
231
+ await writeLicense(answers);
232
+ }
233
+ // src/lib/license.ts
234
+ const LICENSES = [
235
+ {
236
+ id: "Hippocratic-3.0-core",
237
+ label: "Hippocratic",
238
+ hint: "3.0 • ethical source"
239
+ },
240
+ {
241
+ id: "MIT",
242
+ label: "MIT",
243
+ hint: "permissive"
244
+ },
245
+ {
246
+ id: "Apache-2.0",
247
+ label: "Apache",
248
+ hint: "2.0 • permissive, patent grant"
249
+ },
250
+ {
251
+ id: "GPL-3.0-only",
252
+ label: "GPL",
253
+ hint: "3.0-only • strong copyleft"
254
+ },
255
+ {
256
+ id: "LGPL-3.0-only",
257
+ label: "LGPL",
258
+ hint: "3.0-only • weak copyleft"
259
+ },
260
+ {
261
+ id: "BSD-3-Clause",
262
+ label: "BSD",
263
+ hint: "3 Clause • permissive"
264
+ },
265
+ {
266
+ id: "CC0-1.0",
267
+ label: "CC0",
268
+ hint: "1.0 • public domain dedication"
269
+ },
270
+ {
271
+ id: "UNLICENSED",
272
+ label: "Proprietary",
273
+ hint: "no license"
274
+ }
275
+ ];
276
+ function licenseNeedsCopyright(id) {
277
+ return id === "MIT" || id === "BSD-3-Clause" || id === "Apache-2.0";
278
+ }
279
+ function copyrightHolderFromAuthor(author) {
280
+ const value = author.trim();
281
+ if (value === "") return "";
282
+ const match = /^(?<name>.*?)\s*<[^>]*>\s*$/.exec(value);
283
+ if (match) return (match.groups?.name ?? "").trim();
284
+ if (value.includes("@")) return "";
285
+ return value;
286
+ }
287
+ // src/lib/prompts.ts
288
+ var CancelledError = class extends Error {
289
+ constructor() {
290
+ super("Operation cancelled.");
291
+ this.name = "CancelledError";
292
+ }
293
+ };
294
+ function unwrap(value) {
295
+ if (isCancel(value)) throw new CancelledError();
296
+ return value;
297
+ }
298
+ async function askText(options) {
299
+ return unwrap(await text(options)).trim();
300
+ }
301
+ async function askSelect(options) {
302
+ return unwrap(await select(options)).trim();
303
+ }
304
+ function validateRequired(label) {
305
+ return (value) => {
306
+ if ((value ?? "").trim() === "") return `Enter a ${label}.`;
307
+ };
308
+ }
309
+ async function askProject() {
310
+ const target = await askText({
311
+ message: styleText("green", "Target Directory"),
312
+ initialValue: DEFAULT_PACKAGE_NAME,
313
+ placeholder: DEFAULT_PACKAGE_NAME,
314
+ validate: async (input) => {
315
+ if (!input) return /* @__PURE__ */ new TypeError("Enter a target directory.");
316
+ try {
317
+ await assertTargetEmpty(path.resolve(process.cwd(), input));
318
+ } catch (error) {
319
+ if (error instanceof Error) return error;
320
+ }
321
+ }
322
+ });
323
+ const defaultName = sanitizePackageName(path.basename(path.resolve(target)));
324
+ const name = await askText({
325
+ message: styleText("green", "Package Name"),
326
+ initialValue: defaultName,
327
+ placeholder: defaultName,
328
+ validate: (value) => {
329
+ const result = validatePackageName((value ?? "").trim());
330
+ if (result.validForNewPackages) return;
331
+ const { errors, warnings } = result;
332
+ if (Array.isArray(errors) && errors.length > 0) return errors[0];
333
+ if (Array.isArray(warnings) && warnings.length > 0) return warnings[0];
334
+ return "Invalid package name.";
335
+ }
336
+ });
337
+ const description = await askText({
338
+ message: styleText("green", "Description"),
339
+ placeholder: "Optional"
340
+ });
341
+ const defaultAuthor = await detectGitAuthor();
342
+ const author = await askText({
343
+ message: styleText("green", "Author"),
344
+ initialValue: defaultAuthor,
345
+ placeholder: "Name <email>"
346
+ });
347
+ const repository = await askText({
348
+ message: styleText("green", "Repository URL"),
349
+ placeholder: "Optional"
350
+ });
351
+ const license = await askSelect({
352
+ message: styleText("green", "License"),
353
+ initialValue: DEFAULT_LICENSE,
354
+ options: LICENSES.map((license) => ({
355
+ value: license.id,
356
+ label: license.label,
357
+ hint: license.hint
358
+ }))
359
+ });
360
+ let copyrightHolder = copyrightHolderFromAuthor(author);
361
+ if (licenseNeedsCopyright(license) && !copyrightHolder) copyrightHolder = await askText({
362
+ message: styleText("green", "Copyright Holder"),
363
+ placeholder: "Name or organization",
364
+ validate: validateRequired("copyright holder")
365
+ });
366
+ const shouldInstallDependencies = unwrap(await confirm({
367
+ message: styleText("green", "Install dependencies?"),
368
+ initialValue: true
369
+ }));
370
+ return {
371
+ target,
372
+ name,
373
+ description,
374
+ author,
375
+ repository,
376
+ license,
377
+ copyrightHolder,
378
+ shouldInstallDependencies
379
+ };
380
+ }
381
+ // src/bin/create-ts.ts
382
+ async function main() {
383
+ process.stdout.write("\n");
384
+ intro(styleText("dim", `Creating a new ${styleText(["blue"], "TypeScript")} library...`));
385
+ const answers = await askProject();
386
+ const progress = spinner();
387
+ progress.start("Generating project...");
388
+ try {
389
+ await generateProject({ answers });
390
+ progress.stop(styleText("green", "Project generated."));
391
+ } catch (error) {
392
+ progress.error(styleText("red", "Project generation failed."));
393
+ throw error;
394
+ }
395
+ if (answers.shouldInstallDependencies) await installDependencies(answers.target);
396
+ const relativeTarget = path.relative(process.cwd(), answers.target);
397
+ const steps = [];
398
+ if (relativeTarget !== "" && relativeTarget !== ".") steps.push(`cd ${relativeTarget}`);
399
+ if (!answers.shouldInstallDependencies) steps.push("pnpm install");
400
+ steps.push("pnpm dev");
401
+ log.success(`Next steps:\n\n${styleText("dim", steps.join("\n\n"))}`);
402
+ outro("Done.");
403
+ }
404
+ async function run() {
405
+ try {
406
+ await main();
407
+ } catch (error) {
408
+ if (error instanceof CancelledError) {
409
+ cancel("Operation cancelled.");
410
+ process.exitCode = 0;
411
+ return;
412
+ }
413
+ log.error(errorMessage(error));
414
+ process.exitCode = 1;
415
+ }
416
+ }
417
+ await run();
418
+ export {};
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@joshua-dev/create-ts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Generator for TypeScript libraries from ts-template.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "author": "joshua-dev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://codeberg.org/joshua-dev/create-ts.git"
10
+ },
11
+ "bin": {
12
+ "create-ts": "./dist/create-ts.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "templates"
17
+ ],
18
+ "type": "module",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "tsdown",
24
+ "dev": "tsdown --watch src",
25
+ "format": "oxfmt --check",
26
+ "format:fix": "oxfmt",
27
+ "lint": "oxlint",
28
+ "lint:fix": "oxlint --fix",
29
+ "release": "release-it",
30
+ "release:alpha": "release-it --preRelease=alpha",
31
+ "release:beta": "release-it --preRelease=beta",
32
+ "release:dry": "release-it --dry-run",
33
+ "release:rc": "release-it --preRelease=rc",
34
+ "test": "vitest --run",
35
+ "test:coverage": "vitest --run --coverage",
36
+ "test:watch": "vitest",
37
+ "test:integration": "vitest --run --config vitest.integration.config.ts",
38
+ "types": "tsrs",
39
+ "types:watch": "tsrs --watch"
40
+ },
41
+ "dependencies": {
42
+ "@clack/prompts": "^1.9.0",
43
+ "execa": "^10.2.1",
44
+ "find-up": "^8.0.0",
45
+ "giget": "^3.3.1",
46
+ "load-json-file": "^7.0.1",
47
+ "validate-npm-package-name": "^8.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "@joshua-dev/oxc-config": "^1.0.0-beta.8",
51
+ "@release-it/conventional-changelog": "^12.0.2",
52
+ "@types/node": "^26.6.11",
53
+ "@types/validate-npm-package-name": "^4.0.2",
54
+ "@vitest/coverage-v8": "^5.1.2",
55
+ "@vitest/ui": "^5.1.2",
56
+ "dotenv": "^18.0.10",
57
+ "oxfmt": "^0.80.0",
58
+ "oxlint": "^1.95.0",
59
+ "publint": "^0.3.25",
60
+ "release-it": "^21.1.3",
61
+ "release-it-gitea": "^1.9.4",
62
+ "tsdown": "~0.23.7",
63
+ "tsrs": "^7.1.0-beta.tsrs6",
64
+ "unplugin-unused": "^0.6.0",
65
+ "vitest": "^5.1.2"
66
+ },
67
+ "engines": {
68
+ "node": "^26.0.0",
69
+ "pnpm": ">=11"
70
+ },
71
+ "engineStrict": true,
72
+ "packageManager": "pnpm@11.29.0"
73
+ }
@@ -0,0 +1,14 @@
1
+ # {{name}}
2
+
3
+ {{description}}
4
+
5
+ ## Development
6
+
7
+ ```sh
8
+ pnpm install
9
+ pnpm dev
10
+ pnpm test
11
+ pnpm build
12
+ ```
13
+
14
+ {{license}}