Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #2 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@w11k/git-info",
"version": "1.0.2",
"version": "1.0.3",
"description": "A blank schematics",
"scripts": {
"schematics": "schematics",
Expand All @@ -17,6 +17,9 @@
"author": "Kai Henzler",
"license": "MIT",
"schematics": "./src/collection.json",
"ng-add": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this property do?

"save": "devDependencies"
},
"dependencies": {
"@angular-devkit/core": "^9.1.3",
"@angular-devkit/schematics": "^9.1.3",
Expand Down
15 changes: 8 additions & 7 deletions src/git-info/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { apply, chain, mergeWith, move, Rule, SchematicContext, Tree, url } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { concat, Observable, of } from 'rxjs';
import { concatMap, map } from 'rxjs/operators';
import { addPackageJsonDependency, NodeDependencyType } from '../utility/dependencies';
import { addPropertyToGitignore, addPropertyToPackageJson, getLatestNodeVersion, NodePackage } from '../utility/util';

import { addPropertyToGitignore, addPropertyToPackageJson, getLatestNodeVersion, NodePackage, } from '../utility/util';

import { addPackageJsonDependency, NodeDependencyType } from '../utility/dependencies';

import { concat, Observable, of } from 'rxjs';
import { concatMap, map } from 'rxjs/operators';


export function gitInfo(): Rule {
Expand All @@ -25,10 +25,10 @@ function updateDependencies(): Rule {
context.logger.debug('Updating dependencies...');
context.addTask(new NodePackageInstallTask());

const fixedDependencies = of({name: 'fs-extra', version: '6.0.1'})
const fixedDependencies = of({ name: 'fs-extra', version: '6.0.1' })
.pipe(
map((packageFromRegistry: NodePackage) => {
const {name, version} = packageFromRegistry;
const { name, version } = packageFromRegistry;
context.logger.debug(`Adding ${name}:${version} to ${NodeDependencyType.Dev}`);

addPackageJsonDependency(tree, {
Expand All @@ -43,7 +43,7 @@ function updateDependencies(): Rule {
const addLatestDependencies = of('git-describe').pipe(
concatMap((packageName: string) => getLatestNodeVersion(packageName)),
map((packageFromRegistry: NodePackage) => {
const {name, version} = packageFromRegistry;
const { name, version } = packageFromRegistry;
context.logger.debug(`Adding ${name}:${version} to ${NodeDependencyType.Dev}`);

addPackageJsonDependency(tree, {
Expand Down Expand Up @@ -80,6 +80,7 @@ function addScriptsToPackageJson(): Rule {
function addVersionGeneratorToGitignore(): Rule {
return (tree: Tree, context: SchematicContext) => {
addPropertyToGitignore(tree, context, 'src/environments/version.ts');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the old gitignore statement? Let's just go with one that always works instead of having 2

addPropertyToGitignore(tree, context, '*/environments/version.ts');
return tree;
};
}
24 changes: 14 additions & 10 deletions src/utility/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { JsonAstObject, JsonParseMode, parseJsonAst, } from '@angular-devkit/core';
import { JsonAstObject, JsonParseMode, parseJsonAst } from '@angular-devkit/core';
import { SchematicContext, SchematicsException, Tree } from '@angular-devkit/schematics';
import { get } from 'http';
import { pkgJson } from './dependencies';
import { appendPropertyInAstObject, findPropertyInAstObject, insertPropertyInAstObjectInOrder } from './json-utils';

import { SchematicContext, SchematicsException, Tree, } from '@angular-devkit/schematics';

import { pkgJson, } from './dependencies';

import { appendPropertyInAstObject, findPropertyInAstObject, insertPropertyInAstObjectInOrder, } from './json-utils';

import { get } from 'http';

export interface NodePackage {
name: string;
Expand Down Expand Up @@ -58,7 +58,7 @@ export function addPropertyToPackageJson(
// script found, overwrite value
context.logger.debug(`overwriting ${key} with ${value}`);

const {end, start} = innerNode;
const { end, start } = innerNode;

recorder.remove(start.offset, end.offset - start.offset);
recorder.insertRight(start.offset, JSON.stringify(value));
Expand All @@ -77,11 +77,15 @@ export function addPropertyToGitignore(tree: Tree, _context: SchematicContext, f
}

const content = buffer.toString();
_context.logger.debug('gitignore content' + content);
if (content.includes(file)) {
_context.logger.debug('gitignore already includes "' + file + '"');
} else {
_context.logger.debug('gitignore content' + content);

const updatedContent = `${content}\n${file}`;
const updatedContent = `${content}\n${file}`;

tree.overwrite(GIT_IGNORE_FILE, updatedContent);
tree.overwrite(GIT_IGNORE_FILE, updatedContent);
}
} else {
_context.logger.debug('no gitignore found');
}
Expand Down Expand Up @@ -113,7 +117,7 @@ export function getLatestNodeVersion(packageName: string): Promise<NodePackage>
});

function buildPackage(name: string, version: string = DEFAULT_VERSION): NodePackage {
return {name, version};
return { name, version };
}
}

Expand Down