Skip to content

Commit

Permalink
extracted some more function from base-private
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Nov 11, 2022
1 parent 67fa321 commit 3a33885
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 57 deletions.
6 changes: 0 additions & 6 deletions app.jdl

This file was deleted.

54 changes: 27 additions & 27 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Object {
"cassandra": "cassandra:3.11.13",
"cassandraImage": "cassandra",
"cassandraTag": "3.11.13",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.2.1",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.3.0",
"confluentinc/cp-zookeeper": "confluentinc/cp-zookeeper:7.3.0",
"consul": "consul:1.13.3",
"consulConfigLoader": "jhipster/consul-config-loader:v0.4.1",
Expand All @@ -132,10 +132,10 @@ Object {
"elasticsearch": "docker.elastic.co/elasticsearch/elasticsearch:7.17.4",
"elasticsearchImage": "docker.elastic.co/elasticsearch/elasticsearch",
"elasticsearchTag": "7.17.4",
"grafana": "grafana/grafana:9.1.0",
"grafana/grafana": "grafana/grafana:9.1.0",
"grafana": "grafana/grafana:9.2.4",
"grafana/grafana": "grafana/grafana:9.2.4",
"grafanaImage": "grafana/grafana",
"grafanaTag": "9.1.0",
"grafanaTag": "9.2.4",
"grafanaWatcher": "quay.io/coreos/grafana-watcher:v0.0.8",
"grafanaWatcherImage": "quay.io/coreos/grafana-watcher",
"grafanaWatcherTag": "v0.0.8",
Expand All @@ -159,9 +159,9 @@ Object {
"jhipsterRegistry": "jhipster/jhipster-registry:v7.4.0",
"jhipsterRegistryImage": "jhipster/jhipster-registry",
"jhipsterRegistryTag": "v7.4.0",
"kafka": "confluentinc/cp-kafka:7.2.1",
"kafka": "confluentinc/cp-kafka:7.3.0",
"kafkaImage": "confluentinc/cp-kafka",
"kafkaTag": "7.2.1",
"kafkaTag": "7.3.0",
"keycloak": "quay.io/keycloak/keycloak:19.0.3",
"keycloakImage": "quay.io/keycloak/keycloak",
"keycloakTag": "19.0.3",
Expand All @@ -184,10 +184,10 @@ Object {
"mysql": "mysql:8.0.31",
"mysqlImage": "mysql",
"mysqlTag": "8.0.31",
"neo4J": "neo4j:4.4.9",
"neo4J": "neo4j:5.1.0",
"neo4JImage": "neo4j",
"neo4JTag": "4.4.9",
"neo4j": "neo4j:4.4.9",
"neo4JTag": "5.1.0",
"neo4j": "neo4j:5.1.0",
"openzipkin/zipkin": "openzipkin/zipkin:2.23",
"postgres": "postgres:15.0",
"postgresImage": "postgres",
Expand Down Expand Up @@ -466,7 +466,7 @@ Object {
"cassandra": "cassandra:3.11.13",
"cassandraImage": "cassandra",
"cassandraTag": "3.11.13",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.2.1",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.3.0",
"confluentinc/cp-zookeeper": "confluentinc/cp-zookeeper:7.3.0",
"consul": "consul:1.13.3",
"consulConfigLoader": "jhipster/consul-config-loader:v0.4.1",
Expand All @@ -485,10 +485,10 @@ Object {
"elasticsearch": "docker.elastic.co/elasticsearch/elasticsearch:7.17.4",
"elasticsearchImage": "docker.elastic.co/elasticsearch/elasticsearch",
"elasticsearchTag": "7.17.4",
"grafana": "grafana/grafana:9.1.0",
"grafana/grafana": "grafana/grafana:9.1.0",
"grafana": "grafana/grafana:9.2.4",
"grafana/grafana": "grafana/grafana:9.2.4",
"grafanaImage": "grafana/grafana",
"grafanaTag": "9.1.0",
"grafanaTag": "9.2.4",
"grafanaWatcher": "quay.io/coreos/grafana-watcher:v0.0.8",
"grafanaWatcherImage": "quay.io/coreos/grafana-watcher",
"grafanaWatcherTag": "v0.0.8",
Expand All @@ -512,9 +512,9 @@ Object {
"jhipsterRegistry": "jhipster/jhipster-registry:v7.4.0",
"jhipsterRegistryImage": "jhipster/jhipster-registry",
"jhipsterRegistryTag": "v7.4.0",
"kafka": "confluentinc/cp-kafka:7.2.1",
"kafka": "confluentinc/cp-kafka:7.3.0",
"kafkaImage": "confluentinc/cp-kafka",
"kafkaTag": "7.2.1",
"kafkaTag": "7.3.0",
"keycloak": "quay.io/keycloak/keycloak:19.0.3",
"keycloakImage": "quay.io/keycloak/keycloak",
"keycloakTag": "19.0.3",
Expand All @@ -537,10 +537,10 @@ Object {
"mysql": "mysql:8.0.31",
"mysqlImage": "mysql",
"mysqlTag": "8.0.31",
"neo4J": "neo4j:4.4.9",
"neo4J": "neo4j:5.1.0",
"neo4JImage": "neo4j",
"neo4JTag": "4.4.9",
"neo4j": "neo4j:4.4.9",
"neo4JTag": "5.1.0",
"neo4j": "neo4j:5.1.0",
"openzipkin/zipkin": "openzipkin/zipkin:2.23",
"postgres": "postgres:15.0",
"postgresImage": "postgres",
Expand Down Expand Up @@ -819,7 +819,7 @@ Object {
"cassandra": "cassandra:3.11.13",
"cassandraImage": "cassandra",
"cassandraTag": "3.11.13",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.2.1",
"confluentinc/cp-kafka": "confluentinc/cp-kafka:7.3.0",
"confluentinc/cp-zookeeper": "confluentinc/cp-zookeeper:7.3.0",
"consul": "consul:1.13.3",
"consulConfigLoader": "jhipster/consul-config-loader:v0.4.1",
Expand All @@ -838,10 +838,10 @@ Object {
"elasticsearch": "docker.elastic.co/elasticsearch/elasticsearch:7.17.4",
"elasticsearchImage": "docker.elastic.co/elasticsearch/elasticsearch",
"elasticsearchTag": "7.17.4",
"grafana": "grafana/grafana:9.1.0",
"grafana/grafana": "grafana/grafana:9.1.0",
"grafana": "grafana/grafana:9.2.4",
"grafana/grafana": "grafana/grafana:9.2.4",
"grafanaImage": "grafana/grafana",
"grafanaTag": "9.1.0",
"grafanaTag": "9.2.4",
"grafanaWatcher": "quay.io/coreos/grafana-watcher:v0.0.8",
"grafanaWatcherImage": "quay.io/coreos/grafana-watcher",
"grafanaWatcherTag": "v0.0.8",
Expand All @@ -865,9 +865,9 @@ Object {
"jhipsterRegistry": "jhipster/jhipster-registry:v7.4.0",
"jhipsterRegistryImage": "jhipster/jhipster-registry",
"jhipsterRegistryTag": "v7.4.0",
"kafka": "confluentinc/cp-kafka:7.2.1",
"kafka": "confluentinc/cp-kafka:7.3.0",
"kafkaImage": "confluentinc/cp-kafka",
"kafkaTag": "7.2.1",
"kafkaTag": "7.3.0",
"keycloak": "quay.io/keycloak/keycloak:19.0.3",
"keycloakImage": "quay.io/keycloak/keycloak",
"keycloakTag": "19.0.3",
Expand All @@ -890,10 +890,10 @@ Object {
"mysql": "mysql:8.0.31",
"mysqlImage": "mysql",
"mysqlTag": "8.0.31",
"neo4J": "neo4j:4.4.9",
"neo4J": "neo4j:5.1.0",
"neo4JImage": "neo4j",
"neo4JTag": "4.4.9",
"neo4j": "neo4j:4.4.9",
"neo4JTag": "5.1.0",
"neo4j": "neo4j:5.1.0",
"openzipkin/zipkin": "openzipkin/zipkin:2.23",
"postgres": "postgres:15.0",
"postgresImage": "postgres",
Expand Down
28 changes: 9 additions & 19 deletions generators/base/generator-base-private.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import path from 'path';
import _ from 'lodash';
import Generator from 'yeoman-generator';
import chalk from 'chalk';
import shelljs from 'shelljs';
import semver from 'semver';
import { exec } from 'child_process';
import https from 'https';
Expand All @@ -33,7 +32,7 @@ import generatorConstants from '../generator-constants.cjs';
import { stringify } from '../../utils/index.mjs';
import { fieldIsEnum } from '../../utils/field.mjs';
import databaseData from '../sql-constants.mjs';
import { generatedDestinationPath } from './logic/index.mjs';
import { deleteFile, generatedDestinationPath, deleteFolder, moveWithGit } from './logic/index.mjs';

const { JAVA_COMPATIBLE_VERSIONS, SUPPORTED_CLIENT_FRAMEWORKS } = generatorConstants;
const { ANGULAR, REACT, VUE } = SUPPORTED_CLIENT_FRAMEWORKS;
Expand Down Expand Up @@ -152,11 +151,8 @@ export default class PrivateBase extends Generator {
* @param file
*/
removeFile(file) {
file = this.destinationPath(file);
if (file && shelljs.test('-f', file)) {
this.log(`Removing the file - ${file}`);
shelljs.rm(file);
}
// TODO Should not update variable
file = deleteFile(this, file);
}

/**
Expand All @@ -166,11 +162,8 @@ export default class PrivateBase extends Generator {
* @param folder
*/
removeFolder(folder) {
folder = this.destinationPath(folder);
if (folder && shelljs.test('-d', folder)) {
this.log(`Removing the folder - ${folder}`);
shelljs.rm('-rf', folder);
}
// TODO Should not update variable
folder = deleteFolder(this, folder);
}

/**
Expand All @@ -182,13 +175,10 @@ export default class PrivateBase extends Generator {
* @returns {boolean} true if success; false otherwise
*/
gitMove(source, dest) {
source = this.destinationPath(source);
dest = this.destinationPath(dest);
if (source && dest && shelljs.test('-f', source)) {
this.info(`Renaming the file - ${source} to ${dest}`);
return !shelljs.exec(`git mv -f ${source} ${dest}`).code;
}
return true;
const res = moveWithGit(this, source, dest);
// TODO Should not update variables
source = res.source;
dest = res.dest;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion generators/base/logic/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
* limitations under the License.
*/
export { default as locateGenerator } from './generator/locator.mjs';
export { applyOutputPathCustomizer, generatedDestinationPath } from './output/target-path-resolver.mjs';
export { applyOutputPathCustomizer, generatedDestinationPath } from './output/path-resolver.mjs';
export { default as parseJson } from './generator/parsers/json-parser.mjs';
export { deleteFile, deleteFolder, moveWithGit } from './output/file-operations.mjs';
50 changes: 50 additions & 0 deletions generators/base/logic/output/file-operations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2013-2022 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import shelljs from 'shelljs';

const deleteFile = (context, file) => {
const destination = context.destinationPath(file);
if (destination && shelljs.test('-f', destination)) {
context.log(`Removing the file - ${destination}`);
shelljs.rm(destination);
}
return destination;
};

const deleteFolder = (context, folder) => {
const destination = context.destinationPath(folder);
if (destination && shelljs.test('-d', destination)) {
context.log(`Removing the folder - ${destination}`);
shelljs.rm('-rf', destination);
}
return destination;
};

const moveWithGit = (context, from, to) => {
const source = context.destinationPath(from);
const dest = context.destinationPath(to);
if (source && dest && shelljs.test('-f', source)) {
context.info(`Renaming the file - ${source} to ${dest}`);
return !shelljs.exec(`git mv -f ${source} ${dest}`).code;
}
return { source, dest };
};

export { deleteFile, deleteFolder, moveWithGit };
Original file line number Diff line number Diff line change
Expand Up @@ -4799,7 +4799,7 @@ eureka:
- \\"--storage.path=/alertmanager\\"
grafana:
image: grafana/grafana:9.1.0
image: grafana/grafana:9.2.4
ports:
- 3000:3000
volumes:
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/knative.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16907,7 +16907,7 @@ spec:
spec:
containers:
- name: jhipster-grafana
image: grafana/grafana:9.1.0
image: grafana/grafana:9.2.4
ports:
- containerPort: 3000
name: http
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/kubernetes.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ spec:
spec:
containers:
- name: kafka
image: confluentinc/cp-kafka:7.2.1
image: confluentinc/cp-kafka:7.3.0
env:
- name: KAFKA_ADVERTISED_LISTENERS
value: \\"PLAINTEXT://jhipster-kafka.default.svc.cluster.local:9092\\"
Expand Down Expand Up @@ -8523,7 +8523,7 @@ spec:
spec:
containers:
- name: jhipster-grafana
image: grafana/grafana:9.1.0
image: grafana/grafana:9.2.4
ports:
- containerPort: 3000
name: http
Expand Down

0 comments on commit 3a33885

Please sign in to comment.