create-turbo 1.7.0-canary.3 → 1.7.0-canary.4
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.js +418 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
@@ -0,0 +1,418 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
18
|
+
|
19
|
+
// src/index.ts
|
20
|
+
var path2 = __toESM(require("path"));
|
21
|
+
var import_execa = __toESM(require("execa"));
|
22
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
23
|
+
var import_inquirer = __toESM(require("inquirer"));
|
24
|
+
var import_ora = __toESM(require("ora"));
|
25
|
+
var import_meow = __toESM(require("meow"));
|
26
|
+
var import_semver = require("semver");
|
27
|
+
var import_gradient_string = __toESM(require("gradient-string"));
|
28
|
+
var import_update_check = __toESM(require("update-check"));
|
29
|
+
var import_chalk = __toESM(require("chalk"));
|
30
|
+
|
31
|
+
// package.json
|
32
|
+
var package_default = {
|
33
|
+
name: "create-turbo",
|
34
|
+
version: "1.7.0-canary.4",
|
35
|
+
description: "Create a new Turborepo",
|
36
|
+
homepage: "https://turbo.build/repo",
|
37
|
+
license: "MPL-2.0",
|
38
|
+
repository: {
|
39
|
+
type: "git",
|
40
|
+
url: "https://github.com/vercel/turbo",
|
41
|
+
directory: "packages/create-turbo"
|
42
|
+
},
|
43
|
+
bugs: {
|
44
|
+
url: "https://github.com/vercel/turbo/issues"
|
45
|
+
},
|
46
|
+
bin: {
|
47
|
+
"create-turbo": "dist/index.js"
|
48
|
+
},
|
49
|
+
scripts: {
|
50
|
+
build: "tsup",
|
51
|
+
test: "jest",
|
52
|
+
lint: "eslint src/**/*.ts",
|
53
|
+
"check-types": "tsc --noEmit"
|
54
|
+
},
|
55
|
+
dependencies: {
|
56
|
+
chalk: "2.4.2",
|
57
|
+
execa: "5.1.1",
|
58
|
+
"fs-extra": "^10.1.0",
|
59
|
+
"gradient-string": "^2.0.0",
|
60
|
+
inquirer: "^8.0.0",
|
61
|
+
meow: "^7.1.1",
|
62
|
+
ora: "4.1.1",
|
63
|
+
rimraf: "^3.0.2",
|
64
|
+
semver: "^7.3.5",
|
65
|
+
"update-check": "^1.5.4"
|
66
|
+
},
|
67
|
+
devDependencies: {
|
68
|
+
"@types/chalk-animation": "^1.6.0",
|
69
|
+
"@types/fs-extra": "^9.0.13",
|
70
|
+
"@types/gradient-string": "^1.1.2",
|
71
|
+
"@types/inquirer": "^7.3.1",
|
72
|
+
"@types/jest": "^27.4.0",
|
73
|
+
"@types/node": "^16.11.12",
|
74
|
+
"@types/rimraf": "^3.0.2",
|
75
|
+
"@types/semver": "^7.3.9",
|
76
|
+
eslint: "^7.23.0",
|
77
|
+
jest: "^27.4.3",
|
78
|
+
semver: "^7.3.5",
|
79
|
+
"strip-ansi": "^6.0.1",
|
80
|
+
"ts-jest": "^27.1.1",
|
81
|
+
tsconfig: "workspace:*",
|
82
|
+
tsup: "^5.10.3",
|
83
|
+
typescript: "^4.5.5"
|
84
|
+
},
|
85
|
+
files: [
|
86
|
+
"dist",
|
87
|
+
"templates"
|
88
|
+
]
|
89
|
+
};
|
90
|
+
|
91
|
+
// src/shouldUseYarn.ts
|
92
|
+
var import_child_process = require("child_process");
|
93
|
+
function shouldUseYarn() {
|
94
|
+
try {
|
95
|
+
const userAgent = process.env.npm_config_user_agent;
|
96
|
+
if (userAgent && userAgent.startsWith("yarn")) {
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
(0, import_child_process.execSync)("yarnpkg --version", { stdio: "ignore" });
|
100
|
+
return true;
|
101
|
+
} catch (e) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
// src/shouldUsePnpm.ts
|
107
|
+
var import_child_process2 = require("child_process");
|
108
|
+
function shouldUsePnpm() {
|
109
|
+
try {
|
110
|
+
const userAgent = process.env.npm_config_user_agent;
|
111
|
+
if (userAgent && userAgent.startsWith("pnpm")) {
|
112
|
+
return true;
|
113
|
+
}
|
114
|
+
(0, import_child_process2.execSync)("pnpm --version", { stdio: "ignore" });
|
115
|
+
return true;
|
116
|
+
} catch (e) {
|
117
|
+
return false;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
// src/git.ts
|
122
|
+
var import_child_process3 = require("child_process");
|
123
|
+
var import_path = __toESM(require("path"));
|
124
|
+
var import_rimraf = __toESM(require("rimraf"));
|
125
|
+
function isInGitRepository() {
|
126
|
+
try {
|
127
|
+
(0, import_child_process3.execSync)("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
128
|
+
return true;
|
129
|
+
} catch (_) {
|
130
|
+
}
|
131
|
+
return false;
|
132
|
+
}
|
133
|
+
function isInMercurialRepository() {
|
134
|
+
try {
|
135
|
+
(0, import_child_process3.execSync)("hg --cwd . root", { stdio: "ignore" });
|
136
|
+
return true;
|
137
|
+
} catch (_) {
|
138
|
+
}
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
function tryGitInit(root) {
|
142
|
+
let didInit = false;
|
143
|
+
try {
|
144
|
+
(0, import_child_process3.execSync)("git --version", { stdio: "ignore" });
|
145
|
+
if (isInGitRepository() || isInMercurialRepository()) {
|
146
|
+
return false;
|
147
|
+
}
|
148
|
+
(0, import_child_process3.execSync)("git init", { stdio: "ignore" });
|
149
|
+
didInit = true;
|
150
|
+
(0, import_child_process3.execSync)("git checkout -b main", { stdio: "ignore" });
|
151
|
+
(0, import_child_process3.execSync)("git add -A", { stdio: "ignore" });
|
152
|
+
(0, import_child_process3.execSync)('git commit -m "Initial commit from Create Turborepo"', {
|
153
|
+
stdio: "ignore"
|
154
|
+
});
|
155
|
+
return true;
|
156
|
+
} catch (e) {
|
157
|
+
if (didInit) {
|
158
|
+
try {
|
159
|
+
import_rimraf.default.sync(import_path.default.join(root, ".git"));
|
160
|
+
} catch (_) {
|
161
|
+
}
|
162
|
+
}
|
163
|
+
return false;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
// src/constants.ts
|
168
|
+
var PACKAGE_MANAGERS = {
|
169
|
+
npm: [
|
170
|
+
{
|
171
|
+
name: "npm",
|
172
|
+
template: "npm",
|
173
|
+
command: "npm",
|
174
|
+
installArgs: ["install"],
|
175
|
+
version: "latest",
|
176
|
+
executable: "npx",
|
177
|
+
semver: "*"
|
178
|
+
}
|
179
|
+
],
|
180
|
+
pnpm: [
|
181
|
+
{
|
182
|
+
name: "pnpm6",
|
183
|
+
template: "pnpm",
|
184
|
+
command: "pnpm",
|
185
|
+
installArgs: ["install"],
|
186
|
+
version: "latest-6",
|
187
|
+
executable: "pnpx",
|
188
|
+
semver: "6.x"
|
189
|
+
},
|
190
|
+
{
|
191
|
+
name: "pnpm",
|
192
|
+
template: "pnpm",
|
193
|
+
command: "pnpm",
|
194
|
+
installArgs: ["install"],
|
195
|
+
version: "latest",
|
196
|
+
executable: "pnpm dlx",
|
197
|
+
semver: ">=7"
|
198
|
+
}
|
199
|
+
],
|
200
|
+
yarn: [
|
201
|
+
{
|
202
|
+
name: "yarn",
|
203
|
+
template: "yarn",
|
204
|
+
command: "yarn",
|
205
|
+
installArgs: ["install"],
|
206
|
+
version: "1.x",
|
207
|
+
executable: "npx",
|
208
|
+
semver: "<2"
|
209
|
+
},
|
210
|
+
{
|
211
|
+
name: "berry",
|
212
|
+
template: "berry",
|
213
|
+
command: "yarn",
|
214
|
+
installArgs: ["install", "--no-immutable"],
|
215
|
+
version: "stable",
|
216
|
+
executable: "yarn dlx",
|
217
|
+
semver: ">=2"
|
218
|
+
}
|
219
|
+
]
|
220
|
+
};
|
221
|
+
|
222
|
+
// src/getPackageManagerVersion.ts
|
223
|
+
var import_child_process4 = require("child_process");
|
224
|
+
var getPackageManagerVersion = (command) => {
|
225
|
+
return (0, import_child_process4.execSync)(`${command} --version`).toString().trim();
|
226
|
+
};
|
227
|
+
|
228
|
+
// src/index.ts
|
229
|
+
var turboGradient = (0, import_gradient_string.default)("#0099F7", "#F11712");
|
230
|
+
var help = `
|
231
|
+
Usage:
|
232
|
+
$ npx create-turbo [flags...] [<dir>]
|
233
|
+
|
234
|
+
If <dir> is not provided up front you will be prompted for it.
|
235
|
+
|
236
|
+
Flags:
|
237
|
+
--use-npm Explicitly tell the CLI to bootstrap the app using npm
|
238
|
+
--use-pnpm Explicitly tell the CLI to bootstrap the app using pnpm
|
239
|
+
--use-yarn Explicitly tell the CLI to bootstrap the app using yarn
|
240
|
+
--no-install Explicitly do not run the package manager's install command
|
241
|
+
--help, -h Show this help message
|
242
|
+
--version, -v Show the version of this script
|
243
|
+
`;
|
244
|
+
run().then(notifyUpdate).catch(async (reason) => {
|
245
|
+
console.log();
|
246
|
+
console.log("Aborting installation.");
|
247
|
+
if (reason.command) {
|
248
|
+
console.log(` ${import_chalk.default.cyan(reason.command)} has failed.`);
|
249
|
+
} else {
|
250
|
+
console.log(import_chalk.default.red("Unexpected error. Please report it as a bug:"));
|
251
|
+
console.log(reason);
|
252
|
+
}
|
253
|
+
console.log();
|
254
|
+
await notifyUpdate();
|
255
|
+
process.exit(1);
|
256
|
+
});
|
257
|
+
async function run() {
|
258
|
+
let { input, flags } = (0, import_meow.default)(help, {
|
259
|
+
booleanDefault: void 0,
|
260
|
+
flags: {
|
261
|
+
help: { type: "boolean", default: false, alias: "h" },
|
262
|
+
useNpm: { type: "boolean", default: false },
|
263
|
+
usePnpm: { type: "boolean", default: false },
|
264
|
+
useYarn: { type: "boolean", default: false },
|
265
|
+
install: { type: "boolean", default: true },
|
266
|
+
version: { type: "boolean", default: false, alias: "v" }
|
267
|
+
}
|
268
|
+
});
|
269
|
+
console.log(import_chalk.default.bold(turboGradient(`
|
270
|
+
>>> TURBOREPO
|
271
|
+
`)));
|
272
|
+
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
273
|
+
console.log(">>> Welcome to Turborepo! Let's get you set up with a new codebase.");
|
274
|
+
console.log();
|
275
|
+
let projectDir = path2.resolve(process.cwd(), input.length > 0 ? input[0] : (await import_inquirer.default.prompt([
|
276
|
+
{
|
277
|
+
type: "input",
|
278
|
+
name: "dir",
|
279
|
+
message: "Where would you like to create your turborepo?",
|
280
|
+
default: "./my-turborepo"
|
281
|
+
}
|
282
|
+
])).dir);
|
283
|
+
const projectName = path2.basename(projectDir);
|
284
|
+
const isYarnInstalled = shouldUseYarn();
|
285
|
+
const isPnpmInstalled = shouldUsePnpm();
|
286
|
+
let answers;
|
287
|
+
if (flags.useNpm) {
|
288
|
+
answers = { packageManager: "npm" };
|
289
|
+
} else if (flags.usePnpm) {
|
290
|
+
answers = { packageManager: "pnpm" };
|
291
|
+
} else if (flags.useYarn) {
|
292
|
+
answers = { packageManager: "yarn" };
|
293
|
+
} else {
|
294
|
+
answers = await import_inquirer.default.prompt([
|
295
|
+
{
|
296
|
+
name: "packageManager",
|
297
|
+
type: "list",
|
298
|
+
message: "Which package manager do you want to use?",
|
299
|
+
choices: [
|
300
|
+
{ name: "npm", value: "npm" },
|
301
|
+
{
|
302
|
+
name: "pnpm",
|
303
|
+
value: "pnpm",
|
304
|
+
disabled: !isPnpmInstalled && "not installed"
|
305
|
+
},
|
306
|
+
{
|
307
|
+
name: "yarn",
|
308
|
+
value: "yarn",
|
309
|
+
disabled: !isYarnInstalled && "not installed"
|
310
|
+
}
|
311
|
+
]
|
312
|
+
}
|
313
|
+
]);
|
314
|
+
}
|
315
|
+
let relativeProjectDir = path2.relative(process.cwd(), projectDir);
|
316
|
+
let projectDirIsCurrentDir = relativeProjectDir === "";
|
317
|
+
if (!projectDirIsCurrentDir) {
|
318
|
+
if (import_fs_extra.default.existsSync(projectDir) && import_fs_extra.default.readdirSync(projectDir).length !== 0) {
|
319
|
+
console.log(`\uFE0F\u{1F6A8} Oops, "${relativeProjectDir}" already exists. Please try again with a different directory.`);
|
320
|
+
process.exit(1);
|
321
|
+
} else {
|
322
|
+
import_fs_extra.default.mkdirSync(projectDir, { recursive: true });
|
323
|
+
}
|
324
|
+
}
|
325
|
+
let sharedTemplate = path2.resolve(__dirname, "../templates", `_shared_ts`);
|
326
|
+
import_fs_extra.default.copySync(sharedTemplate, projectDir, { recursive: true });
|
327
|
+
let packageManagerVersion = getPackageManagerVersion(answers.packageManager);
|
328
|
+
let packageManagerConfigs = PACKAGE_MANAGERS[answers.packageManager];
|
329
|
+
let packageManager = packageManagerConfigs.find((packageManager2) => (0, import_semver.satisfies)(packageManagerVersion, packageManager2.semver));
|
330
|
+
if (!packageManager) {
|
331
|
+
throw new Error("Unsupported package manager version.");
|
332
|
+
}
|
333
|
+
let packageManagerTemplate = path2.resolve(__dirname, "../templates", packageManager.template);
|
334
|
+
if (import_fs_extra.default.existsSync(packageManagerTemplate)) {
|
335
|
+
import_fs_extra.default.copySync(packageManagerTemplate, projectDir, {
|
336
|
+
recursive: true,
|
337
|
+
overwrite: true
|
338
|
+
});
|
339
|
+
}
|
340
|
+
import_fs_extra.default.renameSync(path2.join(projectDir, "gitignore"), path2.join(projectDir, ".gitignore"));
|
341
|
+
let sharedPkg = require(path2.join(sharedTemplate, "package.json"));
|
342
|
+
let projectPkg = require(path2.join(projectDir, "package.json"));
|
343
|
+
["dependencies", "devDependencies"].forEach((pkgKey) => {
|
344
|
+
sharedPkg[pkgKey] = {
|
345
|
+
...sharedPkg[pkgKey],
|
346
|
+
...projectPkg[pkgKey]
|
347
|
+
};
|
348
|
+
});
|
349
|
+
sharedPkg.packageManager = `${packageManager.command}@${packageManagerVersion}`;
|
350
|
+
sharedPkg.name = projectName;
|
351
|
+
import_fs_extra.default.writeFileSync(path2.join(projectDir, "package.json"), JSON.stringify(sharedPkg, null, 2));
|
352
|
+
console.log();
|
353
|
+
console.log(`>>> Created a new turborepo with the following:`);
|
354
|
+
console.log();
|
355
|
+
console.log(` - ${import_chalk.default.bold("apps/web")}: Next.js with TypeScript`);
|
356
|
+
console.log(` - ${import_chalk.default.bold("apps/docs")}: Next.js with TypeScript`);
|
357
|
+
console.log(` - ${import_chalk.default.bold("packages/ui")}: Shared React component library`);
|
358
|
+
console.log(` - ${import_chalk.default.bold("packages/eslint-config-custom")}: Shared configuration (ESLint)`);
|
359
|
+
console.log(` - ${import_chalk.default.bold("packages/tsconfig")}: Shared TypeScript \`tsconfig.json\``);
|
360
|
+
console.log();
|
361
|
+
if (flags.install) {
|
362
|
+
const spinner = (0, import_ora.default)({
|
363
|
+
text: "Installing dependencies...",
|
364
|
+
spinner: {
|
365
|
+
frames: [" ", "> ", ">> ", ">>>"]
|
366
|
+
}
|
367
|
+
}).start();
|
368
|
+
await (0, import_execa.default)(`${packageManager.command}`, packageManager.installArgs, {
|
369
|
+
stdio: "ignore",
|
370
|
+
cwd: projectDir
|
371
|
+
});
|
372
|
+
spinner.stop();
|
373
|
+
}
|
374
|
+
process.chdir(projectDir);
|
375
|
+
tryGitInit(relativeProjectDir);
|
376
|
+
if (projectDirIsCurrentDir) {
|
377
|
+
console.log(`${import_chalk.default.bold(turboGradient(">>> Success!"))} Your new Turborepo is ready.`);
|
378
|
+
console.log("Inside this directory, you can run several commands:");
|
379
|
+
} else {
|
380
|
+
console.log(`${import_chalk.default.bold(turboGradient(">>> Success!"))} Created a new Turborepo at "${relativeProjectDir}".`);
|
381
|
+
console.log("Inside that directory, you can run several commands:");
|
382
|
+
}
|
383
|
+
console.log();
|
384
|
+
console.log(import_chalk.default.cyan(` ${packageManager.command} run build`));
|
385
|
+
console.log(` Build all apps and packages`);
|
386
|
+
console.log();
|
387
|
+
console.log(import_chalk.default.cyan(` ${packageManager.command} run dev`));
|
388
|
+
console.log(` Develop all apps and packages`);
|
389
|
+
console.log();
|
390
|
+
console.log(`Turborepo will cache locally by default. For an additional`);
|
391
|
+
console.log(`speed boost, enable Remote Caching with Vercel by`);
|
392
|
+
console.log(`entering the following command:`);
|
393
|
+
console.log();
|
394
|
+
console.log(import_chalk.default.cyan(` ${packageManager.executable} turbo login`));
|
395
|
+
console.log();
|
396
|
+
console.log(`We suggest that you begin by typing:`);
|
397
|
+
console.log();
|
398
|
+
if (!projectDirIsCurrentDir) {
|
399
|
+
console.log(` ${import_chalk.default.cyan("cd")} ${relativeProjectDir}`);
|
400
|
+
}
|
401
|
+
console.log(import_chalk.default.cyan(` ${packageManager.executable} turbo login`));
|
402
|
+
console.log();
|
403
|
+
}
|
404
|
+
var update = (0, import_update_check.default)(package_default).catch(() => null);
|
405
|
+
async function notifyUpdate() {
|
406
|
+
try {
|
407
|
+
const res = await update;
|
408
|
+
if (res == null ? void 0 : res.latest) {
|
409
|
+
const isYarn = shouldUseYarn();
|
410
|
+
console.log();
|
411
|
+
console.log(import_chalk.default.yellow.bold("A new version of `create-turbo` is available!"));
|
412
|
+
console.log("You can update by running: " + import_chalk.default.cyan(isYarn ? "yarn global add create-turbo" : "npm i -g create-turbo"));
|
413
|
+
console.log();
|
414
|
+
}
|
415
|
+
process.exit();
|
416
|
+
} catch {
|
417
|
+
}
|
418
|
+
}
|