Skip to content

Commit e0f8f0f

Browse files
NathanWalkerrigor789
authored andcommitted
feat: use scoped app templates and fix create project appid
1 parent 6d97a5f commit e0f8f0f

File tree

12 files changed

+136
-87
lines changed

12 files changed

+136
-87
lines changed

docs/man_pages/project/creation/create.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Interactively creates a new NativeScript app based on a predefined template.
1313

1414
Template | Synopsis
1515
---------|---------
16-
JavaScript based | `$ tns create [<App Name>] [--js] [--path <Directory>] [--appid <App ID>]`
17-
TypeScript based | `$ tns create [<App Name>] --ts [--path <Directory>] [--appid <App ID>]`
18-
Angular based | `$ tns create [<App Name>] --ng [--path <Directory>] [--appid <App ID>]`
19-
Vue.js based | `$ tns create [<App Name>] --vue [--path <Directory>] [--appid <App ID>]`
20-
Custom template | `$ tns create [<App Name>] [--path <Directory>] [--appid <App ID>] --template <Template>`
16+
JavaScript based | `$ ns create [<App Name>] [--js] [--path <Directory>] [--appid <App ID>]`
17+
TypeScript based | `$ ns create [<App Name>] --ts [--path <Directory>] [--appid <App ID>]`
18+
Angular based | `$ ns create [<App Name>] --ng [--path <Directory>] [--appid <App ID>]`
19+
Vue.js based | `$ ns create [<App Name>] --vue [--path <Directory>] [--appid <App ID>]`
20+
Custom template | `$ ns create [<App Name>] [--path <Directory>] [--appid <App ID>] --template <Template>`
2121

2222
### Options
2323

@@ -42,19 +42,19 @@ Below you can see a list of the recommended NativeScript starting templates and
4242

4343
Template | Command
4444
---------|----------
45-
`JavaScript - Hello World`, `--js`, `--javascript` | tns create --template tns-template-hello-world
46-
`JavaScript - SideDrawer` | tns create --template tns-template-drawer-navigation
47-
`JavaScript - Tabs` | tns create --template tns-template-tab-navigation
48-
`TypeScript - Hello World`, `--ts`, `--tsc`, `--typescript` | tns create --template tns-template-hello-world-ts
49-
`TypeScript - SideDrawer` | tns create --template tns-template-drawer-navigation-ts
50-
`TypeScript - Tabs` | tns create --template tns-template-tab-navigation-ts
51-
`Angular - Hello World`, `--ng`, `--angular` | tns create --template tns-template-hello-world-ng
52-
`Angular - SideDrawer` | tns create --template tns-template-drawer-navigation-ng
53-
`Angular - Tabs` | tns create --template tns-template-tab-navigation-ng
54-
`React - Hello World`, `--react`, `--reactjs` | tns create --template tns-template-blank-react
55-
`Vue.js - Blank`, `--vue`, `--vuejs` | tns create --template tns-template-blank-vue
56-
`Vue.js - SideDrawer`, | tns create --template tns-template-drawer-navigation-vue
57-
`Vue.js - Tabs` | tns create --template tns-template-tab-navigation-vue
45+
`JavaScript - Hello World`, `--js`, `--javascript` | ns create --template @nativescript/template-hello-world
46+
`JavaScript - SideDrawer` | ns create --template @nativescript/template-drawer-navigation
47+
`JavaScript - Tabs` | ns create --template @nativescript/template-tab-navigation
48+
`TypeScript - Hello World`, `--ts`, `--tsc`, `--typescript` | ns create --template @nativescript/template-hello-world-ts
49+
`TypeScript - SideDrawer` | ns create --template @nativescript/template-drawer-navigation-ts
50+
`TypeScript - Tabs` | ns create --template @nativescript/template-tab-navigation-ts
51+
`Angular - Hello World`, `--ng`, `--angular` | ns create --template @nativescript/template-hello-world-ng
52+
`Angular - SideDrawer` | ns create --template @nativescript/template-drawer-navigation-ng
53+
`Angular - Tabs` | ns create --template @nativescript/template-tab-navigation-ng
54+
`React - Hello World`, `--react`, `--reactjs` | ns create --template @nativescript/template-blank-react
55+
`Vue.js - Blank`, `--vue`, `--vuejs` | ns create --template @nativescript/template-blank-vue
56+
`Vue.js - SideDrawer`, | ns create --template @nativescript/template-drawer-navigation-vue
57+
`Vue.js - Tabs` | ns create --template @nativescript/template-tab-navigation-vue
5858

5959
### Related Commands
6060

lib/commands/create-project.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
215215
},
216216
{
217217
key: CreateProjectCommand.DrawerTemplateKey,
218-
value: "tns-template-drawer-navigation",
218+
value: "@nativescript/template-drawer-navigation",
219219
description: CreateProjectCommand.DrawerTemplateDescription,
220220
},
221221
{
222222
key: CreateProjectCommand.TabsTemplateKey,
223-
value: "tns-template-tab-navigation",
223+
value: "@nativescript/template-tab-navigation",
224224
description: CreateProjectCommand.TabsTemplateDescription,
225225
},
226226
];
@@ -237,12 +237,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
237237
},
238238
{
239239
key: CreateProjectCommand.DrawerTemplateKey,
240-
value: "tns-template-drawer-navigation-ts",
240+
value: "@nativescript/template-drawer-navigation-ts",
241241
description: CreateProjectCommand.DrawerTemplateDescription,
242242
},
243243
{
244244
key: CreateProjectCommand.TabsTemplateKey,
245-
value: "tns-template-tab-navigation-ts",
245+
value: "@nativescript/template-tab-navigation-ts",
246246
description: CreateProjectCommand.TabsTemplateDescription,
247247
},
248248
];
@@ -259,12 +259,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
259259
},
260260
{
261261
key: CreateProjectCommand.DrawerTemplateKey,
262-
value: "tns-template-drawer-navigation-ng",
262+
value: "@nativescript/template-drawer-navigation-ng",
263263
description: CreateProjectCommand.DrawerTemplateDescription,
264264
},
265265
{
266266
key: CreateProjectCommand.TabsTemplateKey,
267-
value: "tns-template-tab-navigation-ng",
267+
value: "@nativescript/template-tab-navigation-ng",
268268
description: CreateProjectCommand.TabsTemplateDescription,
269269
},
270270
];
@@ -288,17 +288,17 @@ can skip this prompt next time using the --template option, or the --ng, --react
288288
const templates = [
289289
{
290290
key: CreateProjectCommand.BlankTemplateKey,
291-
value: "tns-template-blank-vue",
291+
value: "@nativescript/template-blank-vue",
292292
description: CreateProjectCommand.BlankTemplateDescription,
293293
},
294294
{
295295
key: CreateProjectCommand.DrawerTemplateKey,
296-
value: "tns-template-drawer-navigation-vue",
296+
value: "@nativescript/template-drawer-navigation-vue",
297297
description: CreateProjectCommand.DrawerTemplateDescription,
298298
},
299299
{
300300
key: CreateProjectCommand.TabsTemplateKey,
301-
value: "tns-template-tab-navigation-vue",
301+
value: "@nativescript/template-tab-navigation-vue",
302302
description: CreateProjectCommand.TabsTemplateDescription,
303303
},
304304
];

lib/constants.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ export class ReleaseType {
129129
}
130130

131131
export const RESERVED_TEMPLATE_NAMES: IStringDictionary = {
132-
default: "tns-template-hello-world",
133-
javascript: "tns-template-hello-world",
134-
tsc: "tns-template-hello-world-ts",
135-
vue: "tns-template-blank-vue",
136-
typescript: "tns-template-hello-world-ts",
137-
ng: "tns-template-hello-world-ng",
138-
angular: "tns-template-hello-world-ng",
139-
react: "tns-template-blank-react",
140-
reactjs: "tns-template-blank-react",
132+
default: "@nativescript/template-hello-world",
133+
javascript: "@nativescript/template-hello-world",
134+
tsc: "@nativescript/template-hello-world-ts",
135+
vue: "@nativescript/template-blank-vue",
136+
typescript: "@nativescript/template-hello-world-ts",
137+
ng: "@nativescript/template-hello-world-ng",
138+
angular: "@nativescript/template-hello-world-ng",
139+
react: "@nativescript/template-blank-react",
140+
reactjs: "@nativescript/template-blank-react",
141141
};
142142

143143
export const ANALYTICS_LOCAL_TEMPLATE_PREFIX = "localTemplate_";

lib/controllers/migrate-controller.ts

+23-33
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export class MigrateController
3939
implements IMigrateController {
4040
private static COMMON_MIGRATE_MESSAGE =
4141
"not affect the codebase of the application and you might need to do additional changes manually – for more information, refer to the instructions in the following blog post: https://www.nativescript.org/blog/nativescript-6.0-application-migration";
42-
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 6.0.
43-
Use the \`tns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 6.0.
42+
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 7.0.
43+
Use the \`ns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 7.0.
4444
Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
4545
private static MIGRATE_FINISH_MESSAGE = `The \`tns migrate\` command does ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
4646

@@ -133,15 +133,15 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
133133
migrateAction: this.migrateNativeScriptVue.bind(this),
134134
},
135135
{
136-
packageName: "nativescript-angular",
137-
verifiedVersion: "8.0.2",
136+
packageName: "@nativescript/angular",
137+
verifiedVersion: "10.0.0",
138138
shouldMigrateAction: async (
139139
projectData: IProjectData,
140140
allowInvalidVersions: boolean
141141
) => {
142142
const dependency = {
143-
packageName: "nativescript-angular",
144-
verifiedVersion: "8.0.2",
143+
packageName: "@nativescript/angular",
144+
verifiedVersion: "10.0.0",
145145
isDev: false,
146146
};
147147
const result =
@@ -155,8 +155,6 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
155155
},
156156
migrateAction: this.migrateNativeScriptAngular.bind(this),
157157
},
158-
{ packageName: "nativescript-permissions", verifiedVersion: "1.3.0" },
159-
{ packageName: "nativescript-cardview", verifiedVersion: "3.2.0" },
160158
{
161159
packageName: "@nativescript/unit-test-runner",
162160
verifiedVersion: "1.0.0",
@@ -183,17 +181,14 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
183181
{
184182
packageName: MigrateController.typescriptPackageName,
185183
isDev: true,
186-
verifiedVersion: "3.4.5",
187-
},
188-
{ packageName: "nativescript-localize", verifiedVersion: "4.2.0" },
189-
{ packageName: "nativescript-dev-babel", verifiedVersion: "0.2.1" },
190-
{ packageName: "nativescript-nfc", verifiedVersion: "4.0.1" },
184+
verifiedVersion: "3.9.0",
185+
}
191186
];
192187

193188
get verifiedPlatformVersions(): IDictionary<string> {
194189
return {
195-
[this.$devicePlatformsConstants.Android.toLowerCase()]: "6.0.0",
196-
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "6.0.1",
190+
[this.$devicePlatformsConstants.Android.toLowerCase()]: "7.0.0",
191+
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "7.0.0",
197192
};
198193
}
199194

@@ -809,68 +804,63 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
809804
const dependencies = [
810805
{
811806
packageName: "@angular/platform-browser-dynamic",
812-
verifiedVersion: "8.0.0",
807+
verifiedVersion: "10.0.0",
813808
shouldAddIfMissing: true,
814809
},
815810
{
816811
packageName: "@angular/common",
817-
verifiedVersion: "8.0.0",
812+
verifiedVersion: "10.0.0",
818813
shouldAddIfMissing: true,
819814
},
820815
{
821816
packageName: "@angular/compiler",
822-
verifiedVersion: "8.0.0",
817+
verifiedVersion: "10.0.0",
823818
shouldAddIfMissing: true,
824819
},
825820
{
826821
packageName: "@angular/core",
827-
verifiedVersion: "8.0.0",
822+
verifiedVersion: "10.0.0",
828823
shouldAddIfMissing: true,
829824
},
830825
{
831826
packageName: "@angular/forms",
832-
verifiedVersion: "8.0.0",
833-
shouldAddIfMissing: true,
834-
},
835-
{
836-
packageName: "@angular/http",
837-
verifiedVersion: "8.0.0-beta.10",
827+
verifiedVersion: "10.0.0",
838828
shouldAddIfMissing: true,
839829
},
840830
{
841831
packageName: "@angular/platform-browser",
842-
verifiedVersion: "8.0.0",
832+
verifiedVersion: "10.0.0",
843833
shouldAddIfMissing: true,
844834
},
845835
{
846836
packageName: "@angular/router",
847-
verifiedVersion: "8.0.0",
837+
verifiedVersion: "10.0.0",
848838
shouldAddIfMissing: true,
849839
},
850840
{
851841
packageName: "rxjs",
852-
verifiedVersion: "6.3.3",
842+
verifiedVersion: "6.6.0",
853843
shouldAddIfMissing: true,
854844
},
855845
{
856846
packageName: "zone.js",
857-
verifiedVersion: "0.9.1",
847+
verifiedVersion: "0.11.1",
858848
shouldAddIfMissing: true,
859849
},
860-
{ packageName: "@angular/animations", verifiedVersion: "8.0.0" },
850+
{ packageName: "@angular/animations", verifiedVersion: "10.0.0" },
861851
{
862852
packageName: "@angular/compiler-cli",
863-
verifiedVersion: "8.0.0",
853+
verifiedVersion: "10.0.0",
864854
isDev: true,
865855
},
866856
{
867857
packageName: "@ngtools/webpack",
868-
verifiedVersion: "8.0.0",
858+
verifiedVersion: "10.0.0",
869859
isDev: true,
870860
},
871861
{
872862
packageName: "@angular-devkit/build-angular",
873-
verifiedVersion: "0.800.3",
863+
verifiedVersion: "0.1000.8",
874864
isDev: true,
875865
},
876866
];

lib/definitions/project.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ interface IProjectConfigService {
299299
* Get value for a given config key path
300300
* @param key the property key path
301301
*/
302-
getValue(key: string): any;
302+
getValue(key: string): any;
303+
304+
detectInfo(projectDir?: string): { hasTS: boolean; hasJS: boolean, configJSFilePath: string; configTSFilePath: string };
305+
306+
setAppId(projectId: string, projectDir?: string): void;
303307
}
304308

305309
interface IAssetItem {

lib/services/project-config-service.ts

+37-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export class ProjectConfigService implements IProjectConfigService {
3030
return this.$injector.resolve("projectHelper");
3131
}
3232

33-
public readConfig(projectDir?: string): INsConfig {
33+
public detectInfo(
34+
projectDir?: string
35+
): {
36+
hasTS: boolean;
37+
hasJS: boolean;
38+
configJSFilePath: string;
39+
configTSFilePath: string;
40+
} {
3441
const configJSFilePath = path.join(
3542
projectDir || this.projectHelper.projectDir,
3643
CONFIG_FILE_NAME_JS
@@ -39,7 +46,6 @@ export class ProjectConfigService implements IProjectConfigService {
3946
projectDir || this.projectHelper.projectDir,
4047
CONFIG_FILE_NAME_TS
4148
);
42-
4349
const hasTS = this.$fs.exists(configTSFilePath);
4450
const hasJS = this.$fs.exists(configJSFilePath);
4551

@@ -55,6 +61,19 @@ export class ProjectConfigService implements IProjectConfigService {
5561
);
5662
}
5763

64+
return {
65+
hasTS,
66+
hasJS,
67+
configJSFilePath,
68+
configTSFilePath,
69+
};
70+
}
71+
72+
public readConfig(projectDir?: string): INsConfig {
73+
const { hasTS, configJSFilePath, configTSFilePath } = this.detectInfo(
74+
projectDir
75+
);
76+
5877
let config: INsConfig;
5978

6079
if (hasTS) {
@@ -84,6 +103,22 @@ export class ProjectConfigService implements IProjectConfigService {
84103
public getValue(key: string): any {
85104
return _.get(this.readConfig(), key);
86105
}
106+
107+
// TODO: improve to set any value
108+
// public setValue(projectDir?: string) {
109+
public setAppId(projectId: string, projectDir?: string) {
110+
const { hasTS, configJSFilePath, configTSFilePath } = this.detectInfo(
111+
projectDir
112+
);
113+
114+
const configPath = hasTS ? configTSFilePath : configJSFilePath;
115+
116+
const rawSource = this.$fs.readText(configPath);
117+
this.$fs.writeFile(
118+
configPath,
119+
rawSource.replace(`org.nativescript.app`, projectId)
120+
);
121+
}
87122
}
88123

89124
injector.register("projectConfigService", ProjectConfigService);

lib/services/project-service.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
IProjectSettings,
1414
IProjectCreationSettings,
1515
ITemplateData,
16+
IProjectConfigService,
1617
} from "../definitions/project";
1718
import {
1819
INodePackageManager,
@@ -37,7 +38,8 @@ export class ProjectService implements IProjectService {
3738
private $fs: IFileSystem,
3839
private $logger: ILogger,
3940
private $pacoteService: IPacoteService,
40-
private $projectDataService: IProjectDataService,
41+
private $projectDataService: IProjectDataService,
42+
private $projectConfigService: IProjectConfigService,
4143
private $projectHelper: IProjectHelper,
4244
private $projectNameService: IProjectNameService,
4345
private $projectTemplatesService: IProjectTemplatesService,
@@ -419,7 +421,10 @@ export class ProjectService implements IProjectService {
419421
}
420422

421423
private setAppId(projectDir: string, projectId: string): void {
422-
this.$projectDataService.setNSValue(projectDir, "id", projectId);
424+
// this is what it should do:
425+
// this.$projectConfigService.setValue("id", projectId);
426+
this.$projectConfigService.setAppId(projectId, projectDir);
427+
// this.$projectDataService.setNSValue(projectDir, "id", projectId);
423428
}
424429
}
425430
injector.register("projectService", ProjectService);

0 commit comments

Comments
 (0)