@smapiot/pilet-template-angular 0.15.0-beta.4440
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/LICENSE +21 -0
- package/README.md +38 -0
- package/lib/index.js +1385 -0
- package/package.json +60 -0
- package/src/helpers.ts +76 -0
- package/src/index.ts +77 -0
- package/templates/app.module.ejs +13 -0
- package/templates/index.jsx.ejs +3 -0
- package/templates/index.tsx.ejs +25 -0
- package/templates/page.component.css.ejs +4 -0
- package/templates/page.component.html.ejs +3 -0
- package/templates/page.component.ts.ejs +7 -0
- package/templates/tsconfig.json.ejs +26 -0
- package/templates/webpack.config.js.ejs +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smapiot/pilet-template-angular",
|
|
3
|
+
"version": "0.15.0-beta.4440",
|
|
4
|
+
"description": "Official scaffolding template for pilets: 'angular'.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"piral-cli",
|
|
7
|
+
"pilet",
|
|
8
|
+
"template",
|
|
9
|
+
"scaffold",
|
|
10
|
+
"boilerplate"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=12.0",
|
|
17
|
+
"piral": "0.15.x"
|
|
18
|
+
},
|
|
19
|
+
"templateOptions": {
|
|
20
|
+
"standalone": {
|
|
21
|
+
"description": "Defines if the pilet should include Angular - in case of the app shell not providing Angular already.",
|
|
22
|
+
"default": false,
|
|
23
|
+
"type": "boolean"
|
|
24
|
+
},
|
|
25
|
+
"ngVersion": {
|
|
26
|
+
"description": "Defines the (major) version of Angular to use in case of a standalone pilet.",
|
|
27
|
+
"default": 14,
|
|
28
|
+
"type": "number"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"author": "smapiot",
|
|
32
|
+
"homepage": "https://piral.io",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"main": "lib/index.js",
|
|
35
|
+
"files": [
|
|
36
|
+
"lib",
|
|
37
|
+
"src",
|
|
38
|
+
"templates"
|
|
39
|
+
],
|
|
40
|
+
"funding": {
|
|
41
|
+
"type": "github",
|
|
42
|
+
"url": "https://github.com/sponsors/smapiot"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/smapiot/piral-templates.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/smapiot/piral-templates/issues"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "esbuild src/index.ts --bundle --outfile=./lib/index.js --platform=node",
|
|
53
|
+
"check": "tsc --noEmit",
|
|
54
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@smapiot/template-utils": "0.15.0-beta.4440"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "996f5885e2f799c182bde89a8971381ae6f7b19f"
|
|
60
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function detectMode(piralInstance: { details: any }) {
|
|
2
|
+
const dependencies = piralInstance?.details?.dependencies || {};
|
|
3
|
+
const devDependencies = piralInstance?.details?.devDependencies || {};
|
|
4
|
+
const allDependencies = { ...devDependencies, ...dependencies };
|
|
5
|
+
return allDependencies['piral-ng'] === undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function detectNgVersion(piralInstance: { details: any }) {
|
|
9
|
+
const dependencies = piralInstance?.details?.dependencies || {};
|
|
10
|
+
const devDependencies = piralInstance?.details?.devDependencies || {};
|
|
11
|
+
const allDependencies = { ...devDependencies, ...dependencies };
|
|
12
|
+
const version = allDependencies['@angular/core'] || '14.0.0';
|
|
13
|
+
|
|
14
|
+
if (typeof version === 'string') {
|
|
15
|
+
const result = /\d+/.exec(version);
|
|
16
|
+
|
|
17
|
+
// Get major version
|
|
18
|
+
if (result) {
|
|
19
|
+
return +result[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return 14;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getStandalonePackageJson(cliVersion: string, ngVersion: string) {
|
|
27
|
+
return {
|
|
28
|
+
importmap: {
|
|
29
|
+
imports: {
|
|
30
|
+
'@angular/animations': '.',
|
|
31
|
+
'@angular/cli': '.',
|
|
32
|
+
'@angular/common': '.',
|
|
33
|
+
'@angular/compiler': '.',
|
|
34
|
+
'@angular/core': '.',
|
|
35
|
+
'@angular/forms': '.',
|
|
36
|
+
'@angular/platform-browser': '.',
|
|
37
|
+
'@angular/platform-browser-dynamic': '.',
|
|
38
|
+
'@angular/router': '.',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
dependencies: {
|
|
42
|
+
'@angular/animations': ngVersion,
|
|
43
|
+
'@angular/cli': ngVersion,
|
|
44
|
+
'@angular/common': ngVersion,
|
|
45
|
+
'@angular/compiler': ngVersion,
|
|
46
|
+
'@angular/core': ngVersion,
|
|
47
|
+
'@angular/forms': ngVersion,
|
|
48
|
+
'@angular/platform-browser': ngVersion,
|
|
49
|
+
'@angular/platform-browser-dynamic': ngVersion,
|
|
50
|
+
'@angular/router': ngVersion,
|
|
51
|
+
'piral-ng': cliVersion,
|
|
52
|
+
rxjs: '~7.4',
|
|
53
|
+
'zone.js': '~0.11',
|
|
54
|
+
},
|
|
55
|
+
devDependencies: {
|
|
56
|
+
'@angular/compiler-cli': ngVersion,
|
|
57
|
+
'@ngtools/webpack': ngVersion,
|
|
58
|
+
'copy-webpack-plugin': '^10',
|
|
59
|
+
'html-loader': '^3',
|
|
60
|
+
'to-string-loader': '^1',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getStandardPackageJson(cliVersion: string, ngVersion: string) {
|
|
66
|
+
return {
|
|
67
|
+
devDependencies: {
|
|
68
|
+
'@angular/compiler-cli': ngVersion,
|
|
69
|
+
'@ngtools/webpack': ngVersion,
|
|
70
|
+
'copy-webpack-plugin': '^10',
|
|
71
|
+
'html-loader': '^3',
|
|
72
|
+
'to-string-loader': '^1',
|
|
73
|
+
'piral-ng': cliVersion,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { createPiletTemplateFactory, getPiralInstance } from '@smapiot/template-utils';
|
|
3
|
+
import { detectMode, detectNgVersion, getStandalonePackageJson, getStandardPackageJson } from './helpers';
|
|
4
|
+
|
|
5
|
+
const root = resolve(__dirname, '..');
|
|
6
|
+
|
|
7
|
+
interface AngularPiletArgs {
|
|
8
|
+
standalone: boolean;
|
|
9
|
+
ngVersion: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default createPiletTemplateFactory<AngularPiletArgs>(root, (projectRoot, args, details) => {
|
|
13
|
+
const { sourceName } = args;
|
|
14
|
+
const piralInstance = getPiralInstance(projectRoot, sourceName);
|
|
15
|
+
|
|
16
|
+
if (typeof args.standalone === 'undefined') {
|
|
17
|
+
args.standalone = detectMode(piralInstance);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof args.ngVersion !== 'number') {
|
|
21
|
+
args.ngVersion = detectNgVersion(piralInstance);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ngVersion = `^${args.ngVersion}`;
|
|
25
|
+
const packageJson = args.standalone
|
|
26
|
+
? getStandalonePackageJson(details.cliVersion, ngVersion)
|
|
27
|
+
: getStandardPackageJson(details.cliVersion, ngVersion);
|
|
28
|
+
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
languages: ['ts', 'js'],
|
|
32
|
+
name: 'package.json',
|
|
33
|
+
content: JSON.stringify(packageJson),
|
|
34
|
+
target: '<root>/package.json',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
languages: ['ts', 'js'],
|
|
38
|
+
name: 'webpack.config.js',
|
|
39
|
+
target: '<root>/webpack.config.js',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
languages: ['js'],
|
|
43
|
+
name: 'index.jsx',
|
|
44
|
+
target: '<src>/index.jsx',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
languages: ['ts'],
|
|
48
|
+
name: 'app.module.ts',
|
|
49
|
+
target: '<src>/app/app.module.ts',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
languages: ['ts'],
|
|
53
|
+
name: 'page.component.html',
|
|
54
|
+
target: '<src>/app/page.component.html',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
languages: ['ts'],
|
|
58
|
+
name: 'page.component.css',
|
|
59
|
+
target: '<src>/app/page.component.css',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
languages: ['ts'],
|
|
63
|
+
name: 'page.component.ts',
|
|
64
|
+
target: '<src>/app/page.component.ts',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
languages: ['ts'],
|
|
68
|
+
name: 'index.tsx',
|
|
69
|
+
target: '<src>/index.tsx',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
languages: ['ts'],
|
|
73
|
+
name: 'tsconfig.json',
|
|
74
|
+
target: '<root>/tsconfig.json',
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
3
|
+
import { SharedModule } from 'piral-ng/common';
|
|
4
|
+
|
|
5
|
+
import { PageComponent } from './page.component';
|
|
6
|
+
|
|
7
|
+
@NgModule({
|
|
8
|
+
bootstrap: [PageComponent],
|
|
9
|
+
declarations: [PageComponent],
|
|
10
|
+
exports: [PageComponent],
|
|
11
|
+
imports: [BrowserModule, SharedModule]
|
|
12
|
+
})
|
|
13
|
+
export class AppModule {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
<% if (standalone) { -%>
|
|
3
|
+
import { defineNgModule, fromNg } from 'piral-ng/convert';
|
|
4
|
+
<% } -%>
|
|
5
|
+
import { AppModule } from './app/app.module';
|
|
6
|
+
import { PageComponent } from './app/page.component';
|
|
7
|
+
import type { PiletApi } from '<%- sourceName %>';
|
|
8
|
+
|
|
9
|
+
export function setup(app: PiletApi) {
|
|
10
|
+
<% if (standalone) { %>
|
|
11
|
+
app.defineNgModule(AppModule, {
|
|
12
|
+
// remove the following if you actually want to enable zone.js
|
|
13
|
+
ngZone: 'noop',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.registerPage('/sample', app.fromNg(PageComponent));
|
|
17
|
+
<% } else { %>
|
|
18
|
+
defineNgModule(AppModule, {
|
|
19
|
+
// remove the following if you actually want to enable zone.js
|
|
20
|
+
ngZone: 'noop',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.registerPage('/sample', fromNg(PageComponent));
|
|
24
|
+
<% } %>
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"angularCompilerOptions": {},
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"noImplicitAny": false,
|
|
6
|
+
"removeComments": false,
|
|
7
|
+
"noLib": false,
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"target": "es6",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"lib": ["dom", "es2018"],
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"jsx": "react",
|
|
18
|
+
"importHelpers": true
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"<%- src %>"
|
|
22
|
+
],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|