Skip to content

Commit

Permalink
feat: use scoped app templates and fix create project appid
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker authored and rigor789 committed Sep 4, 2020
1 parent 6d97a5f commit e0f8f0f
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 87 deletions.
36 changes: 18 additions & 18 deletions docs/man_pages/project/creation/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Interactively creates a new NativeScript app based on a predefined template.

Template | Synopsis
---------|---------
JavaScript based | `$ tns create [<App Name>] [--js] [--path <Directory>] [--appid <App ID>]`
TypeScript based | `$ tns create [<App Name>] --ts [--path <Directory>] [--appid <App ID>]`
Angular based | `$ tns create [<App Name>] --ng [--path <Directory>] [--appid <App ID>]`
Vue.js based | `$ tns create [<App Name>] --vue [--path <Directory>] [--appid <App ID>]`
Custom template | `$ tns create [<App Name>] [--path <Directory>] [--appid <App ID>] --template <Template>`
JavaScript based | `$ ns create [<App Name>] [--js] [--path <Directory>] [--appid <App ID>]`
TypeScript based | `$ ns create [<App Name>] --ts [--path <Directory>] [--appid <App ID>]`
Angular based | `$ ns create [<App Name>] --ng [--path <Directory>] [--appid <App ID>]`
Vue.js based | `$ ns create [<App Name>] --vue [--path <Directory>] [--appid <App ID>]`
Custom template | `$ ns create [<App Name>] [--path <Directory>] [--appid <App ID>] --template <Template>`

### Options

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

Template | Command
---------|----------
`JavaScript - Hello World`, `--js`, `--javascript` | tns create --template tns-template-hello-world
`JavaScript - SideDrawer` | tns create --template tns-template-drawer-navigation
`JavaScript - Tabs` | tns create --template tns-template-tab-navigation
`TypeScript - Hello World`, `--ts`, `--tsc`, `--typescript` | tns create --template tns-template-hello-world-ts
`TypeScript - SideDrawer` | tns create --template tns-template-drawer-navigation-ts
`TypeScript - Tabs` | tns create --template tns-template-tab-navigation-ts
`Angular - Hello World`, `--ng`, `--angular` | tns create --template tns-template-hello-world-ng
`Angular - SideDrawer` | tns create --template tns-template-drawer-navigation-ng
`Angular - Tabs` | tns create --template tns-template-tab-navigation-ng
`React - Hello World`, `--react`, `--reactjs` | tns create --template tns-template-blank-react
`Vue.js - Blank`, `--vue`, `--vuejs` | tns create --template tns-template-blank-vue
`Vue.js - SideDrawer`, | tns create --template tns-template-drawer-navigation-vue
`Vue.js - Tabs` | tns create --template tns-template-tab-navigation-vue
`JavaScript - Hello World`, `--js`, `--javascript` | ns create --template @nativescript/template-hello-world
`JavaScript - SideDrawer` | ns create --template @nativescript/template-drawer-navigation
`JavaScript - Tabs` | ns create --template @nativescript/template-tab-navigation
`TypeScript - Hello World`, `--ts`, `--tsc`, `--typescript` | ns create --template @nativescript/template-hello-world-ts
`TypeScript - SideDrawer` | ns create --template @nativescript/template-drawer-navigation-ts
`TypeScript - Tabs` | ns create --template @nativescript/template-tab-navigation-ts
`Angular - Hello World`, `--ng`, `--angular` | ns create --template @nativescript/template-hello-world-ng
`Angular - SideDrawer` | ns create --template @nativescript/template-drawer-navigation-ng
`Angular - Tabs` | ns create --template @nativescript/template-tab-navigation-ng
`React - Hello World`, `--react`, `--reactjs` | ns create --template @nativescript/template-blank-react
`Vue.js - Blank`, `--vue`, `--vuejs` | ns create --template @nativescript/template-blank-vue
`Vue.js - SideDrawer`, | ns create --template @nativescript/template-drawer-navigation-vue
`Vue.js - Tabs` | ns create --template @nativescript/template-tab-navigation-vue

### Related Commands

Expand Down
18 changes: 9 additions & 9 deletions lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
},
{
key: CreateProjectCommand.DrawerTemplateKey,
value: "tns-template-drawer-navigation",
value: "@nativescript/template-drawer-navigation",
description: CreateProjectCommand.DrawerTemplateDescription,
},
{
key: CreateProjectCommand.TabsTemplateKey,
value: "tns-template-tab-navigation",
value: "@nativescript/template-tab-navigation",
description: CreateProjectCommand.TabsTemplateDescription,
},
];
Expand All @@ -237,12 +237,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
},
{
key: CreateProjectCommand.DrawerTemplateKey,
value: "tns-template-drawer-navigation-ts",
value: "@nativescript/template-drawer-navigation-ts",
description: CreateProjectCommand.DrawerTemplateDescription,
},
{
key: CreateProjectCommand.TabsTemplateKey,
value: "tns-template-tab-navigation-ts",
value: "@nativescript/template-tab-navigation-ts",
description: CreateProjectCommand.TabsTemplateDescription,
},
];
Expand All @@ -259,12 +259,12 @@ can skip this prompt next time using the --template option, or the --ng, --react
},
{
key: CreateProjectCommand.DrawerTemplateKey,
value: "tns-template-drawer-navigation-ng",
value: "@nativescript/template-drawer-navigation-ng",
description: CreateProjectCommand.DrawerTemplateDescription,
},
{
key: CreateProjectCommand.TabsTemplateKey,
value: "tns-template-tab-navigation-ng",
value: "@nativescript/template-tab-navigation-ng",
description: CreateProjectCommand.TabsTemplateDescription,
},
];
Expand All @@ -288,17 +288,17 @@ can skip this prompt next time using the --template option, or the --ng, --react
const templates = [
{
key: CreateProjectCommand.BlankTemplateKey,
value: "tns-template-blank-vue",
value: "@nativescript/template-blank-vue",
description: CreateProjectCommand.BlankTemplateDescription,
},
{
key: CreateProjectCommand.DrawerTemplateKey,
value: "tns-template-drawer-navigation-vue",
value: "@nativescript/template-drawer-navigation-vue",
description: CreateProjectCommand.DrawerTemplateDescription,
},
{
key: CreateProjectCommand.TabsTemplateKey,
value: "tns-template-tab-navigation-vue",
value: "@nativescript/template-tab-navigation-vue",
description: CreateProjectCommand.TabsTemplateDescription,
},
];
Expand Down
18 changes: 9 additions & 9 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ export class ReleaseType {
}

export const RESERVED_TEMPLATE_NAMES: IStringDictionary = {
default: "tns-template-hello-world",
javascript: "tns-template-hello-world",
tsc: "tns-template-hello-world-ts",
vue: "tns-template-blank-vue",
typescript: "tns-template-hello-world-ts",
ng: "tns-template-hello-world-ng",
angular: "tns-template-hello-world-ng",
react: "tns-template-blank-react",
reactjs: "tns-template-blank-react",
default: "@nativescript/template-hello-world",
javascript: "@nativescript/template-hello-world",
tsc: "@nativescript/template-hello-world-ts",
vue: "@nativescript/template-blank-vue",
typescript: "@nativescript/template-hello-world-ts",
ng: "@nativescript/template-hello-world-ng",
angular: "@nativescript/template-hello-world-ng",
react: "@nativescript/template-blank-react",
reactjs: "@nativescript/template-blank-react",
};

export const ANALYTICS_LOCAL_TEMPLATE_PREFIX = "localTemplate_";
Expand Down
56 changes: 23 additions & 33 deletions lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class MigrateController
implements IMigrateController {
private static COMMON_MIGRATE_MESSAGE =
"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";
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 6.0.
Use the \`tns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 6.0.
private static UNABLE_TO_MIGRATE_APP_ERROR = `The current application is not compatible with NativeScript CLI 7.0.
Use the \`ns migrate\` command to migrate the app dependencies to a form compatible with NativeScript 7.0.
Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
private static MIGRATE_FINISH_MESSAGE = `The \`tns migrate\` command does ${MigrateController.COMMON_MIGRATE_MESSAGE}`;

Expand Down Expand Up @@ -133,15 +133,15 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
migrateAction: this.migrateNativeScriptVue.bind(this),
},
{
packageName: "nativescript-angular",
verifiedVersion: "8.0.2",
packageName: "@nativescript/angular",
verifiedVersion: "10.0.0",
shouldMigrateAction: async (
projectData: IProjectData,
allowInvalidVersions: boolean
) => {
const dependency = {
packageName: "nativescript-angular",
verifiedVersion: "8.0.2",
packageName: "@nativescript/angular",
verifiedVersion: "10.0.0",
isDev: false,
};
const result =
Expand All @@ -155,8 +155,6 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
},
migrateAction: this.migrateNativeScriptAngular.bind(this),
},
{ packageName: "nativescript-permissions", verifiedVersion: "1.3.0" },
{ packageName: "nativescript-cardview", verifiedVersion: "3.2.0" },
{
packageName: "@nativescript/unit-test-runner",
verifiedVersion: "1.0.0",
Expand All @@ -183,17 +181,14 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
{
packageName: MigrateController.typescriptPackageName,
isDev: true,
verifiedVersion: "3.4.5",
},
{ packageName: "nativescript-localize", verifiedVersion: "4.2.0" },
{ packageName: "nativescript-dev-babel", verifiedVersion: "0.2.1" },
{ packageName: "nativescript-nfc", verifiedVersion: "4.0.1" },
verifiedVersion: "3.9.0",
}
];

get verifiedPlatformVersions(): IDictionary<string> {
return {
[this.$devicePlatformsConstants.Android.toLowerCase()]: "6.0.0",
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "6.0.1",
[this.$devicePlatformsConstants.Android.toLowerCase()]: "7.0.0",
[this.$devicePlatformsConstants.iOS.toLowerCase()]: "7.0.0",
};
}

Expand Down Expand Up @@ -809,68 +804,63 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
const dependencies = [
{
packageName: "@angular/platform-browser-dynamic",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/common",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/compiler",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/core",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/forms",
verifiedVersion: "8.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/http",
verifiedVersion: "8.0.0-beta.10",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/platform-browser",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "@angular/router",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
shouldAddIfMissing: true,
},
{
packageName: "rxjs",
verifiedVersion: "6.3.3",
verifiedVersion: "6.6.0",
shouldAddIfMissing: true,
},
{
packageName: "zone.js",
verifiedVersion: "0.9.1",
verifiedVersion: "0.11.1",
shouldAddIfMissing: true,
},
{ packageName: "@angular/animations", verifiedVersion: "8.0.0" },
{ packageName: "@angular/animations", verifiedVersion: "10.0.0" },
{
packageName: "@angular/compiler-cli",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
isDev: true,
},
{
packageName: "@ngtools/webpack",
verifiedVersion: "8.0.0",
verifiedVersion: "10.0.0",
isDev: true,
},
{
packageName: "@angular-devkit/build-angular",
verifiedVersion: "0.800.3",
verifiedVersion: "0.1000.8",
isDev: true,
},
];
Expand Down
6 changes: 5 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ interface IProjectConfigService {
* Get value for a given config key path
* @param key the property key path
*/
getValue(key: string): any;
getValue(key: string): any;

detectInfo(projectDir?: string): { hasTS: boolean; hasJS: boolean, configJSFilePath: string; configTSFilePath: string };

setAppId(projectId: string, projectDir?: string): void;
}

interface IAssetItem {
Expand Down
39 changes: 37 additions & 2 deletions lib/services/project-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export class ProjectConfigService implements IProjectConfigService {
return this.$injector.resolve("projectHelper");
}

public readConfig(projectDir?: string): INsConfig {
public detectInfo(
projectDir?: string
): {
hasTS: boolean;
hasJS: boolean;
configJSFilePath: string;
configTSFilePath: string;
} {
const configJSFilePath = path.join(
projectDir || this.projectHelper.projectDir,
CONFIG_FILE_NAME_JS
Expand All @@ -39,7 +46,6 @@ export class ProjectConfigService implements IProjectConfigService {
projectDir || this.projectHelper.projectDir,
CONFIG_FILE_NAME_TS
);

const hasTS = this.$fs.exists(configTSFilePath);
const hasJS = this.$fs.exists(configJSFilePath);

Expand All @@ -55,6 +61,19 @@ export class ProjectConfigService implements IProjectConfigService {
);
}

return {
hasTS,
hasJS,
configJSFilePath,
configTSFilePath,
};
}

public readConfig(projectDir?: string): INsConfig {
const { hasTS, configJSFilePath, configTSFilePath } = this.detectInfo(
projectDir
);

let config: INsConfig;

if (hasTS) {
Expand Down Expand Up @@ -84,6 +103,22 @@ export class ProjectConfigService implements IProjectConfigService {
public getValue(key: string): any {
return _.get(this.readConfig(), key);
}

// TODO: improve to set any value
// public setValue(projectDir?: string) {
public setAppId(projectId: string, projectDir?: string) {
const { hasTS, configJSFilePath, configTSFilePath } = this.detectInfo(
projectDir
);

const configPath = hasTS ? configTSFilePath : configJSFilePath;

const rawSource = this.$fs.readText(configPath);
this.$fs.writeFile(
configPath,
rawSource.replace(`org.nativescript.app`, projectId)
);
}
}

injector.register("projectConfigService", ProjectConfigService);
9 changes: 7 additions & 2 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IProjectSettings,
IProjectCreationSettings,
ITemplateData,
IProjectConfigService,
} from "../definitions/project";
import {
INodePackageManager,
Expand All @@ -37,7 +38,8 @@ export class ProjectService implements IProjectService {
private $fs: IFileSystem,
private $logger: ILogger,
private $pacoteService: IPacoteService,
private $projectDataService: IProjectDataService,
private $projectDataService: IProjectDataService,
private $projectConfigService: IProjectConfigService,
private $projectHelper: IProjectHelper,
private $projectNameService: IProjectNameService,
private $projectTemplatesService: IProjectTemplatesService,
Expand Down Expand Up @@ -419,7 +421,10 @@ export class ProjectService implements IProjectService {
}

private setAppId(projectDir: string, projectId: string): void {
this.$projectDataService.setNSValue(projectDir, "id", projectId);
// this is what it should do:
// this.$projectConfigService.setValue("id", projectId);
this.$projectConfigService.setAppId(projectId, projectDir);
// this.$projectDataService.setNSValue(projectDir, "id", projectId);
}
}
injector.register("projectService", ProjectService);
Loading

0 comments on commit e0f8f0f

Please sign in to comment.