Skip to content

Commit 2aa5ff4

Browse files
committed
feat(cli): removed the need for nx.json
1 parent 590e9ef commit 2aa5ff4

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
lines changed

.changeset/nasty-swans-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'qwik-ui': patch
3+
---
4+
5+
Removed the generated `nx.json` after `qwik-ui init` command.
6+
Apparently, only an empty `nx: {}` in the package.json is enough.

packages/cli/bin/index.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import {
99
multiselect,
1010
outro,
1111
select,
12-
spinner,
1312
text,
1413
} from '@clack/prompts';
15-
import { getPackageManagerCommand, readJsonFile, workspaceRoot } from '@nx/devkit';
14+
import {
15+
getPackageManagerCommand,
16+
readJsonFile,
17+
workspaceRoot,
18+
writeJsonFile,
19+
} from '@nx/devkit';
1620

1721
import { execSync } from 'child_process';
18-
import { existsSync } from 'fs';
22+
import { existsSync, readFileSync, writeFileSync } from 'fs';
1923
import { bold, cyan, green, red } from 'kleur/colors';
2024
import yargs, { type CommandModule } from 'yargs';
2125
import {
@@ -188,6 +192,7 @@ async function handleInit() {
188192
}
189193

190194
// ADD QWIK UI CLI TO DEPENDENCIES
195+
log.info('Adding qwik-ui cli to package.json...');
191196
execSync(`${getPackageManagerCommand().addDev} qwik-ui@latest`, {
192197
stdio: 'inherit',
193198
});
@@ -209,6 +214,7 @@ async function handleInit() {
209214

210215
const packageTag = args['e2e'] ? 'e2e' : 'latest';
211216

217+
log.info(`Installing ${styledPackage}...`);
212218
execSync(`${getPackageManagerCommand().addDev} ${styledPackage}@${packageTag}`, {
213219
stdio: 'inherit',
214220
});
@@ -225,38 +231,35 @@ async function handleInit() {
225231
},
226232
);
227233

228-
await handleAdd(config.projectRoot, args['components'] as string);
234+
log.info('Tailwind configured.');
229235
}
230236

231237
async function installNxIfNeeded() {
232-
// eslint-disable-next-line @typescript-eslint/no-var-requires
233-
// const nxVersion = require('../package.json').dependencies['@nx/devkit'];
234-
235238
if (existsSync('nx.json')) {
236239
log.info('seems like nx.json already exists. cool!');
237240
} else {
238-
// const haveNxInstalled = cancelable(
239-
// await confirm({
240-
// message: 'Do you already have Nx installed? (required)',
241-
// initialValue: false,
242-
// }),
243-
// );
244-
245-
// if (!haveNxInstalled) {
246-
const initSpinner = spinner();
247241
log.info('Installing Nx...');
248-
initSpinner.start('Installing Nx...');
242+
249243
execSync(`${getPackageManagerCommand().addDev} nx@latest`, {
250244
stdio: 'inherit',
251245
});
252-
// TODO: Just add "nx: {} " to package.json and see if it still works
253-
execSync(`${getPackageManagerCommand().exec} nx init --interactive false`, {
254-
stdio: 'inherit',
255-
});
256-
initSpinner.stop('Installed Nx!');
246+
247+
const packageJson = await readJsonFile('package.json');
248+
packageJson['nx'] = {};
249+
await writeJsonFile('package.json', packageJson);
250+
251+
const ignorePath = '.gitignore';
252+
try {
253+
let contents = readFileSync(ignorePath, 'utf-8');
254+
if (!contents.includes('.nx/cache')) {
255+
contents = [contents, '', '.nx/cache'].join('\n');
256+
writeFileSync(ignorePath, contents, 'utf-8');
257+
}
258+
} catch {
259+
/* empty */
260+
}
257261
}
258262
log.success('nx init done');
259-
// }
260263
}
261264

262265
async function handleAdd(projectRoot?: string, componentsFromInit?: string) {

packages/cli/project.json

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,6 @@
4747
]
4848
}
4949
},
50-
"version-dry": {
51-
"executor": "@jscutlery/semver:version",
52-
"options": {
53-
"dryRun": true,
54-
"trackDeps": true,
55-
"noVerify": true,
56-
"skipCommit": true
57-
}
58-
},
59-
"version": {
60-
"executor": "@jscutlery/semver:version",
61-
"options": {
62-
"trackDeps": true,
63-
"noVerify": true
64-
}
65-
},
66-
"publish": {
67-
"dependsOn": ["build"],
68-
"executor": "ngx-deploy-npm:deploy",
69-
"options": {
70-
"access": "public"
71-
}
72-
},
7350
"test-generators": {
7451
"executor": "@nx/jest:jest",
7552
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],

0 commit comments

Comments
 (0)