UNPKG

@git.zone/cli

Version:

A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.

152 lines (134 loc) 4.77 kB
import * as plugins from './mod.plugins.js'; import * as paths from '../paths.js'; import * as gulpFunction from '@push.rocks/gulp-function'; import { Project } from '../classes.project.js'; /** * Migrates npmextra.json from old namespace keys to new package-scoped keys */ const migrateNamespaceKeys = (npmextraJson: any): boolean => { let migrated = false; const migrations = [ { oldKey: 'gitzone', newKey: '@git.zone/cli' }, { oldKey: 'tsdoc', newKey: '@git.zone/tsdoc' }, { oldKey: 'npmdocker', newKey: '@git.zone/tsdocker' }, { oldKey: 'npmci', newKey: '@ship.zone/szci' }, { oldKey: 'szci', newKey: '@ship.zone/szci' }, ]; for (const { oldKey, newKey } of migrations) { if (npmextraJson[oldKey]) { if (!npmextraJson[newKey]) { // New key doesn't exist - simple rename npmextraJson[newKey] = npmextraJson[oldKey]; } else { // New key exists - merge old into new (old values don't overwrite new) npmextraJson[newKey] = { ...npmextraJson[oldKey], ...npmextraJson[newKey], }; } delete npmextraJson[oldKey]; migrated = true; console.log(`Migrated npmextra.json: ${oldKey} -> ${newKey}`); } } return migrated; }; /** * Migrates npmAccessLevel from @ship.zone/szci to @git.zone/cli.release.accessLevel * This is a one-time migration for projects using the old location */ const migrateAccessLevel = (npmextraJson: any): boolean => { const szciConfig = npmextraJson['@ship.zone/szci']; // Check if szci has npmAccessLevel that needs to be migrated if (!szciConfig?.npmAccessLevel) { return false; } // Check if we already have the new location const gitzoneConfig = npmextraJson['@git.zone/cli'] || {}; if (gitzoneConfig?.release?.accessLevel) { // Already migrated, just remove from szci delete szciConfig.npmAccessLevel; return true; } // Ensure @git.zone/cli and release exist if (!npmextraJson['@git.zone/cli']) { npmextraJson['@git.zone/cli'] = {}; } if (!npmextraJson['@git.zone/cli'].release) { npmextraJson['@git.zone/cli'].release = {}; } // Migrate the value npmextraJson['@git.zone/cli'].release.accessLevel = szciConfig.npmAccessLevel; delete szciConfig.npmAccessLevel; console.log(`Migrated npmAccessLevel to @git.zone/cli.release.accessLevel`); return true; }; /** * runs the npmextra file checking */ export const run = async (projectArg: Project) => { const formatSmartstream = new plugins.smartstream.StreamWrapper([ plugins.smartgulp.src([`npmextra.json`]), gulpFunction.forEach(async (fileArg: plugins.smartfile.SmartFile) => { const fileString = fileArg.contents.toString(); const npmextraJson = JSON.parse(fileString); // Migrate old namespace keys to new package-scoped keys migrateNamespaceKeys(npmextraJson); // Migrate npmAccessLevel from szci to @git.zone/cli.release.accessLevel migrateAccessLevel(npmextraJson); if (!npmextraJson['@git.zone/cli']) { npmextraJson['@git.zone/cli'] = {}; } const expectedRepoInformation: string[] = [ 'projectType', 'module.githost', 'module.gitscope', 'module.gitrepo', 'module.description', 'module.npmPackagename', 'module.license', ]; const interactInstance = new plugins.smartinteract.SmartInteract(); for (const expectedRepoInformationItem of expectedRepoInformation) { if ( !plugins.smartobject.smartGet( npmextraJson['@git.zone/cli'], expectedRepoInformationItem, ) ) { interactInstance.addQuestions([ { message: `What is the value of ${expectedRepoInformationItem}`, name: expectedRepoInformationItem, type: 'input', default: 'undefined variable', }, ]); } } const answerbucket = await interactInstance.runQueue(); for (const expectedRepoInformationItem of expectedRepoInformation) { const cliProvidedValue = answerbucket.getAnswerFor( expectedRepoInformationItem, ); if (cliProvidedValue) { plugins.smartobject.smartAdd( npmextraJson['@git.zone/cli'], expectedRepoInformationItem, cliProvidedValue, ); } } // delete obsolete // tbd if (!npmextraJson['@ship.zone/szci']) { npmextraJson['@ship.zone/szci'] = {}; } fileArg.setContentsFromString(JSON.stringify(npmextraJson, null, 2)); }), plugins.smartgulp.replace(), ]); await formatSmartstream.run().catch((error) => { console.log(error); }); };