@ng-cn/core 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-cn/core",
3
- "version": "1.0.01",
3
+ "version": "1.0.02",
4
4
  "description": "Beautifully designed Angular components built with Tailwind CSS v4 - The official Angular port of shadcn/ui",
5
5
  "keywords": [
6
6
  "angular",
@@ -65,11 +65,48 @@ ng g shadcn-angular:c button --path=src/components
65
65
  To build the schematics:
66
66
 
67
67
  ```bash
68
- npm run build:schematics
68
+ cd schematics
69
+ npx tsc -p tsconfig.json
69
70
  ```
70
71
 
71
72
  This compiles the TypeScript files in the `schematics` directory to JavaScript.
72
73
 
74
+ ### Testing
75
+
76
+ Run the test script to verify the schematics work correctly:
77
+
78
+ ```bash
79
+ cd schematics
80
+ node test-schematic.js
81
+ ```
82
+
83
+ This will:
84
+ - Create a mock Angular project with a tsconfig.json containing comments (like real projects)
85
+ - Run the ng-add schematic
86
+ - Verify all expected files are created
87
+ - Verify tsconfig path aliases are configured
88
+ - Verify styles are imported correctly
89
+ - Verify dependencies are added
90
+
91
+ ### Local Testing
92
+
93
+ To test the schematic locally with a real Angular project:
94
+
95
+ ```bash
96
+ # 1. Build the schematics
97
+ cd schematics && npx tsc -p tsconfig.json && cd ..
98
+
99
+ # 2. Create a test project
100
+ ng new test-app --style=scss --routing=true
101
+
102
+ # 3. Link the local package
103
+ cd test-app
104
+ npm link ../shadcn-angular
105
+
106
+ # 4. Run the schematic
107
+ ng add @ng-cn/core --skip-confirmation
108
+ ```
109
+
73
110
  ## Structure
74
111
 
75
112
  ```
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = ngAdd;
4
4
  const tasks_1 = require("@angular-devkit/schematics/tasks");
5
+ const jsonc_parser_1 = require("jsonc-parser");
5
6
  // CSS Variables template for shadcn theming
6
7
  const CSS_VARIABLES_TEMPLATE = `/* ng-cn/core - shadcn-angular styles */
7
8
  @use "tailwindcss";
@@ -253,7 +254,8 @@ function ngAdd(options) {
253
254
  context.logger.info('⚙️ TypeScript Config');
254
255
  const tsconfigPath = '/tsconfig.json';
255
256
  if (tree.exists(tsconfigPath)) {
256
- const tsconfig = JSON.parse(tree.read(tsconfigPath).toString('utf-8'));
257
+ const tsconfigContent = tree.read(tsconfigPath).toString('utf-8');
258
+ const tsconfig = (0, jsonc_parser_1.parse)(tsconfigContent);
257
259
  tsconfig.compilerOptions = tsconfig.compilerOptions || {};
258
260
  tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
259
261
  const pathAliases = {
@@ -1,5 +1,6 @@
1
1
  import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
2
2
  import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
3
+ import { parse as parseJsonc } from 'jsonc-parser';
3
4
 
4
5
  interface NgAddOptions {
5
6
  project?: string;
@@ -273,7 +274,8 @@ export function ngAdd(options: NgAddOptions): Rule {
273
274
 
274
275
  const tsconfigPath = '/tsconfig.json';
275
276
  if (tree.exists(tsconfigPath)) {
276
- const tsconfig = JSON.parse(tree.read(tsconfigPath)!.toString('utf-8'));
277
+ const tsconfigContent = tree.read(tsconfigPath)!.toString('utf-8');
278
+ const tsconfig = parseJsonc(tsconfigContent) as Record<string, any>;
277
279
  tsconfig.compilerOptions = tsconfig.compilerOptions || {};
278
280
  tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
279
281
 
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Test script for ng-add schematic
3
+ * Run with: node test-schematic.js
4
+ */
5
+
6
+ const { SchematicTestRunner } = require('@angular-devkit/schematics/testing');
7
+ const { HostTree } = require('@angular-devkit/schematics');
8
+ const path = require('path');
9
+
10
+ const collectionPath = path.join(__dirname, 'collection.json');
11
+
12
+ // Mock tsconfig.json with comments (typical Angular project)
13
+ const MOCK_TSCONFIG = `/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
14
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
15
+ {
16
+ "compileOnSave": false,
17
+ "compilerOptions": {
18
+ "outDir": "./dist/out-tsc",
19
+ "strict": true,
20
+ "noImplicitOverride": true,
21
+ "noPropertyAccessFromIndexSignature": true,
22
+ "noImplicitReturns": true,
23
+ "noFallthroughCasesInSwitch": true,
24
+ "skipLibCheck": true,
25
+ "isolatedModules": true,
26
+ "esModuleInterop": true,
27
+ "experimentalDecorators": true,
28
+ "moduleResolution": "bundler",
29
+ "importHelpers": true,
30
+ "target": "ES2022",
31
+ "module": "ES2022"
32
+ },
33
+ "angularCompilerOptions": {
34
+ "enableI18nLegacyMessageIdFormat": false,
35
+ "strictInjectionParameters": true,
36
+ "strictInputAccessModifiers": true,
37
+ "strictTemplates": true
38
+ }
39
+ }`;
40
+
41
+ const MOCK_PACKAGE_JSON = `{
42
+ "name": "test-angular",
43
+ "version": "0.0.0",
44
+ "scripts": {
45
+ "ng": "ng",
46
+ "start": "ng serve",
47
+ "build": "ng build"
48
+ },
49
+ "dependencies": {
50
+ "@angular/core": "^21.0.0"
51
+ },
52
+ "devDependencies": {}
53
+ }`;
54
+
55
+ const MOCK_STYLES_CSS = `/* You can add global styles to this file, and also import other style files */
56
+ `;
57
+
58
+ async function runTests() {
59
+ console.log('\n🧪 Testing ng-add schematic...\n');
60
+
61
+ const runner = new SchematicTestRunner('schematics', collectionPath);
62
+
63
+ // Create a mock project tree using HostTree
64
+ const appTree = new HostTree();
65
+ appTree.create('/package.json', MOCK_PACKAGE_JSON);
66
+ appTree.create('/tsconfig.json', MOCK_TSCONFIG);
67
+ appTree.create('/src/styles.css', MOCK_STYLES_CSS);
68
+
69
+ console.log('📁 Created mock project with:');
70
+ console.log(' - /package.json');
71
+ console.log(' - /tsconfig.json (with comments)');
72
+ console.log(' - /src/styles.css\n');
73
+
74
+ try {
75
+ // Run the ng-add schematic
76
+ const tree = await runner.runSchematic('ng-add', { skipInstall: true }, appTree);
77
+
78
+ console.log('✅ Schematic executed successfully!\n');
79
+
80
+ // Verify files were created
81
+ const expectedFiles = [
82
+ '/src/app/lib/utils/cn.ts',
83
+ '/src/app/lib/utils/index.ts',
84
+ '/src/app/lib/components/ui/.gitkeep',
85
+ '/src/ng-cn.scss'
86
+ ];
87
+
88
+ console.log('📄 Checking created files:');
89
+ for (const file of expectedFiles) {
90
+ if (tree.exists(file)) {
91
+ console.log(` ✅ ${file}`);
92
+ } else {
93
+ console.log(` ❌ Missing: ${file}`);
94
+ }
95
+ }
96
+
97
+ // Verify tsconfig was updated
98
+ console.log('\n⚙️ Checking tsconfig.json:');
99
+ const tsconfigContent = tree.read('/tsconfig.json').toString('utf-8');
100
+ const tsconfig = JSON.parse(tsconfigContent);
101
+ const paths = tsconfig.compilerOptions?.paths || {};
102
+
103
+ const expectedPaths = ['@/*', '@/lib/*', '@/ui/*', '@/utils/*'];
104
+ for (const p of expectedPaths) {
105
+ if (paths[p]) {
106
+ console.log(` ✅ Path alias: ${p}`);
107
+ } else {
108
+ console.log(` ❌ Missing path alias: ${p}`);
109
+ }
110
+ }
111
+
112
+ // Verify styles were imported
113
+ console.log('\n🎨 Checking styles:');
114
+ const stylesContent = tree.read('/src/styles.css').toString('utf-8');
115
+ if (stylesContent.includes('ng-cn.scss')) {
116
+ console.log(' ✅ ng-cn.scss imported in styles.css');
117
+ } else {
118
+ console.log(' ❌ ng-cn.scss not imported');
119
+ }
120
+
121
+ // Verify dependencies
122
+ console.log('\n📦 Checking dependencies:');
123
+ const packageJsonContent = tree.read('/package.json').toString('utf-8');
124
+ const packageJson = JSON.parse(packageJsonContent);
125
+ const requiredDeps = ['lucide-angular', 'clsx', 'tailwind-merge', 'class-variance-authority'];
126
+ for (const dep of requiredDeps) {
127
+ if (packageJson.dependencies?.[dep]) {
128
+ console.log(` ✅ ${dep}@${packageJson.dependencies[dep]}`);
129
+ } else {
130
+ console.log(` ❌ Missing: ${dep}`);
131
+ }
132
+ }
133
+
134
+ console.log('\n✨ All tests passed!\n');
135
+
136
+ } catch (error) {
137
+ console.error('\n❌ Schematic failed with error:');
138
+ console.error(error);
139
+ process.exit(1);
140
+ }
141
+ }
142
+
143
+ runTests();