Skip to content

Commit 4c47d1a

Browse files
feat: add yarn v3 support (#84)
Co-authored-by: pinkcig <fayekllr@gmail.com>
1 parent aeecd8e commit 4c47d1a

File tree

5 files changed

+161
-133
lines changed

5 files changed

+161
-133
lines changed

.all-contributorsrc

+103-131
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,105 @@
11
{
2-
"projectName": "cli",
3-
"projectOwner": "sapphiredev",
4-
"repoType": "github",
5-
"repoHost": "https://github.com",
6-
"files": [
7-
"README.md"
8-
],
9-
"imageSize": 100,
10-
"commit": true,
11-
"commitConvention": "angular",
12-
"contributors": [
13-
{
14-
"login": "favna",
15-
"name": "Jeroen Claassens",
16-
"avatar_url": "https://avatars3.githubusercontent.com/u/4019718?v=4",
17-
"profile": "https://favware.tech/",
18-
"contributions": [
19-
"code",
20-
"doc",
21-
"infra",
22-
"projectManagement",
23-
"plugin"
24-
]
25-
},
26-
{
27-
"login": "enxg",
28-
"name": "Enes Genç",
29-
"avatar_url": "https://avatars.githubusercontent.com/u/61084101?v=4",
30-
"profile": "https://github.com/enxg",
31-
"contributions": [
32-
"code",
33-
"doc",
34-
"infra",
35-
"ideas",
36-
"example",
37-
"tutorial"
38-
]
39-
},
40-
{
41-
"login": "kaname-png",
42-
"name": "Kaname",
43-
"avatar_url": "https://avatars.githubusercontent.com/u/56084970?v=4",
44-
"profile": "https://kaname.netlify.app",
45-
"contributions": [
46-
"code"
47-
]
48-
},
49-
{
50-
"login": "UndiedGamer",
51-
"name": "UndiedGamer",
52-
"avatar_url": "https://avatars.githubusercontent.com/u/84702365?v=4",
53-
"profile": "https://github.com/UndiedGamer",
54-
"contributions": [
55-
"doc"
56-
]
57-
},
58-
{
59-
"login": "Lioness100",
60-
"name": "Lioness100",
61-
"avatar_url": "https://avatars.githubusercontent.com/u/65814829?v=4",
62-
"profile": "https://github.com/Lioness100",
63-
"contributions": [
64-
"doc"
65-
]
66-
},
67-
{
68-
"login": "megatank58",
69-
"name": "megatank58",
70-
"avatar_url": "https://avatars.githubusercontent.com/u/51410502?v=4",
71-
"profile": "https://megatank58.me/",
72-
"contributions": [
73-
"code"
74-
]
75-
},
76-
{
77-
"login": "renovate-bot",
78-
"name": "WhiteSource Renovate",
79-
"avatar_url": "https://avatars.githubusercontent.com/u/25180681?v=4",
80-
"profile": "https://renovate.whitesourcesoftware.com/",
81-
"contributions": [
82-
"maintenance"
83-
]
84-
},
85-
{
86-
"login": "renovate[bot]",
87-
"name": "renovate[bot]",
88-
"avatar_url": "https://avatars.githubusercontent.com/in/2740?v=4",
89-
"profile": "https://github.com/apps/renovate",
90-
"contributions": [
91-
"maintenance"
92-
]
93-
},
94-
{
95-
"login": "allcontributors[bot]",
96-
"name": "allcontributors[bot]",
97-
"avatar_url": "https://avatars.githubusercontent.com/in/23186?v=4",
98-
"profile": "https://github.com/apps/allcontributors",
99-
"contributions": [
100-
"doc"
101-
]
102-
},
103-
{
104-
"login": "depfu[bot]",
105-
"name": "depfu[bot]",
106-
"avatar_url": "https://avatars.githubusercontent.com/in/715?v=4",
107-
"profile": "https://github.com/apps/depfu",
108-
"contributions": [
109-
"maintenance"
110-
]
111-
},
112-
{
113-
"login": "Allianaab2m",
114-
"name": "Alliana",
115-
"avatar_url": "https://avatars.githubusercontent.com/u/56180684?v=4",
116-
"profile": "https://allianaab2m.github.io/",
117-
"contributions": [
118-
"code"
119-
]
120-
},
121-
{
122-
"login": "MajesticString",
123-
"name": "Harry Allen",
124-
"avatar_url": "https://avatars.githubusercontent.com/u/66224939?v=4",
125-
"profile": "https://github.com/MajesticString",
126-
"contributions": [
127-
"code"
128-
]
129-
}
130-
],
131-
"contributorsPerLine": 7,
132-
"skipCi": true
2+
"projectName": "cli",
3+
"projectOwner": "sapphiredev",
4+
"repoType": "github",
5+
"repoHost": "https://github.com",
6+
"files": ["README.md"],
7+
"imageSize": 100,
8+
"commit": true,
9+
"commitConvention": "angular",
10+
"contributors": [
11+
{
12+
"login": "favna",
13+
"name": "Jeroen Claassens",
14+
"avatar_url": "https://avatars3.githubusercontent.com/u/4019718?v=4",
15+
"profile": "https://favware.tech/",
16+
"contributions": ["code", "doc", "infra", "projectManagement", "plugin"]
17+
},
18+
{
19+
"login": "enxg",
20+
"name": "Enes Genç",
21+
"avatar_url": "https://avatars.githubusercontent.com/u/61084101?v=4",
22+
"profile": "https://github.com/enxg",
23+
"contributions": ["code", "doc", "infra", "ideas", "example", "tutorial"]
24+
},
25+
{
26+
"login": "kaname-png",
27+
"name": "Kaname",
28+
"avatar_url": "https://avatars.githubusercontent.com/u/56084970?v=4",
29+
"profile": "https://kaname.netlify.app",
30+
"contributions": ["code"]
31+
},
32+
{
33+
"login": "UndiedGamer",
34+
"name": "UndiedGamer",
35+
"avatar_url": "https://avatars.githubusercontent.com/u/84702365?v=4",
36+
"profile": "https://github.com/UndiedGamer",
37+
"contributions": ["doc"]
38+
},
39+
{
40+
"login": "Lioness100",
41+
"name": "Lioness100",
42+
"avatar_url": "https://avatars.githubusercontent.com/u/65814829?v=4",
43+
"profile": "https://github.com/Lioness100",
44+
"contributions": ["doc"]
45+
},
46+
{
47+
"login": "megatank58",
48+
"name": "megatank58",
49+
"avatar_url": "https://avatars.githubusercontent.com/u/51410502?v=4",
50+
"profile": "https://megatank58.me/",
51+
"contributions": ["code"]
52+
},
53+
{
54+
"login": "renovate-bot",
55+
"name": "WhiteSource Renovate",
56+
"avatar_url": "https://avatars.githubusercontent.com/u/25180681?v=4",
57+
"profile": "https://renovate.whitesourcesoftware.com/",
58+
"contributions": ["maintenance"]
59+
},
60+
{
61+
"login": "renovate[bot]",
62+
"name": "renovate[bot]",
63+
"avatar_url": "https://avatars.githubusercontent.com/in/2740?v=4",
64+
"profile": "https://github.com/apps/renovate",
65+
"contributions": ["maintenance"]
66+
},
67+
{
68+
"login": "allcontributors[bot]",
69+
"name": "allcontributors[bot]",
70+
"avatar_url": "https://avatars.githubusercontent.com/in/23186?v=4",
71+
"profile": "https://github.com/apps/allcontributors",
72+
"contributions": ["doc"]
73+
},
74+
{
75+
"login": "depfu[bot]",
76+
"name": "depfu[bot]",
77+
"avatar_url": "https://avatars.githubusercontent.com/in/715?v=4",
78+
"profile": "https://github.com/apps/depfu",
79+
"contributions": ["maintenance"]
80+
},
81+
{
82+
"login": "Allianaab2m",
83+
"name": "Alliana",
84+
"avatar_url": "https://avatars.githubusercontent.com/u/56180684?v=4",
85+
"profile": "https://allianaab2m.github.io/",
86+
"contributions": ["code"]
87+
},
88+
{
89+
"login": "MajesticString",
90+
"name": "Harry Allen",
91+
"avatar_url": "https://avatars.githubusercontent.com/u/66224939?v=4",
92+
"profile": "https://github.com/MajesticString",
93+
"contributions": ["code"]
94+
},
95+
{
96+
"login": "pinkcig",
97+
"name": "Faye Keller",
98+
"avatar_url": "https://avatars.githubusercontent.com/u/62260409?v=4",
99+
"profile": "https://github.com/pinkcig",
100+
"contributions": ["code"]
101+
}
102+
],
103+
"contributorsPerLine": 7,
104+
"skipCi": true
133105
}

.github/husky/commit-msg

100644100755
File mode changed.

.github/husky/pre-commit

100644100755
File mode changed.

src/commands/new.ts

+53-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,48 @@ function installDeps(location: string, pm: string, verbose: boolean) {
4444
});
4545
}
4646

47+
function configureYarnRc(location: string) {
48+
return (name: string, value: string) => {
49+
return new Promise((resolve, reject) => {
50+
return exec(`yarn config set ${name} ${value}`, { cwd: `./${location}/` }, (e) => {
51+
if (e) return reject(e);
52+
return resolve(true);
53+
});
54+
});
55+
};
56+
}
57+
58+
function installYarnV3(location: string, verbose: boolean) {
59+
const yarnProcess = spawn('yarn', ['set', 'version', 'berry'], {
60+
stdio: verbose ? 'inherit' : undefined,
61+
cwd: `./${location}/`
62+
});
63+
64+
return new Promise((resolve, reject) => {
65+
yarnProcess.on('error', reject);
66+
67+
yarnProcess.on('exit', async (code) => {
68+
if (code === 0) {
69+
const configure = configureYarnRc(location);
70+
await Promise.all([configure('enableGlobalCache', 'true'), configure('nodeLinker', 'node-modules')]).catch(reject);
71+
72+
resolve(true);
73+
} else {
74+
reject(new Error('An unknown error occured while installing Yarn v3. Try running Sapphire CLI with "--verbose" flag.'));
75+
}
76+
});
77+
});
78+
}
79+
80+
function installYarnTypescriptPlugin(location: string) {
81+
return new Promise((resolve, reject) => {
82+
return exec('yarn plugin import typescript', { cwd: `./${location}/` }, (e) => {
83+
if (!e) return resolve(true);
84+
return reject(e);
85+
});
86+
});
87+
}
88+
4789
function initializeGitRepo(location: string) {
4890
return new Promise((resolve, reject) => {
4991
return exec('git init', { cwd: `./${location}/` }, (e) => {
@@ -115,14 +157,23 @@ export default async (name: string, flags: Record<string, boolean>) => {
115157

116158
const jobs: [() => any, string][] = [
117159
[() => cloneRepo(response.projectName, flags.verbose), 'Cloning the repository'],
118-
[stpJob, 'Setting up the project'],
119-
[() => installDeps(response.projectName, response.packageManager, flags.verbose), `Installing dependencies using ${response.packageManager}`]
160+
[stpJob, 'Setting up the project']
120161
];
121162

122163
if (response.git) {
123164
jobs.push([() => initializeGitRepo(response.projectName), 'Initializing git repo']);
124165
}
125166

167+
if (response.yarnV3) {
168+
jobs.push([() => installYarnV3(response.projectName, flags.verbose), 'Installing Yarn v3']);
169+
if (response.projectLang === 'ts') jobs.push([() => installYarnTypescriptPlugin(response.projectName), 'Installing Yarn Typescript Plugin']);
170+
}
171+
172+
jobs.push([
173+
() => installDeps(response.projectName, response.packageManager, flags.verbose),
174+
`Installing dependencies using ${response.packageManager}`
175+
]);
176+
126177
for (const [job, name] of jobs) {
127178
await runJob(job, name).catch(() => process.exit(1));
128179
}

src/prompts/PromptNew.ts

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export const PromptNew = (projectName: string, yarn: boolean) => {
5858
message: 'What package manager do you want to use?',
5959
choices: yarn ? pmChoices : pmChoices.slice().reverse()
6060
},
61+
{
62+
type: (prev) => (prev === 'Yarn' ? 'confirm' : false),
63+
name: 'yarnV3',
64+
message: 'Do you want to use Yarn v3?'
65+
},
6166
{
6267
type: 'confirm',
6368
name: 'git',

0 commit comments

Comments
 (0)