create-tina-app 1.2.0 → 1.2.2
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/dist/index.d.ts +2 -1
- package/dist/index.js +267 -187
- package/dist/templates.d.ts +16 -0
- package/dist/util/checkPkgManagers.d.ts +2 -0
- package/dist/util/fileUtil.d.ts +4 -5
- package/dist/util/git.d.ts +2 -4
- package/dist/util/logger.d.ts +20 -0
- package/dist/util/preRunChecks.d.ts +2 -4
- package/package.json +6 -5
- package/dist/examples.d.ts +0 -19
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const PKG_MANAGERS: string[];
|
|
2
|
+
export declare function run(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
// src/index.ts
|
|
26
26
|
var src_exports = {};
|
|
27
27
|
__export(src_exports, {
|
|
28
|
+
PKG_MANAGERS: () => PKG_MANAGERS,
|
|
28
29
|
run: () => run
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -35,12 +36,49 @@ var import_node_path = __toESM(require("path"));
|
|
|
35
36
|
|
|
36
37
|
// package.json
|
|
37
38
|
var name = "create-tina-app";
|
|
38
|
-
var version = "1.2.
|
|
39
|
+
var version = "1.2.2";
|
|
39
40
|
|
|
40
41
|
// src/util/fileUtil.ts
|
|
41
42
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
42
43
|
var import_path = __toESM(require("path"));
|
|
44
|
+
|
|
45
|
+
// src/util/logger.ts
|
|
43
46
|
var import_chalk = __toESM(require("chalk"));
|
|
47
|
+
var TextStyles = {
|
|
48
|
+
link: import_chalk.default.bold.cyan,
|
|
49
|
+
cmd: import_chalk.default.inverse,
|
|
50
|
+
info: import_chalk.default.blue,
|
|
51
|
+
success: import_chalk.default.green,
|
|
52
|
+
warn: import_chalk.default.yellow,
|
|
53
|
+
err: import_chalk.default.red,
|
|
54
|
+
bold: import_chalk.default.bold
|
|
55
|
+
};
|
|
56
|
+
var Logger = class {
|
|
57
|
+
log(message) {
|
|
58
|
+
console.info(message);
|
|
59
|
+
}
|
|
60
|
+
debug(message) {
|
|
61
|
+
console.debug(TextStyles.info(`[DEBUG] ${message}`));
|
|
62
|
+
}
|
|
63
|
+
info(message) {
|
|
64
|
+
console.info(TextStyles.info(`[INFO] ${message}`));
|
|
65
|
+
}
|
|
66
|
+
success(message) {
|
|
67
|
+
console.log(TextStyles.success(`[SUCCESS] ${message}`));
|
|
68
|
+
}
|
|
69
|
+
cmd(message) {
|
|
70
|
+
console.log(TextStyles.cmd(message));
|
|
71
|
+
}
|
|
72
|
+
warn(message) {
|
|
73
|
+
console.warn(TextStyles.warn(`[WARNING] ${message}`));
|
|
74
|
+
}
|
|
75
|
+
err(message) {
|
|
76
|
+
console.error(TextStyles.err(`[ERROR] ${message}`));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var log = new Logger();
|
|
80
|
+
|
|
81
|
+
// src/util/fileUtil.ts
|
|
44
82
|
async function isWriteable(directory) {
|
|
45
83
|
try {
|
|
46
84
|
await import_fs_extra.default.promises.access(directory, (import_fs_extra.default.constants || import_fs_extra.default).W_OK);
|
|
@@ -49,10 +87,7 @@ async function isWriteable(directory) {
|
|
|
49
87
|
return false;
|
|
50
88
|
}
|
|
51
89
|
}
|
|
52
|
-
function
|
|
53
|
-
return import_fs_extra.default.mkdirp(root);
|
|
54
|
-
}
|
|
55
|
-
function isFolderEmpty(root, name2) {
|
|
90
|
+
function folderContainsInstallConflicts(root) {
|
|
56
91
|
const validFiles = [
|
|
57
92
|
".DS_Store",
|
|
58
93
|
".git",
|
|
@@ -74,35 +109,49 @@ function isFolderEmpty(root, name2) {
|
|
|
74
109
|
"yarn-error.log"
|
|
75
110
|
];
|
|
76
111
|
const conflicts = import_fs_extra.default.readdirSync(root).filter((file) => !validFiles.includes(file)).filter((file) => !/\.iml$/.test(file));
|
|
112
|
+
return conflicts;
|
|
113
|
+
}
|
|
114
|
+
async function setupProjectDirectory(dir) {
|
|
115
|
+
const appName = import_path.default.basename(dir);
|
|
116
|
+
await import_fs_extra.default.mkdirp(dir);
|
|
117
|
+
process.chdir(dir);
|
|
118
|
+
const conflicts = folderContainsInstallConflicts(dir);
|
|
77
119
|
if (conflicts.length > 0) {
|
|
78
|
-
|
|
79
|
-
`The directory ${
|
|
120
|
+
log.err(
|
|
121
|
+
`The directory '${TextStyles.bold(
|
|
122
|
+
appName
|
|
123
|
+
)}' contains files that could conflict. Below is a list of conflicts, please remove them and try again.`
|
|
80
124
|
);
|
|
81
|
-
console.log();
|
|
82
125
|
for (const file of conflicts) {
|
|
83
126
|
try {
|
|
84
|
-
const stats = import_fs_extra.default.lstatSync(import_path.default.join(
|
|
127
|
+
const stats = import_fs_extra.default.lstatSync(import_path.default.join(dir, file));
|
|
85
128
|
if (stats.isDirectory()) {
|
|
86
|
-
|
|
129
|
+
log.log(`- ${TextStyles.info(file)}/`);
|
|
87
130
|
} else {
|
|
88
|
-
|
|
131
|
+
log.log(`- ${file}`);
|
|
89
132
|
}
|
|
90
133
|
} catch {
|
|
91
|
-
|
|
134
|
+
log.log(`- ${file}`);
|
|
92
135
|
}
|
|
93
136
|
}
|
|
94
|
-
|
|
95
|
-
console.log(
|
|
96
|
-
"Either try using a new directory name, or remove the files listed above."
|
|
97
|
-
);
|
|
98
|
-
console.log();
|
|
99
|
-
return false;
|
|
137
|
+
process.exit(1);
|
|
100
138
|
}
|
|
101
|
-
return
|
|
139
|
+
return appName;
|
|
140
|
+
}
|
|
141
|
+
function updateProjectPackageName(dir, name2) {
|
|
142
|
+
const packageJsonPath = import_path.default.join(dir, "package.json");
|
|
143
|
+
const packageJson = JSON.parse(import_fs_extra.default.readFileSync(packageJsonPath, "utf8"));
|
|
144
|
+
packageJson.name = name2;
|
|
145
|
+
import_fs_extra.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
146
|
+
}
|
|
147
|
+
function updateProjectPackageVersion(dir, version2) {
|
|
148
|
+
const packageJsonPath = import_path.default.join(dir, "package.json");
|
|
149
|
+
const packageJson = JSON.parse(import_fs_extra.default.readFileSync(packageJsonPath, "utf8"));
|
|
150
|
+
packageJson.version = version2;
|
|
151
|
+
import_fs_extra.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
102
152
|
}
|
|
103
153
|
|
|
104
154
|
// src/util/install.ts
|
|
105
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
106
155
|
var import_cross_spawn = __toESM(require("cross-spawn"));
|
|
107
156
|
function install(root, dependencies, { packageManager, isOnline, devDependencies }) {
|
|
108
157
|
const npmFlags = [];
|
|
@@ -140,12 +189,10 @@ function install(root, dependencies, { packageManager, isOnline, devDependencies
|
|
|
140
189
|
} else {
|
|
141
190
|
args = ["install"];
|
|
142
191
|
if (!isOnline) {
|
|
143
|
-
|
|
192
|
+
log.warn("You appear to be offline.");
|
|
144
193
|
if (packageManager === "yarn") {
|
|
145
|
-
|
|
194
|
+
log.warn("Falling back to the local Yarn cache.");
|
|
146
195
|
args.push("--offline");
|
|
147
|
-
} else {
|
|
148
|
-
console.log();
|
|
149
196
|
}
|
|
150
197
|
}
|
|
151
198
|
}
|
|
@@ -174,14 +221,10 @@ function install(root, dependencies, { packageManager, isOnline, devDependencies
|
|
|
174
221
|
});
|
|
175
222
|
}
|
|
176
223
|
|
|
177
|
-
// src/index.ts
|
|
178
|
-
var import_chalk5 = __toESM(require("chalk"));
|
|
179
|
-
|
|
180
224
|
// src/util/git.ts
|
|
181
225
|
var import_child_process = require("child_process");
|
|
182
226
|
var import_path2 = __toESM(require("path"));
|
|
183
227
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
184
|
-
var import_chalk3 = __toESM(require("chalk"));
|
|
185
228
|
function isInGitRepository() {
|
|
186
229
|
try {
|
|
187
230
|
(0, import_child_process.execSync)("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
|
@@ -198,51 +241,40 @@ function isInMercurialRepository() {
|
|
|
198
241
|
}
|
|
199
242
|
return false;
|
|
200
243
|
}
|
|
201
|
-
function
|
|
202
|
-
let didInit = false;
|
|
244
|
+
function makeFirstCommit(root) {
|
|
203
245
|
try {
|
|
204
|
-
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
205
|
-
if (isInGitRepository() || isInMercurialRepository()) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
if (!import_fs_extra2.default.existsSync(".gitignore")) {
|
|
209
|
-
console.warn(
|
|
210
|
-
import_chalk3.default.yellow(
|
|
211
|
-
"There is no .gitignore file in this repository, creating one..."
|
|
212
|
-
)
|
|
213
|
-
);
|
|
214
|
-
import_fs_extra2.default.writeFileSync(
|
|
215
|
-
".gitignore",
|
|
216
|
-
`node_modules
|
|
217
|
-
.yarn/*
|
|
218
|
-
.DS_Store
|
|
219
|
-
.cache
|
|
220
|
-
.next/
|
|
221
|
-
`
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
(0, import_child_process.execSync)("git init", { stdio: "ignore" });
|
|
225
|
-
didInit = true;
|
|
226
246
|
(0, import_child_process.execSync)("git checkout -b main", { stdio: "ignore" });
|
|
227
247
|
(0, import_child_process.execSync)("git add -A", { stdio: "ignore" });
|
|
228
248
|
(0, import_child_process.execSync)('git commit -m "Initial commit from Create Tina App"', {
|
|
229
249
|
stdio: "ignore"
|
|
230
250
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
} catch (err) {
|
|
252
|
+
import_fs_extra2.default.removeSync(import_path2.default.join(root, ".git"));
|
|
253
|
+
throw err;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function initializeGit() {
|
|
257
|
+
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
258
|
+
if (isInGitRepository() || isInMercurialRepository()) {
|
|
259
|
+
log.warn("Already in a Git repository, skipping.");
|
|
239
260
|
return false;
|
|
240
261
|
}
|
|
262
|
+
if (!import_fs_extra2.default.existsSync(".gitignore")) {
|
|
263
|
+
log.warn("There is no .gitignore file in this repository, creating one...");
|
|
264
|
+
import_fs_extra2.default.writeFileSync(
|
|
265
|
+
".gitignore",
|
|
266
|
+
`node_modules
|
|
267
|
+
.yarn/*
|
|
268
|
+
.DS_Store
|
|
269
|
+
.cache
|
|
270
|
+
.next/
|
|
271
|
+
`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
(0, import_child_process.execSync)("git init", { stdio: "ignore" });
|
|
275
|
+
return true;
|
|
241
276
|
}
|
|
242
277
|
|
|
243
|
-
// src/index.ts
|
|
244
|
-
var import_node_process = require("process");
|
|
245
|
-
|
|
246
278
|
// src/util/examples.ts
|
|
247
279
|
var import_node_stream = require("stream");
|
|
248
280
|
var import_promises = require("stream/promises");
|
|
@@ -291,11 +323,10 @@ async function downloadAndExtractRepo(root, { username, name: name2, branch, fil
|
|
|
291
323
|
);
|
|
292
324
|
}
|
|
293
325
|
|
|
294
|
-
// src/
|
|
295
|
-
var import_chalk4 = __toESM(require("chalk"));
|
|
326
|
+
// src/templates.ts
|
|
296
327
|
var import_fs_extra3 = require("fs-extra");
|
|
297
328
|
var import_path3 = __toESM(require("path"));
|
|
298
|
-
var
|
|
329
|
+
var TEMPLATES = [
|
|
299
330
|
{
|
|
300
331
|
title: "\u2B50 NextJS starter",
|
|
301
332
|
description: "Kickstart your project with NextJS \u2013 our top recommendation for a seamless, performant, and versatile web experience.",
|
|
@@ -339,168 +370,217 @@ var EXAMPLES = [
|
|
|
339
370
|
gitURL: "https://github.com/tinacms/tina-barebones-starter"
|
|
340
371
|
}
|
|
341
372
|
];
|
|
342
|
-
|
|
343
|
-
if (
|
|
344
|
-
const repoURL = new URL(
|
|
373
|
+
async function downloadTemplate(template, root) {
|
|
374
|
+
if (template.isInternal === false) {
|
|
375
|
+
const repoURL = new URL(template.gitURL);
|
|
345
376
|
const repoInfo = await getRepoInfo(repoURL);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
377
|
+
if (!repoInfo) {
|
|
378
|
+
throw new Error("Repository information not found.");
|
|
379
|
+
}
|
|
380
|
+
log.info(
|
|
381
|
+
`Downloading files from repo ${TextStyles.link(
|
|
349
382
|
`${repoInfo == null ? void 0 : repoInfo.username}/${repoInfo == null ? void 0 : repoInfo.name}`
|
|
350
|
-
)}
|
|
383
|
+
)}.`
|
|
351
384
|
);
|
|
352
|
-
|
|
353
|
-
throw new Error("downloadExample Failed. Repo info not found");
|
|
354
|
-
}
|
|
355
|
-
await downloadAndExtractRepo(root, repoInfo2);
|
|
385
|
+
await downloadAndExtractRepo(root, repoInfo);
|
|
356
386
|
} else {
|
|
357
|
-
const
|
|
358
|
-
await (0, import_fs_extra3.copy)(`${
|
|
387
|
+
const templateFile = import_path3.default.join(__dirname, "..", "examples", template.value);
|
|
388
|
+
await (0, import_fs_extra3.copy)(`${templateFile}/`, "./");
|
|
359
389
|
}
|
|
360
|
-
}
|
|
390
|
+
}
|
|
361
391
|
|
|
362
392
|
// src/util/preRunChecks.ts
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
393
|
+
var SUPPORTED_NODE_VERSIONS = ["18", "20", "22"];
|
|
394
|
+
function preRunChecks() {
|
|
395
|
+
checkSupportedNodeVersion();
|
|
396
|
+
}
|
|
397
|
+
function checkSupportedNodeVersion() {
|
|
398
|
+
if (!SUPPORTED_NODE_VERSIONS.some(
|
|
399
|
+
(version2) => process.version.startsWith(`v${version2}`)
|
|
400
|
+
)) {
|
|
401
|
+
log.warn(
|
|
402
|
+
`Version ${process.version} of Node.js is not supported in create-tina-app, please update to the latest LTS version. See https://nodejs.org/en/download/ for more details.`
|
|
367
403
|
);
|
|
368
404
|
}
|
|
369
|
-
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/util/checkPkgManagers.ts
|
|
408
|
+
var import_child_process2 = require("child_process");
|
|
409
|
+
async function checkPackageExists(name2) {
|
|
410
|
+
try {
|
|
411
|
+
await new Promise((resolve, reject) => {
|
|
412
|
+
(0, import_child_process2.exec)(`${name2} -v`, (error, stdout, stderr) => {
|
|
413
|
+
if (error) {
|
|
414
|
+
reject(stderr);
|
|
415
|
+
}
|
|
416
|
+
resolve(stdout);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
return true;
|
|
420
|
+
} catch (_) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
370
424
|
|
|
371
425
|
// src/index.ts
|
|
372
|
-
var
|
|
373
|
-
var
|
|
374
|
-
var
|
|
375
|
-
|
|
376
|
-
var program = new import_commander.Command(name);
|
|
377
|
-
var projectName = "";
|
|
378
|
-
program.version(version).option("-e, --example <example>", "Choose which example to start from").option("-d, --dir <dir>", "Choose which directory to run this script from").option("--noTelemetry", "Disable anonymous telemetry that is collected").arguments("[project-directory]").usage(`${import_chalk5.default.green("<project-directory>")} [options]`).action((name2) => {
|
|
379
|
-
projectName = name2;
|
|
380
|
-
});
|
|
381
|
-
var run = async () => {
|
|
426
|
+
var import_node_process = require("process");
|
|
427
|
+
var import_validate_npm_package_name = __toESM(require("validate-npm-package-name"));
|
|
428
|
+
var PKG_MANAGERS = ["npm", "yarn", "pnpm"];
|
|
429
|
+
async function run() {
|
|
382
430
|
preRunChecks();
|
|
431
|
+
let projectName = "";
|
|
432
|
+
const program = new import_commander.Command(name);
|
|
433
|
+
program.version(version).option(
|
|
434
|
+
"-t, --template <template>",
|
|
435
|
+
`Choose which template to start from. Valid templates are: ${TEMPLATES.map(
|
|
436
|
+
(x2) => x2.value
|
|
437
|
+
)}`
|
|
438
|
+
).option(
|
|
439
|
+
"-p, --pkg-manager <pkg-manager>",
|
|
440
|
+
`Choose which package manager to use. Valid package managers are: ${PKG_MANAGERS}`
|
|
441
|
+
).option(
|
|
442
|
+
"-d, --dir <dir>",
|
|
443
|
+
"Choose which directory to run this script from."
|
|
444
|
+
).option("--noTelemetry", "Disable anonymous telemetry that is collected.").arguments("[project-directory]").usage(`${TextStyles.success("<project-directory>")} [options]`).action((name2) => {
|
|
445
|
+
projectName = name2;
|
|
446
|
+
});
|
|
383
447
|
program.parse(process.argv);
|
|
384
448
|
const opts = program.opts();
|
|
385
449
|
if (opts.dir) {
|
|
386
450
|
process.chdir(opts.dir);
|
|
387
451
|
}
|
|
388
452
|
const telemetry = new import_metrics.Telemetry({ disabled: opts == null ? void 0 : opts.noTelemetry });
|
|
389
|
-
let
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
453
|
+
let template = opts.template;
|
|
454
|
+
if (template) {
|
|
455
|
+
template = TEMPLATES.find((_template) => _template.value === template);
|
|
456
|
+
if (!template) {
|
|
457
|
+
log.err(
|
|
458
|
+
`The provided template '${opts.template}' is invalid. Please provide one of the following: ${TEMPLATES.map(
|
|
459
|
+
(x2) => x2.value
|
|
460
|
+
)}`
|
|
461
|
+
);
|
|
462
|
+
(0, import_node_process.exit)(1);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
let pkgManager = opts.pkgManager;
|
|
466
|
+
if (pkgManager) {
|
|
467
|
+
if (!PKG_MANAGERS.find((_pkgManager) => _pkgManager === pkgManager)) {
|
|
468
|
+
log.err(
|
|
469
|
+
`The provided package manager '${opts.pkgManager}' is not supported. Please provide one of the following: ${PKG_MANAGERS}`
|
|
470
|
+
);
|
|
471
|
+
(0, import_node_process.exit)(1);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!pkgManager) {
|
|
475
|
+
const installedPkgManagers = [];
|
|
476
|
+
for (const pkg_manager of PKG_MANAGERS) {
|
|
477
|
+
if (await checkPackageExists(pkg_manager)) {
|
|
478
|
+
installedPkgManagers.push(pkg_manager);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (installedPkgManagers.length === 0) {
|
|
482
|
+
log.err(
|
|
483
|
+
`You have no supported package managers installed. Please install one of the following: ${PKG_MANAGERS}`
|
|
484
|
+
);
|
|
485
|
+
(0, import_node_process.exit)(1);
|
|
486
|
+
}
|
|
487
|
+
const res = await (0, import_prompts.default)({
|
|
488
|
+
message: "Which package manager would you like to use?",
|
|
489
|
+
name: "packageManager",
|
|
490
|
+
type: "select",
|
|
491
|
+
choices: installedPkgManagers.map((manager) => {
|
|
492
|
+
return { title: manager, value: manager };
|
|
493
|
+
})
|
|
494
|
+
});
|
|
495
|
+
if (!Object.hasOwn(res, "packageManager"))
|
|
496
|
+
(0, import_node_process.exit)(1);
|
|
497
|
+
pkgManager = res.packageManager;
|
|
498
|
+
}
|
|
402
499
|
if (!projectName) {
|
|
403
|
-
const
|
|
500
|
+
const res = await (0, import_prompts.default)({
|
|
404
501
|
name: "name",
|
|
405
502
|
type: "text",
|
|
406
503
|
message: "What is your project named?",
|
|
407
|
-
initial: "my-tina-app"
|
|
504
|
+
initial: "my-tina-app",
|
|
505
|
+
validate: (name2) => {
|
|
506
|
+
const { validForNewPackages, errors } = (0, import_validate_npm_package_name.default)(
|
|
507
|
+
import_node_path.default.basename(import_node_path.default.resolve(name2))
|
|
508
|
+
);
|
|
509
|
+
if (validForNewPackages)
|
|
510
|
+
return true;
|
|
511
|
+
return "Invalid project name: " + errors[0];
|
|
512
|
+
}
|
|
408
513
|
});
|
|
409
|
-
|
|
514
|
+
if (!Object.hasOwn(res, "name"))
|
|
515
|
+
(0, import_node_process.exit)(1);
|
|
516
|
+
projectName = res.name;
|
|
410
517
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
name: "example",
|
|
518
|
+
if (!template) {
|
|
519
|
+
const res = await (0, import_prompts.default)({
|
|
520
|
+
name: "template",
|
|
415
521
|
type: "select",
|
|
416
522
|
message: "What starter code would you like to use?",
|
|
417
|
-
choices:
|
|
523
|
+
choices: TEMPLATES
|
|
418
524
|
});
|
|
419
|
-
if (
|
|
420
|
-
console.error(import_chalk5.default.red("Input must be a string"));
|
|
525
|
+
if (!Object.hasOwn(res, "template"))
|
|
421
526
|
(0, import_node_process.exit)(1);
|
|
422
|
-
|
|
423
|
-
example = res2.example;
|
|
424
|
-
}
|
|
425
|
-
const chosenExample = EXAMPLES.find((x2) => x2.value === example);
|
|
426
|
-
if (!chosenExample) {
|
|
427
|
-
console.error(
|
|
428
|
-
`The example provided is not a valid example. Please provide one of the following; ${EXAMPLES.map(
|
|
429
|
-
(x2) => x2.value
|
|
430
|
-
)}`
|
|
431
|
-
);
|
|
527
|
+
template = TEMPLATES.find((_template) => _template.value === res.template);
|
|
432
528
|
}
|
|
433
529
|
await telemetry.submitRecord({
|
|
434
530
|
event: {
|
|
435
531
|
name: "create-tina-app:invoke",
|
|
436
|
-
|
|
437
|
-
|
|
532
|
+
template,
|
|
533
|
+
pkgManager
|
|
438
534
|
}
|
|
439
535
|
});
|
|
440
|
-
const
|
|
441
|
-
if (!await isWriteable(import_node_path.default.dirname(
|
|
442
|
-
|
|
443
|
-
"The application path is not writable, please check folder permissions and try again."
|
|
444
|
-
);
|
|
445
|
-
console.error(
|
|
446
|
-
"It is likely you do not have write permissions for this folder."
|
|
536
|
+
const rootDir = import_node_path.default.join(process.cwd(), projectName);
|
|
537
|
+
if (!await isWriteable(import_node_path.default.dirname(rootDir))) {
|
|
538
|
+
log.err(
|
|
539
|
+
"The application path is not writable, please check folder permissions and try again. It is likely you do not have write permissions for this folder."
|
|
447
540
|
);
|
|
448
541
|
process.exit(1);
|
|
449
542
|
}
|
|
450
|
-
const appName =
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
`The example provided is not a valid example. Please provide one of the following; ${EXAMPLES.map(
|
|
459
|
-
(x2) => x2.value
|
|
460
|
-
)}`
|
|
461
|
-
);
|
|
462
|
-
throw new Error("Invalid example");
|
|
543
|
+
const appName = await setupProjectDirectory(rootDir);
|
|
544
|
+
try {
|
|
545
|
+
await downloadTemplate(template, rootDir);
|
|
546
|
+
updateProjectPackageName(rootDir, projectName);
|
|
547
|
+
updateProjectPackageVersion(rootDir, "0.0.1");
|
|
548
|
+
} catch (err) {
|
|
549
|
+
log.err(`Failed to download template: ${err.message}`);
|
|
550
|
+
(0, import_node_process.exit)(1);
|
|
463
551
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
552
|
+
log.info("Installing packages.");
|
|
553
|
+
await install(rootDir, null, { packageManager: pkgManager, isOnline: true });
|
|
554
|
+
log.info("Initializing git repository.");
|
|
555
|
+
try {
|
|
556
|
+
if (initializeGit()) {
|
|
557
|
+
makeFirstCommit(rootDir);
|
|
558
|
+
log.info("Initialized git repository.");
|
|
559
|
+
}
|
|
560
|
+
} catch (err) {
|
|
561
|
+
log.err("Failed to initialize Git repository, skipping.");
|
|
473
562
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
)
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
);
|
|
493
|
-
console.log(
|
|
494
|
-
`\u2022 \u{1F58C}\uFE0F Extend Tina with custom field components: ${linkText(
|
|
495
|
-
"https://tina.io/docs/advanced/extending-tina/"
|
|
496
|
-
)}`
|
|
497
|
-
);
|
|
498
|
-
console.log(
|
|
499
|
-
`\u2022 \u{1F680} Deploy to Production: ${linkText("https://tina.io/docs/tina-cloud/")}`
|
|
500
|
-
);
|
|
501
|
-
};
|
|
563
|
+
log.success("Starter successfully created!");
|
|
564
|
+
log.log(TextStyles.bold("\nTo launch your app, run:\n"));
|
|
565
|
+
log.cmd(`cd ${appName}
|
|
566
|
+
${pkgManager} run dev`);
|
|
567
|
+
log.log(`
|
|
568
|
+
Next steps:
|
|
569
|
+
\u2022 \u{1F4DD} Edit some content on ${TextStyles.link(
|
|
570
|
+
"http://localhost:3000"
|
|
571
|
+
)} (See ${TextStyles.link("https://tina.io/docs/using-tina-editor")})
|
|
572
|
+
\u2022 \u{1F4D6} Learn the basics: ${TextStyles.link("https://tina.io/docs/schema/")}
|
|
573
|
+
\u2022 \u{1F58C}\uFE0F Extend Tina with custom field components: ${TextStyles.link(
|
|
574
|
+
"https://tina.io/docs/advanced/extending-tina/"
|
|
575
|
+
)}
|
|
576
|
+
\u2022 \u{1F680} Deploy to Production: ${TextStyles.link(
|
|
577
|
+
"https://tina.io/docs/tina-cloud/"
|
|
578
|
+
)}
|
|
579
|
+
`);
|
|
580
|
+
}
|
|
502
581
|
run();
|
|
503
582
|
// Annotate the CommonJS export names for ESM import in node:
|
|
504
583
|
0 && (module.exports = {
|
|
584
|
+
PKG_MANAGERS,
|
|
505
585
|
run
|
|
506
586
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type BaseExample = {
|
|
2
|
+
title: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type InternalTemplate = BaseExample & {
|
|
7
|
+
isInternal: true;
|
|
8
|
+
};
|
|
9
|
+
export type ExternalTemplate = BaseExample & {
|
|
10
|
+
isInternal: false;
|
|
11
|
+
gitURL: string;
|
|
12
|
+
};
|
|
13
|
+
export type Template = InternalTemplate | ExternalTemplate;
|
|
14
|
+
export declare const TEMPLATES: Template[];
|
|
15
|
+
export declare function downloadTemplate(template: Template, root: string): Promise<void>;
|
|
16
|
+
export {};
|
package/dist/util/fileUtil.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
1
|
export declare function isWriteable(directory: string): Promise<boolean>;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
2
|
+
export declare function folderContainsInstallConflicts(root: string): string[];
|
|
3
|
+
export declare function setupProjectDirectory(dir: string): Promise<string>;
|
|
4
|
+
export declare function updateProjectPackageName(dir: string, name: string): void;
|
|
5
|
+
export declare function updateProjectPackageVersion(dir: string, version: string): void;
|
package/dist/util/git.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export declare const TextStyles: {
|
|
3
|
+
link: chalk.Chalk;
|
|
4
|
+
cmd: chalk.Chalk;
|
|
5
|
+
info: chalk.Chalk;
|
|
6
|
+
success: chalk.Chalk;
|
|
7
|
+
warn: chalk.Chalk;
|
|
8
|
+
err: chalk.Chalk;
|
|
9
|
+
bold: chalk.Chalk;
|
|
10
|
+
};
|
|
11
|
+
export declare class Logger {
|
|
12
|
+
log(message: string): void;
|
|
13
|
+
debug(message: string): void;
|
|
14
|
+
info(message: string): void;
|
|
15
|
+
success(message: string): void;
|
|
16
|
+
cmd(message: string): void;
|
|
17
|
+
warn(message: string): void;
|
|
18
|
+
err(message: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare const log: Logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tina-app",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/cross-spawn": "^6.0.6",
|
|
33
33
|
"@types/fs-extra": "^11.0.4",
|
|
34
|
-
"@types/node": "^
|
|
34
|
+
"@types/node": "^22.7.4",
|
|
35
35
|
"@types/prompts": "^2.4.9",
|
|
36
36
|
"@types/tar": "6.1.13",
|
|
37
|
-
"typescript": "^5.
|
|
38
|
-
"@tinacms/scripts": "1.2.
|
|
37
|
+
"typescript": "^5.6.2",
|
|
38
|
+
"@tinacms/scripts": "1.2.3"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"chalk": "4.1.2",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"got": "^14.4.2",
|
|
46
46
|
"prompts": "^2.4.2",
|
|
47
47
|
"tar": "7.4.0",
|
|
48
|
-
"
|
|
48
|
+
"validate-npm-package-name": "^5.0.1",
|
|
49
|
+
"@tinacms/metrics": "1.0.7"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"types": "pnpm tsc",
|
package/dist/examples.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
type BaseExample = {
|
|
5
|
-
title: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
export type InternalExample = BaseExample & {
|
|
10
|
-
isInternal: true;
|
|
11
|
-
};
|
|
12
|
-
export type ExternalExample = BaseExample & {
|
|
13
|
-
isInternal: false;
|
|
14
|
-
gitURL: string;
|
|
15
|
-
};
|
|
16
|
-
export type Example = InternalExample | ExternalExample;
|
|
17
|
-
export declare const EXAMPLES: Example[];
|
|
18
|
-
export declare const downloadExample: (example: Example, root: string) => Promise<void>;
|
|
19
|
-
export {};
|