Skip to content

Commit 1954182

Browse files
committed
feat: create simple angular skeleton
1 parent 6084706 commit 1954182

17 files changed

Lines changed: 418 additions & 326 deletions

File tree

.editorconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ root = true
33

44
[*]
55
charset = utf-8
6-
end_of_line = lf
7-
indent_size = 2
86
indent_style = space
7+
indent_size = 2
98
insert_final_newline = true
10-
max_line_length = 140
119
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
max_line_length = 140
1212

1313
[*.md]
14-
indent_size = 4
14+
max_line_length = off
1515

1616
[*.ts]
1717
quote_type = single

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Marcel Hendrich",
33
"bin": {
4-
"swagstack": "dist/cli/index.js"
4+
"swagstack": "dist/index.js"
55
},
66
"contributors": [
77
{
@@ -11,10 +11,10 @@
1111
],
1212
"dependencies": {
1313
"@inquirer/prompts": "8.3.2",
14-
"commander": "14.0.3",
1514
"chalk": "5.6.2",
16-
"figlet": "1.11.0",
15+
"commander": "14.0.3",
1716
"execa": "9.6.1",
17+
"figlet": "1.11.0",
1818
"fs-extra": "11.3.4",
1919
"handlebars": "4.7.9"
2020
},
@@ -35,9 +35,9 @@
3535
"private": true,
3636
"repository": "https://github.com/inpercima/swagstack",
3737
"scripts": {
38-
"build": "tsc",
39-
"dev": "tsx src/cli/index.ts",
40-
"start": "node dist/cli/index.js"
38+
"build": "tsc && node scripts/copy-templates.js",
39+
"dev": "tsx src/index.ts",
40+
"start": "node dist/index.js"
4141
},
4242
"type": "module",
4343
"version": "3.0.0-SNAPSHOT"

scripts/copy-templates.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from 'fs-extra';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
const source = path.resolve(__dirname, '../src/templates');
8+
const target = path.resolve(__dirname, '../dist/templates');
9+
10+
await fs.ensureDir(path.dirname(target));
11+
await fs.copy(source, target, { overwrite: true });
12+
13+
console.log(`Copied templates: ${source} -> ${target}`);

src/commands/init.ts

Lines changed: 0 additions & 214 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from 'node:path';
2+
import { PRESETS, Config, DESIGN_SYSTEMS } from '../../../utils/types.js';
3+
import { run } from '../../../utils/utils.js';
4+
import { ANGULAR_CLI_VERSION, CLARITY_DESIGN_VERSION } from '../../../utils/versions.js';
5+
6+
export async function createAngularFrontendSkeleton(config: Config): Promise<void> {
7+
const isAngularOnly = config.preset === PRESETS.ANGULAR_ONLY;
8+
const workingRootDir = isAngularOnly ? process.cwd() : config.repoRoot;
9+
const workingAngularDir = isAngularOnly ? config.repoRoot : path.join(config.repoRoot, 'frontend');
10+
11+
await installAngularCli(workingRootDir, isAngularOnly, config.pm, config.projectName);
12+
13+
await run('ng', ['add', 'angular-eslint'], workingAngularDir);
14+
15+
if (config.useCypress) {
16+
await run('ng', ['add', '@cypress/schematic'], workingAngularDir);
17+
}
18+
19+
if (config.designSystem.includes(DESIGN_SYSTEMS.ANGULAR_MATERIAL)) {
20+
await run('ng', ['add', `@angular/material@${ANGULAR_CLI_VERSION}`], workingAngularDir);
21+
}
22+
23+
if (config.designSystem.includes(DESIGN_SYSTEMS.CLARITY_DESIGN)) {
24+
await run(config.pm, ['install', `@clr/ui@${CLARITY_DESIGN_VERSION}`, `@clr/angular@${CLARITY_DESIGN_VERSION}`], workingAngularDir);
25+
}
26+
}
27+
28+
async function installAngularCli(workingRootDir: string, isAngularOnly: boolean, pm: string, projectName: string): Promise<void> {
29+
return run(
30+
'npx',
31+
[
32+
'-y',
33+
`@angular/cli@${ANGULAR_CLI_VERSION}`,
34+
'new',
35+
isAngularOnly ? projectName : 'frontend',
36+
'--interactive=false',
37+
'--skip-git',
38+
'--style=css',
39+
'--routing',
40+
'--package-manager',
41+
pm,
42+
],
43+
workingRootDir,
44+
);
45+
}

0 commit comments

Comments
 (0)