Skip to content

Commit ca53755

Browse files
committed
chore: tooling
1 parent 0c29b8b commit ca53755

26 files changed

+220
-130
lines changed

apps/demo-angular/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
"@nativescript/zip": "file:../../dist/packages/zip"
3030
},
3131
"devDependencies": {
32+
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
3233
"@nativescript/android": "~7.0.0",
33-
"@nativescript/ios": "~7.0.0",
34+
"@nativescript/ios": "7.0.0",
3435
"@nativescript/webpack": "~3.0.0",
35-
"typescript": "file:../../node_modules/typescript",
36-
"@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli",
37-
"@ngtools/webpack": "file:../../node_modules/@ngtools/webpack"
36+
"@ngtools/webpack": "file:../../node_modules/@ngtools/webpack",
37+
"typescript": "file:../../node_modules/typescript"
3838
}
3939
}

apps/demo-angular/src/app-routing.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Routes } from "@angular/router";
33
import { NativeScriptRouterModule } from "@nativescript/angular";
44

55
import { HomeComponent } from "./home.component";
6-
import { ImagePickerComponent, DateTimePickerComponent } from "./plugin-demos";
76

87
const routes: Routes = [
98
{ path: "", redirectTo: "/home", pathMatch: "full" },
109
{ path: "home", component: HomeComponent },
11-
{ path: "datetimepicker", component: DateTimePickerComponent },
12-
{ path: "imagepicker", component: ImagePickerComponent }
10+
{ path: "datetimepicker", loadChildren: () => import('./plugin-demos/datetimepicker.module').then(m => m.DateTimePickerModule) },
11+
{ path: "imagepicker", loadChildren: () => import('./plugin-demos/imagepicker.module').then(m => m.ImagePickerModule) },
12+
{ path: "appavailability", loadChildren: () => import('./plugin-demos/appavailability.module').then(m => m.AppavailabilityModule) }
1313
];
1414

1515
@NgModule({

apps/demo-angular/src/app.component.html

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component } from "@angular/core";
1+
import { Component } from '@angular/core';
22

33
@Component({
4-
selector: "demo-app",
5-
templateUrl: "app.component.html",
4+
selector: 'demo-app',
5+
template: `<GridLayout>
6+
<page-router-outlet></page-router-outlet>
7+
</GridLayout>`,
68
})
7-
export class AppComponent {
8-
9-
}
9+
export class AppComponent {}

apps/demo-angular/src/app.module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { NativeScriptModule } from "@nativescript/angular";
44
import { AppComponent } from "./app.component";
55
import { AppRoutingModule } from "./app-routing.module";
66
import { HomeComponent } from "./home.component";
7-
import { COMPONENTS } from "./plugin-demos";
8-
import { NativeScriptDateTimePickerModule } from "@nativescript/datetimepicker/angular";
97

108
@NgModule({
119
schemas: [NO_ERRORS_SCHEMA],
12-
declarations: [AppComponent, HomeComponent, ...COMPONENTS],
10+
declarations: [AppComponent, HomeComponent],
1311
bootstrap: [AppComponent],
14-
imports: [NativeScriptModule, AppRoutingModule, NativeScriptDateTimePickerModule],
12+
imports: [NativeScriptModule, AppRoutingModule],
1513
})
1614
export class AppModule {}

apps/demo-angular/src/home.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<ActionBar>
2+
<ActionBar title="Demos"></ActionBar>
3+
</ActionBar>
14
<GridLayout>
25
<ListView [items]="demos">
36
<ng-template let-item="item" let-i="index">

apps/demo-angular/src/home.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export class HomeComponent {
1111
},
1212
{
1313
name: 'imagepicker',
14+
},
15+
{
16+
name: 'appavailability',
1417
},
1518
];
1619
}

apps/demo-angular/src/plugin-demos/appavailability.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<ActionBar>
2+
<ActionBar title="appavailability"></ActionBar>
3+
</ActionBar>
14
<StackLayout class="p-20">
25
<ScrollView class="h-full">
36
<StackLayout>
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { Component, NgZone } from '@angular/core';
2-
import { } from '@nativescript/appavailability';
2+
import {} from '@nativescript/appavailability';
33

44
@Component({
55
selector: 'demo-appavailability',
66
templateUrl: 'appavailability.component.html',
77
})
88
export class AppavailabilityComponent {
9+
constructor(private ngZone: NgZone) {}
910

10-
constructor(private _ngZone: NgZone) {}
11-
12-
testIt() {
13-
// test something here
14-
}
15-
11+
testIt() {
12+
console.log('test your plugin!');
13+
}
1614
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { AppavailabilityComponent } from './appavailability.component';
4+
5+
@NgModule({
6+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: AppavailabilityComponent }])],
7+
declarations: [AppavailabilityComponent],
8+
schemas: [ NO_ERRORS_SCHEMA]
9+
})
10+
export class AppavailabilityModule {}

apps/demo-angular/src/plugin-demos/datetimepicker.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<ActionBar>
2+
<ActionBar title="datetimepicker"></ActionBar>
3+
</ActionBar>
14
<ScrollView #scrollView>
25
<StackLayout class="p-20">
36
<Label text="DatePickerField" id="date" class="header" (tap)="onHeaderTap($event)" [opacity]="dateOpacity"></Label>

apps/demo-angular/src/plugin-demos/datetimepicker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, NgZone, ViewChild, ElementRef } from '@angular/core';
2-
import { DateTimePicker } from '@nativescript/datetimepicker';
32
import { EventData, Button } from '@nativescript/core';
3+
import { DateTimePicker } from '@nativescript/datetimepicker';
44

55
@Component({
66
selector: 'demo-datetimepicker',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { DateTimePickerComponent } from './datetimepicker.component';
4+
import { NativeScriptDateTimePickerModule } from "@nativescript/datetimepicker/angular";
5+
6+
@NgModule({
7+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: DateTimePickerComponent }]), NativeScriptDateTimePickerModule],
8+
declarations: [DateTimePickerComponent],
9+
schemas: [ NO_ERRORS_SCHEMA]
10+
})
11+
export class DateTimePickerModule {}

apps/demo-angular/src/plugin-demos/imagepicker.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<ActionBar>
2-
<ActionBar title="Image Picker"></ActionBar>
2+
<ActionBar title="imagepicker"></ActionBar>
33
</ActionBar>
4-
54
<GridLayout rows="*, auto, auto">
65
<ListView [items]="imageAssets" *ngIf="!isSingleMode">
76
<ng-template let-image="item" let-i="index">
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { ImagePickerComponent } from './imagepicker.component';
4+
5+
@NgModule({
6+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: ImagePickerComponent }])],
7+
declarations: [ImagePickerComponent],
8+
schemas: [ NO_ERRORS_SCHEMA]
9+
})
10+
export class ImagePickerModule {}

apps/demo-angular/src/plugin-demos/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/demo-angular/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
"paths": {
55
"~/*": ["src/*"]
66
}
7-
}
7+
},
8+
"files": [
9+
"./references.d.ts",
10+
"./src/main.ts"
11+
]
812
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"license": "MIT",
55
"scripts": {
6-
"setup": "ns clean && npm i && ts-patch install",
6+
"setup": "npx rimraf node_modules package-lock.json dist tmp && npm i && ts-patch install",
77
"start": "nps"
88
},
99
"private": true,

tools/schematics/add-package/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { chain, Rule, Tree, SchematicContext, apply, url, move, mergeWith, template } from '@angular-devkit/schematics';
22
import { stringUtils, addProjectToNxJsonInTree, getWorkspace } from '@nrwl/workspace';
3-
import { updateWorkspaceJson, getJsonFromFile, scopeName } from '../utils';
3+
import { updateWorkspaceJson, getJsonFromFile, scopeName, getAllPackages } from '../utils';
44
import syncPackagesWithDemos from '../sync-packages-with-demos';
55
import { Schema } from './schema';
66

@@ -134,8 +134,7 @@ function updateReadMe() {
134134
const readmeStart = readmeContent.substring(0, listPackageSectionIndex);
135135
const listEndIndex = readmeContent.indexOf(`# How to`);
136136
const readmeEnd = readmeContent.substring(listEndIndex, readmeContent.length);
137-
const packagesDir = tree.getDir('packages');
138-
const packageNames = packagesDir.subdirs.sort();
137+
const packageNames = getAllPackages(tree);
139138
let packageList = '';
140139
for (const packageName of packageNames) {
141140
packageList += `* ${scopeName}/${packageName}\n`;

tools/schematics/focus-packages/index.ts

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { chain, Rule, Tree, SchematicContext, apply, url, move, mergeWith, template, externalSchematic, noop } from '@angular-devkit/schematics';
22
import * as path from 'path';
33
import { stringUtils, addProjectToNxJsonInTree, getWorkspace } from '@nrwl/workspace';
4-
import { updateWorkspaceJson, getJsonFromFile, sanitizeCollectionArgs, getDemoAppRoot, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getDemoIndexPathForType } from '../utils';
4+
import { updateWorkspaceJson, getJsonFromFile, sanitizeCollectionArgs, getDemoAppRoot, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getDemoIndexPathForType, getAllPackages, resetIndexForDemoType, getPluginDemoPath } from '../utils';
55
import syncPackagesWithDemos from '../sync-packages-with-demos';
66
import { Schema } from './schema';
77
const prettyData = require('pretty-data').pd;
@@ -24,27 +24,25 @@ export default function (schema: Schema): Rule {
2424
? noop()
2525
: (tree: Tree, context: SchematicContext) => {
2626
setPackageNamesToUpdate(focusPackages);
27-
allPackages = tree.getDir('packages').subdirs;
27+
allPackages = getAllPackages(tree);
2828
// console.log('allPackages:', allPackages);
2929
// apps
3030
const appsDir = tree.getDir('apps');
3131
if (appsDir && appsDir.subdirs) {
3232
const appFolders = appsDir.subdirs;
3333
for (const dir of appFolders) {
34-
const demoViewsPath = `${appsDir.path}/${dir}/src/plugin-demos`;
34+
const demoViewsPath = `${appsDir.path}/${dir}/${getPluginDemoPath()}`;
3535
const demoAppRoot = `${appsDir.path}/${dir}`;
3636
// console.log(`demoAppRoot: ${demoAppRoot}`);
3737
const demoType = getDemoTypeFromName(dir);
3838
// console.log(`demoType: ${demoType}`);
3939
updateDemoDependencies(tree, demoType, demoAppRoot, allPackages, true);
40-
let mainIndex: string;
4140

4241
// add `_off` suffix on ts,xml files for those that not being focused on
4342
// this removes those from the app build
4443
for (const p of allPackages) {
4544
switch (demoType) {
4645
case 'xml':
47-
mainIndex = `${demoAppRoot}/src/main-page.xml`;
4846
const xmlView = `${demoViewsPath}/${p}.xml`;
4947
// console.log('xmlView:', xmlView);
5048
const tsClass = `${demoViewsPath}/${p}.ts`;
@@ -73,57 +71,7 @@ export default function (schema: Schema): Rule {
7371
}
7472

7573
// cleanup index listing to only have buttons for what is being focused on
76-
const demoIndexPath = getDemoIndexPathForType(demoType);
77-
const demoIndexFullPath = `${demoAppRoot}/${demoIndexPath}`;
78-
if (tree.exists(demoIndexFullPath)) {
79-
const indexStringData = tree.get(demoIndexFullPath).content.toString();
80-
xml2js.parseString(indexStringData, (err, indexData: any) => {
81-
// console.log('indexData:', indexData);
82-
if (indexData && indexData.Page) {
83-
if (indexData.Page.StackLayout) {
84-
const stackLayout = indexData.Page.StackLayout[0];
85-
if (stackLayout && stackLayout.ScrollView) {
86-
const scrollView = stackLayout.ScrollView[0];
87-
if (scrollView && scrollView.StackLayout) {
88-
const buttons = scrollView.StackLayout[0].Button;
89-
const buttonStructure = buttons[0];
90-
// console.log('buttonStructure:', buttonStructure);
91-
// console.log('buttons:', buttons);
92-
scrollView.StackLayout[0].Button = [];
93-
if (focusPackages.length === 0) {
94-
// resetting to include buttons for all packages
95-
for (const p of allPackages) {
96-
scrollView.StackLayout[0].Button.push({
97-
$: {
98-
...buttonStructure.$,
99-
text: p,
100-
},
101-
});
102-
}
103-
} else {
104-
// focus on specific packages for demo testing
105-
for (const p of focusPackages) {
106-
scrollView.StackLayout[0].Button.push({
107-
$: {
108-
...buttonStructure.$,
109-
text: p,
110-
},
111-
});
112-
}
113-
}
114-
115-
const xmlBuilder = new xml2js.Builder({
116-
headless: true,
117-
});
118-
const modifiedIndex = xmlBuilder.buildObject(indexData);
119-
// console.log('modifiedIndex:', modifiedIndex);
120-
tree.overwrite(demoIndexFullPath, modifiedIndex);
121-
}
122-
}
123-
}
124-
}
125-
});
126-
}
74+
resetIndexForDemoType(tree, demoType);
12775
}
12876
}
12977
return tree;

tools/schematics/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class <%= stringUtils.classify(name) %>Component {
1010
constructor(private _ngZone: NgZone) {}
1111

1212
testIt() {
13-
// test something here
13+
console.log('test your plugin!');
1414
}
1515

1616
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { <%= stringUtils.classify(name) %>Component } from './<%= name %>.component';
4+
5+
@NgModule({
6+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: <%= stringUtils.classify(name) %>Component }])],
7+
declarations: [<%= stringUtils.classify(name) %>Component],
8+
schemas: [ NO_ERRORS_SCHEMA]
9+
})
10+
export class <%= stringUtils.classify(name) %>Module {}

0 commit comments

Comments
 (0)