Skip to content

Commit

Permalink
fix issue w11k#2
Browse files Browse the repository at this point in the history
  • Loading branch information
eturella committed Feb 25, 2021
1 parent a76c8e9 commit f8cc23b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
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": {
"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');
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

0 comments on commit f8cc23b

Please sign in to comment.