Skip to content

Commit 0997b31

Browse files
NathanWalkerrigor789
authored andcommitted
chore: migration handling
1 parent a7ba6d9 commit 0997b31

File tree

9 files changed

+188
-68
lines changed

9 files changed

+188
-68
lines changed

docs/man_pages/general/clean.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<% if (isJekyll) { %>---
2+
title: ns clean
3+
position: 24
4+
---<% } %>
5+
6+
# ns clean
7+
8+
### Description
9+
10+
Clean project artifacts.
11+
12+
### Commands
13+
14+
Usage | Synopsis
15+
------|-------
16+
General | `$ ns clean`
17+
18+
<% if(isHtml) { %>
19+
20+
### Related Commands
21+
22+
<% } %>

docs/man_pages/start.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Command | Description
2929
Command | Description
3030
---|---
3131
[create](project/creation/create.html) | Creates a new project for native development with NativeScript.
32+
[clean](general/clean.html) | Cleans project artifacts.
3233
[preview](project/testing/preview.html) | Generates a QR code that can be scanned by the NativeScript PlayGround app.
3334
[platform add `<Platform>`](project/configuration/platform-add.html) | Configures the current project to target the selected platform.
3435
[platform list](project/configuration/platform.html) | Lists all platforms that the project currently targets.

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ injector.requirePublicClass(
163163

164164
injector.require("platformCommandParameter", "./platform-command-param");
165165
injector.requireCommand("create", "./commands/create-project");
166+
injector.requireCommand("clean", "./commands/clean");
166167
injector.requireCommand("generate", "./commands/generate");
167168
injector.requireCommand("platform|*list", "./commands/list-platforms");
168169
injector.requireCommand("platform|add", "./commands/add-platform");

lib/commands/clean.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as path from "path";
2+
import { ICommand, ICommandParameter } from "../common/definitions/commands";
3+
import { injector } from "../common/yok";
4+
import { IFileSystem, IProjectHelper } from "../common/declarations";
5+
import * as constants from "../constants";
6+
7+
export class CleanCommand implements ICommand {
8+
public allowedParameters: ICommandParameter[] = [];
9+
10+
constructor(
11+
private $fs: IFileSystem,
12+
private $logger: ILogger,
13+
private $projectHelper: IProjectHelper
14+
) {}
15+
16+
public async execute(args: string[]): Promise<void> {
17+
this.$fs.deleteDirectory(
18+
path.join(this.$projectHelper.projectDir, constants.HOOKS_DIR_NAME)
19+
);
20+
this.$fs.deleteDirectory(
21+
path.join(this.$projectHelper.projectDir, constants.PLATFORMS_DIR_NAME)
22+
);
23+
this.$fs.deleteDirectory(
24+
path.join(this.$projectHelper.projectDir, constants.NODE_MODULES_FOLDER_NAME)
25+
);
26+
this.$fs.deleteFile(
27+
path.join(this.$projectHelper.projectDir, constants.PACKAGE_LOCK_JSON_FILE_NAME)
28+
);
29+
30+
this.$logger.info("Project successfully cleaned.");
31+
}
32+
}
33+
34+
injector.registerCommand("clean", CleanCommand);

lib/controllers/migrate-controller.ts

+47-15
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,50 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
102102
}
103103

104104
private migrationDependencies: IMigrationDependency[] = [
105-
{ packageName: constants.TNS_CORE_MODULES_NAME, verifiedVersion: "6.0.1" },
105+
{
106+
packageName: constants.SCOPED_TNS_CORE_MODULES,
107+
verifiedVersion: "7.0.0-rc.57",
108+
shouldAddIfMissing: true,
109+
},
110+
{
111+
packageName: constants.TNS_CORE_MODULES_NAME,
112+
shouldRemove: true,
113+
},
114+
{
115+
packageName: "@nativescript/types",
116+
verifiedVersion: "7.0.0-rc.0",
117+
isDev: true,
118+
},
119+
{
120+
packageName: "tns-platform-declarations",
121+
replaceWith: "@nativescript/types",
122+
verifiedVersion: "7.0.0-rc.0",
123+
isDev: true,
124+
},
106125
{
107126
packageName: constants.TNS_CORE_MODULES_WIDGETS_NAME,
108-
verifiedVersion: "6.0.1",
127+
shouldRemove: true,
128+
},
129+
{
130+
packageName: "nativescript-dev-webpack",
131+
shouldRemove: true,
132+
},
133+
{
134+
packageName: constants.WEBPACK_PLUGIN_NAME,
135+
verifiedVersion: "3.0.0-rc.2",
136+
shouldAddIfMissing: true,
137+
isDev: true,
109138
},
110-
{ packageName: "kinvey-nativescript-sdk", verifiedVersion: "4.2.1" },
111-
{ packageName: "nativescript-plugin-firebase", verifiedVersion: "9.0.2" },
112139
{
113140
packageName: "nativescript-vue",
114-
verifiedVersion: "2.3.0",
141+
verifiedVersion: "2.8.0",
115142
shouldMigrateAction: async (
116143
projectData: IProjectData,
117144
allowInvalidVersions: boolean
118145
) => {
119146
const dependency = {
120147
packageName: "nativescript-vue",
121-
verifiedVersion: "2.3.0",
148+
verifiedVersion: "2.8.0",
122149
isDev: false,
123150
};
124151
const result =
@@ -132,6 +159,11 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
132159
},
133160
migrateAction: this.migrateNativeScriptVue.bind(this),
134161
},
162+
{
163+
packageName: "nativescript-angular",
164+
replaceWith: "@nativescript/angular",
165+
verifiedVersion: "10.0.0",
166+
},
135167
{
136168
packageName: "@nativescript/angular",
137169
verifiedVersion: "10.0.0",
@@ -181,7 +213,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
181213
{
182214
packageName: MigrateController.typescriptPackageName,
183215
isDev: true,
184-
verifiedVersion: "3.9.0",
216+
verifiedVersion: "3.9.7",
185217
},
186218
];
187219

@@ -448,11 +480,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
448480
}
449481

450482
private async cleanUpProject(projectData: IProjectData): Promise<void> {
451-
this.$logger.info("Clean old project artefacts.");
452-
this.$projectDataService.removeNSConfigProperty(
453-
projectData.projectDir,
454-
"useLegacyWorkflow"
455-
);
483+
this.$logger.info("Clean old project artifacts.");
456484
this.$fs.deleteDirectory(
457485
path.join(projectData.projectDir, constants.HOOKS_DIR_NAME)
458486
);
@@ -474,7 +502,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
474502
);
475503
}
476504

477-
this.$logger.info("Clean old project artefacts complete.");
505+
this.$logger.info("Clean old project artifacts complete.");
478506
}
479507

480508
private handleAutoGeneratedFiles(
@@ -847,7 +875,11 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
847875
verifiedVersion: "0.11.1",
848876
shouldAddIfMissing: true,
849877
},
850-
{ packageName: "@angular/animations", verifiedVersion: "10.0.0" },
878+
{
879+
packageName: "@angular/animations",
880+
verifiedVersion: "10.0.0",
881+
shouldAddIfMissing: true,
882+
},
851883
{
852884
packageName: "@angular/compiler-cli",
853885
verifiedVersion: "10.0.0",
@@ -872,7 +904,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`;
872904
const dependencies = [
873905
{
874906
packageName: "nativescript-vue-template-compiler",
875-
verifiedVersion: "2.3.0",
907+
verifiedVersion: "2.8.0",
876908
isDev: true,
877909
},
878910
];

lib/controllers/update-controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class UpdateController
181181
}
182182

183183
private async cleanUpProject(projectData: IProjectData) {
184-
this.$logger.info("Clean old project artefacts.");
184+
this.$logger.info("Clean old project artifacts.");
185185
this.$fs.deleteDirectory(
186186
path.join(projectData.projectDir, constants.HOOKS_DIR_NAME)
187187
);
@@ -206,7 +206,7 @@ export class UpdateController
206206
this.$fs.deleteFile(
207207
path.join(projectData.projectDir, constants.PACKAGE_LOCK_JSON_FILE_NAME)
208208
);
209-
this.$logger.info("Clean old project artefacts complete.");
209+
this.$logger.info("Clean old project artifacts complete.");
210210
}
211211

212212
private async updateProject(

lib/project-data.ts

+40-18
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ export class ProjectData implements IProjectData {
137137
): void {
138138
projectDir = projectDir || this.$projectHelper.projectDir || "";
139139
const projectFilePath = this.getProjectFilePath(projectDir);
140-
// If no project found, projectDir should be null
141-
const nsConfig: INsConfig = this.projectConfig.readConfig(projectDir);
140+
// If no project found, projectDir should be null
141+
// handle migration cases
142+
let isMigrate = false;
143+
if (this.$options.argv && this.$options.argv._ && this.$options.argv._.length) {
144+
this.$logger.info('this.$options.argv._[0]:', this.$options.argv._[0]);
145+
isMigrate = this.$options.argv._[0] === 'migrate';
146+
}
147+
this.$logger.info('about to call readConfig...')
148+
this.$logger.info('isMigrate:', isMigrate);
149+
const nsConfig: INsConfig = isMigrate ? null : this.projectConfig.readConfig(projectDir);
142150
let packageJsonData = null;
143151

144152
try {
@@ -151,7 +159,7 @@ export class ProjectData implements IProjectData {
151159
);
152160
}
153161

154-
if (nsConfig && packageJsonData) {
162+
if ((isMigrate || nsConfig) && packageJsonData) {
155163
this.projectDir = projectDir;
156164
this.projectName = this.$projectHelper.sanitizeName(
157165
path.basename(projectDir)
@@ -264,9 +272,15 @@ export class ProjectData implements IProjectData {
264272
public getAppDirectoryRelativePath(): string {
265273
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY]) {
266274
return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];
267-
}
275+
}
276+
277+
if (this.$fs.exists(path.resolve(this.projectDir, constants.SRC_DIR))) {
278+
return constants.SRC_DIR;
279+
} else {
280+
// legacy project setup often uses app folder
281+
return constants.APP_FOLDER_NAME;
282+
}
268283

269-
return constants.SRC_DIR;
270284
}
271285

272286
public getNsConfigRelativePath(): string {
@@ -291,19 +305,27 @@ export class ProjectData implements IProjectData {
291305
private initializeProjectIdentifiers(
292306
config: INsConfig
293307
): Mobile.IProjectIdentifier {
294-
const identifier: Mobile.IProjectIdentifier = {
295-
ios: config.id,
296-
android: config.id,
297-
};
298-
299-
if (config.ios && config.ios.id) {
300-
identifier.ios = config.ios.id;
301-
}
302-
if (config.android && config.android.id) {
303-
identifier.android = config.android.id;
304-
}
305-
306-
return identifier;
308+
if (config) {
309+
const identifier: Mobile.IProjectIdentifier = {
310+
ios: config.id,
311+
android: config.id,
312+
};
313+
314+
if (config.ios && config.ios.id) {
315+
identifier.ios = config.ios.id;
316+
}
317+
if (config.android && config.android.id) {
318+
identifier.android = config.android.id;
319+
}
320+
321+
return identifier;
322+
} else {
323+
// when migrating projects this can be ignored
324+
return {
325+
ios: '',
326+
android: ''
327+
};
328+
}
307329
}
308330

309331
private getProjectType(): string {

0 commit comments

Comments
 (0)