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 f62379a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2,755 deletions.
6 changes: 0 additions & 6 deletions app.jdl

This file was deleted.

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 };
Loading

0 comments on commit f62379a

Please sign in to comment.