Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/services/pacote-service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import * as pacote from "pacote";
import * as tar from "tar";
import * as path from "path";

export class PacoteService implements IPacoteService {
constructor(private $npm: INodePackageManager) { }
constructor(private $fs: IFileSystem,
private $npm: INodePackageManager) { }

public async manifest(packageName: string, options?: IPacoteManifestOptions): Promise<any> {
// In case `tns create myapp --template https://github.com/NativeScript/template-hello-world.git` command is executed, pacote module throws an error if cache option is not provided.
const manifestOptions = { cache: await this.$npm.getCachePath() };
const cache = await this.$npm.getCachePath();
const manifestOptions = { cache };
if (options) {
_.extend(manifestOptions, options);
}

if (this.$fs.exists(packageName)) {
packageName = path.resolve(packageName);
}

return pacote.manifest(packageName, manifestOptions);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export class ProjectService implements IProjectService {

this.$logger.trace(`Copying application from '${templateData.templatePath}' into '${destinationDirectory}'.`);
shelljs.cp('-R', path.join(templateData.templatePath, "*"), destinationDirectory);

this.$fs.createDirectory(path.join(projectDir, "platforms"));
break;
case constants.TemplateVersions.v2:
await this.$pacoteService.extractPackage(templateData.templateName, projectDir);
Expand Down
15 changes: 0 additions & 15 deletions test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,15 @@ class ProjectIntegrationTest {
const fs: IFileSystem = this.testInjector.resolve("fs");
const projectDir = path.join(tempFolder, projectName);
const appDirectoryPath = path.join(projectDir, "app");
const platformsDirectoryPath = path.join(projectDir, "platforms");
const tnsProjectFilePath = path.join(projectDir, "package.json");
const tnsModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME, constants.TNS_CORE_MODULES_NAME);
const packageJsonContent = fs.readJson(tnsProjectFilePath);

assert.isTrue(fs.exists(appDirectoryPath));
assert.isTrue(fs.exists(platformsDirectoryPath));
assert.isTrue(fs.exists(tnsProjectFilePath));
assert.isTrue(fs.exists(tnsModulesPath));

assert.isFalse(fs.isEmptyDir(appDirectoryPath));
assert.isTrue(fs.isEmptyDir(platformsDirectoryPath));

const actualAppId = packageJsonContent["nativescript"].id;
const expectedAppId = appId;
Expand All @@ -95,18 +92,6 @@ class ProjectIntegrationTest {

const sourceDir = projectSourceDirectory;

// Hidden files (starting with dots ".") are not copied.
const expectedFiles = fs.enumerateFilesInDirectorySync(sourceDir, (file, stat) => stat.isDirectory() || !_.startsWith(path.basename(file), "."));
const actualFiles = fs.enumerateFilesInDirectorySync(appDirectoryPath);

assert.isTrue(actualFiles.length >= expectedFiles.length, "Files in created project must be at least as files in app dir.");

_.each(expectedFiles, file => {
const relativeToProjectDir = helpers.getRelativeToRootPath(sourceDir, file);
const filePathInApp = path.join(appDirectoryPath, relativeToProjectDir);
assert.isTrue(fs.exists(filePathInApp), `File ${filePathInApp} does not exist.`);
});

// assert dependencies and devDependencies are copied from template to real project
const sourcePackageJsonContent = fs.readJson(path.join(sourceDir, "package.json"));
const missingDeps = _.difference(_.keys(sourcePackageJsonContent.dependencies), _.keys(packageJsonContent.dependencies));
Expand Down