Skip to content

Commit 426950b

Browse files
feat(add-angular-to-qwik): create the package
1 parent fdd9487 commit 426950b

16 files changed

+1752
-186
lines changed

README.md

Lines changed: 356 additions & 28 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
"@nx/linter": "16.5.0",
1414
"@nx/vite": "16.5.0",
1515
"@nx/workspace": "16.5.0",
16+
"@swc/cli": "~0.1.62",
17+
"@swc/core": "~1.3.51",
1618
"@types/node": "^18.16.1",
19+
"@types/yargs": "^17.0.24",
1720
"@typescript-eslint/eslint-plugin": "^5.60.1",
1821
"@typescript-eslint/parser": "^5.60.1",
1922
"@vitest/ui": "~0.32.0",
23+
"chalk": "^4.1.2",
2024
"eslint": "~8.15.0",
2125
"eslint-config-prettier": "8.1.0",
2226
"eslint-plugin-qwik": "~1.2.6",
@@ -34,9 +38,13 @@
3438
"vite": "~4.4.0",
3539
"vite-plugin-dts": "~2.3.0",
3640
"vite-tsconfig-paths": "~4.2.0",
37-
"vitest": "~0.32.0"
41+
"vitest": "~0.32.0",
42+
"yargs": "^17.7.2"
3843
},
3944
"nx": {
4045
"includedScripts": []
46+
},
47+
"dependencies": {
48+
"@swc/helpers": "~0.5.0"
4149
}
4250
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "../../.eslintrc",
3+
"rules": {},
4+
"ignorePatterns": ["!**/*"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {}
9+
},
10+
{
11+
"files": ["*.ts", "*.tsx"],
12+
"rules": {}
13+
},
14+
{
15+
"files": ["*.js", "*.jsx"],
16+
"rules": {}
17+
}
18+
]
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# add-angular-to-qwik
2+
3+
## What is It?
4+
5+
This is a simple utility package that allows runs an integration to add Angular to your existing Qwik application.
6+
7+
Run `npx add-angular-to-qwik@latest` to try it out!
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
import * as yargs from 'yargs';
3+
import * as chalk from 'chalk';
4+
5+
import { CreateWorkspaceOptions } from 'create-nx-workspace/';
6+
import {
7+
getPackageManagerCommand,
8+
detectPackageManager,
9+
} from 'nx/src/utils/package-manager';
10+
import { output } from 'create-nx-workspace/src/utils/output';
11+
import { readFileSync, unlinkSync, writeFileSync } from 'fs';
12+
import { execSync } from 'child_process';
13+
14+
interface Arguments extends CreateWorkspaceOptions {
15+
installMaterialExample: boolean;
16+
}
17+
18+
export const commandsObject: yargs.Argv<Arguments> = yargs
19+
.wrap(yargs.terminalWidth())
20+
.parserConfiguration({
21+
'strip-dashed': true,
22+
'dot-notation': true,
23+
})
24+
.command<Arguments>(
25+
// this is the default and only command
26+
'$0 [options]',
27+
'Add Angular to the Qwik workspace',
28+
(yargs) => [
29+
yargs.option('installMaterialExample', {
30+
describe: chalk.dim`Add dependencies for the Angular Material and qwikified example component, that uses it`,
31+
type: 'boolean',
32+
}),
33+
],
34+
35+
async (argv: yargs.ArgumentsCamelCase<Arguments>) => {
36+
await main(argv).catch((error) => {
37+
const { version } = require('../package.json');
38+
output.error({
39+
title: `Something went wrong! v${version}`,
40+
});
41+
throw error;
42+
});
43+
}
44+
)
45+
.help('help', chalk.dim`Show help`)
46+
.version(
47+
'version',
48+
chalk.dim`Show version`,
49+
require('../package.json').version
50+
) as yargs.Argv<Arguments>;
51+
52+
async function main(parsedArgs: yargs.Arguments<Arguments>) {
53+
let isQwikNxInstalled = false;
54+
const pm = getRelevantPackageManagerCommand();
55+
56+
output.log({
57+
title: `Adding Angular to your workspace.`,
58+
bodyLines: [
59+
'To make sure the command works reliably in all environments, and that the integration is applied correctly,',
60+
`We will run "${pm.install}" several times. Please wait.`,
61+
],
62+
});
63+
64+
try {
65+
// letting Nx think that's an Nx repo
66+
writeFileSync(
67+
'project.json',
68+
JSON.stringify({
69+
name: 'temp-project',
70+
sourceRoot: 'src',
71+
projectType: 'application',
72+
targets: {},
73+
})
74+
);
75+
76+
isQwikNxInstalled = checkIfPackageInstalled('qwik-nx');
77+
78+
if (!isQwikNxInstalled) {
79+
execSync(`${pm.add} qwik-nx@latest nx@latest`, { stdio: [0, 1, 2] });
80+
}
81+
const installMaterialExample = parsedArgs['installMaterialExample'];
82+
const installMaterialExampleFlag =
83+
installMaterialExample === true || installMaterialExample === false
84+
? `--installMaterialExample=${parsedArgs['installMaterialExample']}`
85+
: undefined;
86+
87+
const cmd = [
88+
'npx nx g qwik-nx:angular-in-app',
89+
'--project=temp-project',
90+
installMaterialExampleFlag,
91+
'--skipFormat',
92+
].filter(Boolean);
93+
execSync(cmd.join(' '), { stdio: [0, 1, 2] });
94+
} catch (error) {
95+
output.error({
96+
title: 'Failed to add angular to your repo',
97+
bodyLines: ['Reverting changes.', 'See original printed error above.'],
98+
});
99+
cleanup(isQwikNxInstalled, pm.uninstall);
100+
process.exit(1);
101+
}
102+
103+
cleanup(isQwikNxInstalled, pm.uninstall);
104+
105+
output.log({
106+
title: `Successfully added Angular integration to your repo`,
107+
});
108+
}
109+
110+
function checkIfPackageInstalled(pkg: string): boolean {
111+
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
112+
return (
113+
!!packageJson['dependencies']?.[pkg] ||
114+
!!packageJson['devDependencies']?.[pkg]
115+
);
116+
}
117+
118+
function getRelevantPackageManagerCommand() {
119+
const pm = detectPackageManager();
120+
const pmc = getPackageManagerCommand(pm);
121+
let uninstall: string;
122+
if (pm === 'npm') {
123+
uninstall = 'npm uninstall';
124+
} else if (pm === 'yarn') {
125+
uninstall = 'yarn remove';
126+
} else {
127+
uninstall = 'pnpm remove';
128+
}
129+
130+
return {
131+
install: pmc.install,
132+
add: pmc.add,
133+
uninstall,
134+
};
135+
}
136+
137+
function cleanup(isQwikNxInstalled: boolean, uninstallCmd: string) {
138+
unlinkSync('project.json');
139+
if (!isQwikNxInstalled) {
140+
execSync(`${uninstallCmd} qwik-nx nx`, { stdio: [0, 1, 2] });
141+
}
142+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { commandsObject } from './add-angular-to-qwik';
4+
5+
commandsObject.argv;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable */
2+
export default {
3+
transform: {
4+
'^.+\\.[tj]sx?$': 'ts-jest',
5+
},
6+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
7+
globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' } },
8+
displayName: 'add-angular-to-qwik',
9+
testEnvironment: 'node',
10+
preset: '../../jest.preset.js',
11+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "add-angular-to-qwik",
3+
"version": "0.1.3",
4+
"private": false,
5+
"description": "Adds Angular to the Qwik repo",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/QwikDev/qwik-angular.git",
9+
"directory": "packages/add-angular-to-qwik"
10+
},
11+
"keywords": [
12+
"Qwik",
13+
"Angular",
14+
"Web",
15+
"CLI"
16+
],
17+
"bin": {
18+
"add-angular-to-qwik": "./bin/index.js"
19+
},
20+
"author": "Dmitriy Stepanenko",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/QwikDev/qwik-angular/issues"
24+
},
25+
"homepage": "https://github.com/QwikDev/qwik-angular",
26+
"peerDependencies": {
27+
"qwik-nx": "^1.0.9"
28+
},
29+
"publishConfig": {
30+
"access": "public",
31+
"provenance": true
32+
}
33+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"name": "add-angular-to-qwik",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/add-angular-to-qwik",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nx/js:tsc",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/packages/add-angular-to-qwik",
12+
"main": "packages/add-angular-to-qwik/bin/add-angular-to-qwik.ts",
13+
"tsConfig": "packages/add-angular-to-qwik/tsconfig.lib.json",
14+
"assets": [
15+
"packages/add-angular-to-qwik/README.md",
16+
{
17+
"input": "packages/add-angular-to-qwik",
18+
"glob": "**/files/**",
19+
"output": "/"
20+
},
21+
{
22+
"input": "packages/add-angular-to-qwik",
23+
"glob": "**/files/**/.gitkeep",
24+
"output": "/"
25+
},
26+
{
27+
"input": "packages/add-angular-to-qwik",
28+
"glob": "**/*.json",
29+
"ignore": ["**/tsconfig*.json", "project.json", ".eslintrc.json"],
30+
"output": "/"
31+
},
32+
{
33+
"input": "packages/add-angular-to-qwik",
34+
"glob": "**/*.js",
35+
"ignore": ["**/jest.config.js"],
36+
"output": "/"
37+
},
38+
{
39+
"input": "packages/add-angular-to-qwik",
40+
"glob": "**/*.d.ts",
41+
"output": "/"
42+
},
43+
{
44+
"input": "",
45+
"glob": "LICENSE",
46+
"output": "/"
47+
}
48+
],
49+
"updateBuildableProjectDepsInPackageJson": true
50+
}
51+
},
52+
"lint": {
53+
"executor": "@nx/linter:eslint",
54+
"options": {
55+
"lintFilePatterns": [
56+
"packages/add-angular-to-qwik/**/*.ts",
57+
"packages/add-angular-to-qwik/**/*.spec.ts",
58+
"packages/add-angular-to-qwik/**/*_spec.ts",
59+
"packages/add-angular-to-qwik/**/*.spec.tsx",
60+
"packages/add-angular-to-qwik/**/*.spec.js",
61+
"packages/add-angular-to-qwik/**/*.spec.jsx",
62+
"packages/add-angular-to-qwik/**/*.d.ts"
63+
]
64+
},
65+
"outputs": ["{options.outputFile}"]
66+
},
67+
"version": {
68+
"executor": "@jscutlery/semver:version",
69+
"options": {}
70+
},
71+
"version-publish": {
72+
"executor": "@jscutlery/semver:version",
73+
"options": {
74+
"noVerify": true,
75+
"push": false,
76+
"releaseAs": "patch",
77+
"postTargets": [
78+
"add-angular-to-qwik:publish",
79+
"add-angular-to-qwik:push-to-github"
80+
]
81+
}
82+
},
83+
"publish": {
84+
"executor": "ngx-deploy-npm:deploy",
85+
"options": {
86+
"access": "public"
87+
},
88+
"configurations": {
89+
"local": {
90+
"registry": "http://localhost:4873"
91+
}
92+
}
93+
},
94+
"push-to-github": {
95+
"executor": "@jscutlery/semver:github",
96+
"options": {
97+
"tag": "${tag}",
98+
"notes": "${notes}"
99+
}
100+
}
101+
},
102+
"implicitDependencies": []
103+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"types": ["node", "jest"],
5+
"strict": true
6+
},
7+
"include": [],
8+
"files": [],
9+
"references": [
10+
{
11+
"path": "./tsconfig.lib.json"
12+
},
13+
{
14+
"path": "./tsconfig.spec.json"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)