This repository was archived by the owner on Jul 3, 2025. It is now read-only.
forked from avajs/create-ava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (64 loc) · 2.08 KB
/
Copy pathindex.js
File metadata and controls
78 lines (64 loc) · 2.08 KB
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
"use strict";
const path = require("path");
const execa = require("execa");
const hasYarn = require("has-yarn");
const readPkgUp = require("read-pkg-up");
const writePkg = require("write-pkg");
const DEFAULT_TEST_SCRIPT = 'echo "Error: no test specified" && exit 1';
module.exports = async (options = {}) => {
const packageResult =
readPkgUp.sync({
cwd: options.cwd,
normalize: false,
}) || {};
const packageJson = packageResult.package || {};
const packagePath =
packageResult.path ||
path.resolve(options.cwd || process.cwd(), "package.json");
const packageCwd = path.dirname(packagePath);
const args = options.args || [];
const cmd = "quyz" + (args.length > 0 ? " " + args.join(" ") : "");
packageJson.scripts = packageJson.scripts ? packageJson.scripts : {};
const s = packageJson.scripts;
if (s.test && s.test !== DEFAULT_TEST_SCRIPT) {
s.test = s.test.replace(/\bnode (test\/)?test\.js\b/, cmd);
if (!/\bquyz\b/.test(s.test)) {
s.test += ` && ${cmd}`;
}
} else {
s.test = cmd;
}
writePkg.sync(packagePath, packageJson, { normalize: false });
if (options.skipInstall) {
return;
}
const quyzTag = "quyz";
if (hasYarn(packageCwd)) {
const yarnArguments = [
"add",
quyzTag,
"--dev",
"--ignore-workspace-root-check"
];
try {
await execa("yarn", yarnArguments, {
cwd: packageCwd,
stdio: "inherit",
});
} catch (error) {
if (error.code === "ENOENT") {
console.error(
"This project uses Yarn but you don't seem to have Yarn installed.\nRun `npm install --global yarn` to install it."
);
return;
}
throw error;
}
return;
}
const npmArguments = ["install", "--save-dev", quyzTag];
await execa("npm", npmArguments, {
cwd: packageCwd,
stdio: "inherit",
});
};