Skip to content

Commit

Permalink
fix(TEC-20): Windows Scripts, typo, remove API from ng create.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKaempf committed Jan 3, 2025
1 parent 6a46c4f commit 41d05e6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 97 deletions.
92 changes: 7 additions & 85 deletions src/commands/angular/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as crypto from 'crypto';
import { GluegunCommand } from 'gluegun';

import { ExtendedGluegunToolbox } from '../../interfaces/extended-gluegun-toolbox';
Expand All @@ -8,7 +7,7 @@ import { ExtendedGluegunToolbox } from '../../interfaces/extended-gluegun-toolbo
*/
const NewCommand: GluegunCommand = {
alias: ['c'],
description: 'Creates a new angular (fullstack) workspace',
description: 'Creates a new angular workspace',
hidden: false,
name: 'create',
run: async (toolbox: ExtendedGluegunToolbox) => {
Expand All @@ -21,9 +20,8 @@ const NewCommand: GluegunCommand = {
patching,
print: { error, info, spin, success },
prompt: { confirm },
strings: { camelCase, kebabCase, pascalCase },
strings: { kebabCase },
system,
template,
} = toolbox;

// Start timer
Expand Down Expand Up @@ -61,11 +59,6 @@ const NewCommand: GluegunCommand = {
= parameters.second?.toLowerCase().includes('localize')
|| (!parameters.second && (await confirm('Init localize for Angular?', true)));

// Nest-Server
const nestServer
= parameters.second?.toLowerCase().includes('nest')
|| (!parameters.second && (await confirm('Add API (Nest-Server)?', true)));

const gitLink = (
await helper.getInput(null, {
name: 'link to an empty repository (e.g. [email protected]:group/project.git or leave empty for no linking)',
Expand All @@ -85,21 +78,16 @@ const NewCommand: GluegunCommand = {
}

// Remove git folder after clone
await system.run(`cd ${projectDir} && rm -rf .git`);
filesystem.remove(`${projectDir}/.git`);

// Set project name
await filesystem.write(`${projectDir}/lt.json`, JSON.stringify({ name }));
filesystem.write(`${projectDir}/lt.json`, JSON.stringify({ name }));
await patching.update(`${projectDir}/package.json`, (data: Record<string, any>) => {
data.name = kebabCase(name);
data.version = '0.0.0';
return data;
});

// Set up initial props (to pass into templates)
const nameCamel = camelCase(name);
const nameKebab = kebabCase(name);
const namePascal = pascalCase(name);

// Install packages
await system.run(`cd ${projectDir} && npm i`);

Expand All @@ -118,17 +106,17 @@ const NewCommand: GluegunCommand = {
const ngBaseSpinner = spin('Integrate example for Angular');

// Remove gitkeep file
await system.run(`cd ${projectDir}/projects && rm .gitkeep`);
filesystem.remove(`${projectDir}/projects/.gitkeep`);

// Clone ng-base-starter
await system.run(`cd ${projectDir}/projects && git clone https://github.com/lenneTech/ng-base-starter.git app`);

if (filesystem.isDirectory(`./${projectDir}/projects/app`)) {
// Remove git folder after clone
await system.run(`cd ${projectDir}/projects/app && rm -rf .git`);
filesystem.remove(`${projectDir}/projects/app/.git`);

// Remove husky from app project
await system.run(`rm -rf ${projectDir}/projects/app/.husky`);
filesystem.remove(`${projectDir}/projects/app/.husky`);
await patching.update(`${projectDir}/projects/app/package.json`, (data: Record<string, any>) => {
delete data.scripts.prepare;
delete data.devDependencies.husky;
Expand All @@ -150,72 +138,6 @@ const NewCommand: GluegunCommand = {
// Angular example integration done
ngBaseSpinner.succeed('Example for Angular integrated');

// Include files from https://github.com/lenneTech/nest-server-starter
if (nestServer) {
// Init
const serverSpinner = spin('Integrate Nest Server Starter');

// Clone api
await system.run(`cd ${projectDir}/projects && git clone https://github.com/lenneTech/nest-server-starter api`);

// Integrate files
if (filesystem.isDirectory(`./${projectDir}/projects/api`)) {
// Remove git folder from clone
await system.run(`cd ${projectDir}/projects/api && rm -rf .git`);

// Remove husky from api project
await system.run(`rm -rf ${projectDir}/projects/api/.husky`);
await patching.update(`${projectDir}/projects/api/package.json`, (data: Record<string, any>) => {
delete data.scripts.prepare;
delete data.devDependencies.husky;
return data;
});

// Prepare meta.json in api
filesystem.write(`./${projectDir}/projects/api/src/meta.json`, {
description: `API for ${name} app`,
name: `${name}-api-server`,
version: '0.0.0',
});

// Set configuration
for (const env of ['LOCAL', 'DEV', 'TEST', 'PREV', 'PROD']) {
await patching.replace(
`./${projectDir}/projects/api/src/config.env.ts`,
`SECRET_OR_PRIVATE_KEY_${env}`,
crypto.randomBytes(512).toString('base64'),
);
await patching.replace(
`./${projectDir}/projects/api/src/config.env.ts`,
`SECRET_OR_PRIVATE_KEY_${env}_REFRESH`,
crypto.randomBytes(512).toString('base64'),
);
}
await patching.update(`./${projectDir}/projects/api/src/config.env.ts`, data =>
data.replace(/nest-server-/g, `${projectDir}-`),
);

// Set readme
await template.generate({
props: { name, nameCamel, nameKebab, namePascal, repository: gitLink || 'REPOSITORY' },
target: `./${projectDir}/README.md`,
template: 'monorepro/README.md.ejs',
});

// Commit changes
await system.run(`cd ${projectDir} && git add . && git commit -am "feat: Nest Server Starter integrated"`);

// Check if git init is active
if (gitLink) {
`cd ${projectDir} && git push`;
}

// Done
serverSpinner.succeed('Nest Server Starter integrated');
} else {
serverSpinner.warn('Nest Server Starter not integrated');
}
}

// Install all packages
const installSpinner = spin('Install all packages');
Expand Down
10 changes: 5 additions & 5 deletions src/commands/fullstack/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const NewCommand: GluegunCommand = {
const ngBaseSpinner = spin(`Integrate example for ${frontend}`);

// Remove git folder after clone
await system.run(`cd ${projectDir} && rm -rf .git`);
filesystem.remove(`${projectDir}/.git`);

// Check if git init is active
if (addToGit) {
Expand All @@ -126,10 +126,10 @@ const NewCommand: GluegunCommand = {
}

// Remove gitkeep file
await system.run(`cd ${projectDir}/projects && rm .gitkeep`);
filesystem.remove(`${projectDir}/projects/.gitkeep`);

// Remove git folder after clone
await system.run(`cd ${projectDir}/projects/app && rm -rf .git`);
filesystem.remove(`${projectDir}/projects/app/.git`);

// Integrate files
if (filesystem.isDirectory(`./${projectDir}/projects/app`)) {
Expand All @@ -155,15 +155,15 @@ const NewCommand: GluegunCommand = {
// Integrate files
if (filesystem.isDirectory(`./${projectDir}/projects/api`)) {
// Remove git folder from clone
await system.run(`cd ${projectDir}/projects/api && rm -rf .git`);
filesystem.remove(`${projectDir}/projects/api/.git`);

// Prepare meta.json in api
filesystem.write(`./${projectDir}/projects/api/src/meta.json`, {
description: `API for ${name} app`,
name: `${name}-api-server`,
version: '0.0.0',
});

await patching.update(`./${projectDir}/projects/api/src/config.env.ts`, server.replaceSecretOrPrivateKeys);

// Check if git init is active
Expand Down
29 changes: 23 additions & 6 deletions src/commands/git/clean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GluegunCommand } from 'gluegun';
import { GluegunCommand, system } from 'gluegun';

import { ExtendedGluegunToolbox } from '../../interfaces/extended-gluegun-toolbox';

Expand Down Expand Up @@ -54,18 +54,35 @@ const NewCommand: GluegunCommand = {
const timer = startTimer();

// Reset soft
const undoSpinner = spin('Start cleaning');
const undoSpinner = spin('Start cleaning\n');

const resultFetch = await run('git fetch -p');
info(resultFetch);

const resultpull = await run('git pull');
info(resultpull);

const resultDelete = await run(
'git branch --merged | egrep -v "(^\\*|main|dev|develop|beta|intern|release)" | xargs git branch -d',
);
info(resultDelete);
const result = await system.run('git branch --merged');
const excludedBranches = ['main', 'dev', 'develop', 'beta', 'intern', 'release'];

// Local Branches into Array
const branches = result
.split('\n')
.map(branch => branch.trim().replace(/^\* /, '')) // Remove '* '
.filter(branch => branch && !excludedBranches.includes(branch));

if (branches.length === 0) {
info('No branches to delete.');
return;
}

info(`Deleting branches: ${branches.join(', ')}`);

// Delete branches
for (const branch of branches) {
await system.run(`git branch -d ${branch}`);
success(`Deleted branch: ${branch}`);
}

undoSpinner.succeed();

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class Server {
properties: string[] = undefined;
/**
* User how has tested the ${this.pascalCase(modelName)}
* User who has tested the ${this.pascalCase(modelName)}
*/
@Field(() => User, {
description: 'User who has tested the ${this.pascalCase(modelName)}',
Expand Down

0 comments on commit 41d05e6

Please sign in to comment.