Skip to content

Commit

Permalink
📝 docs(all): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ángel Albiñana Espejo authored and Ángel Albiñana Espejo committed Mar 18, 2024
1 parent 784bec4 commit 39588b3
Show file tree
Hide file tree
Showing 27 changed files with 1,198 additions and 148 deletions.
124 changes: 101 additions & 23 deletions .dev/core/main.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* Core for .dev folder.
* Core for .Utils folder.
*
* @description Functions for .dev folder.
* @description Functions for .Utils folder.
*/
import { spawn } from 'child_process'
import {
execSync, spawn,
} from 'child_process'
import { fileURLToPath } from 'url'
import fs from 'fs'
import path from 'path'

export { zipFile } from './zip.mjs'
import figlet from 'figlet'

export const exec = async cmd => {

Expand Down Expand Up @@ -43,17 +44,18 @@ export const exec = async cmd => {
} )

}
export const getCorePath = () => path.dirname( fileURLToPath( import.meta.url ) )
export const getDevPath = () => path.join( getCorePath(), '..' )

export const pkgFunct = fileName => {

const json = projectPath => JSON.parse( fs.readFileSync( projectPath ) )

let projectPath = path.join( getDevPath(), '..' )
let projectPath = path.join(
path.dirname( fileURLToPath( import.meta.url ) ),
'..', '..',
)

// when is used in the compilated files of 'dist' folder
if ( projectPath.includes( 'dist' ) ) projectPath = path.join( projectPath, '..' )
if ( projectPath.includes( 'dist' ) || projectPath.includes( 'build' ) ) projectPath = path.join( projectPath, '..' )

const pkgPath = path.join( projectPath, fileName + '.json' )
const pkgData = json( pkgPath )
Expand Down Expand Up @@ -82,35 +84,76 @@ export const writeSync = ( projectPath, txt ) => {

console.groupEnd()

}
export const generateASCII = ( projectName = '', collectiveName = 'PIGEON\nPOSSE', font = 'ANSI Shadow' ) => {

return figlet.textSync( `${collectiveName}\n-------\n${projectName}` , {
font,
horizontalLayout : 'default',
verticalLayout : 'default',
whitespaceBreak : true,
} )

}
export const joinPath = path.join
export const joinUrl = ( ...parts ) => {

export const addTextBetweenAMark = async ( projectPath, startMarker, endMarker, textToAdd ) =>{
parts = parts.map( part => part.replace( /^\/+|\/+$/g, '' ) )
return parts.join( '/' )

const filePath = path.join( pkg.dir, projectPath )
const fileContent = fs.readFileSync( filePath, 'utf-8' )
const startIndex = fileContent.indexOf( startMarker ) + startMarker.length
const endIndex = fileContent.indexOf( endMarker )
const newTextContent = `${fileContent.substring( 0, startIndex )}\n${textToAdd}\n${fileContent.substring( endIndex )}`
}
export const constructorLinks = ( links, type = 'link' ) => {

let res = ''
links.forEach( ( link, index ) => {

writeSync( projectPath, newTextContent )
res += type === 'img' ? imgUrl( link ) : `[${link.name}](${link.url})`
if ( index !== links.length - 1 ) res += '\n'

} )
return res

}
export const readJSON = async path =>{

export const addTextBetweenAMark = async ( projectPath, startMarker, endMarker, textToAdd ) => {

try {

const content = fs.readFileSync( path, 'utf-8' )
const data = JSON.parse( content )
return data
const filePath = path.join( pkg.dir, projectPath )
const fileContent = await fs.promises.readFile( filePath, 'utf-8' )
const startIndex = fileContent.indexOf( startMarker )
const endIndex = fileContent.indexOf( endMarker )

// Check if both start and end markers exist
if ( startIndex !== -1 && endIndex !== -1 ) {

// Start and end markers found, adding text between them
console.log( 'Markers found, adding text...' )
const newTextContent = `${fileContent.substring( 0, startIndex + startMarker.length )}\n${textToAdd}\n${fileContent.substring( endIndex )}`

console.log()
console.group( `🐢 Writing: ${filePath}` )
// Write the modified content back to the file
await fs.promises.writeFile( filePath, newTextContent )
console.log( '✅ File overwritten!' )
console.groupEnd()

} else {

// Start or end markers not found
console.log( 'Markers not found in the file.' )

}

} catch ( error ) {

throw Error( error )
// Error handling
console.error( 'Error:', error )

}

}

export const renameAndCopyFiles = async ( oldFileName, tempFileName, newFileName ) => {

try {
Expand Down Expand Up @@ -222,8 +265,43 @@ export const copyDir = async ( src, dest ) => {

}

export const formatString = inputString => {
export const getCurrentDateTime = () => {

const currentDate = new Date()
const year = currentDate.getUTCFullYear()
const month = ( '0' + ( currentDate.getUTCMonth() + 1 ) ).slice( -2 )
const day = ( '0' + currentDate.getUTCDate() ).slice( -2 )
const hours = ( '0' + currentDate.getUTCHours() ).slice( -2 )
const minutes = ( '0' + currentDate.getUTCMinutes() ).slice( -2 )
const seconds = ( '0' + currentDate.getUTCSeconds() ).slice( -2 )

return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`

}

export const imgUrl = ( { name, color = 'black', url, logo = false, type = false } ) => {

if( !type ) type = `badge/${encodeURIComponent( name )}-${color}?`
else type = `${type}?color=${color}&`

return inputString.toLowerCase().replace( / /g, '--' )
const img = `https://img.shields.io/${type}style=for-the-badge${logo ? '&logo=' + encodeURIComponent( logo.toLowerCase() ) : ''}&logoColor=white`

return `[![${name}](${img})](${url})`

}
export const isGitHubAuthenticated = () =>{

try {

const output = execSync( 'gh auth status', {
encoding : 'utf-8',
} )
return output.includes( 'Active account: true' )

} catch ( error ) {

return false

}

}
49 changes: 49 additions & 0 deletions .dev/readme.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Readme.
*
* @description Readme.
*/

import { readme } from './templates/readme.mjs'
import {
pkg, addTextBetweenAMark,
} from './core/main.mjs'

const dynamicReadme = async () => {

try{

const readmeTemp = readme( pkg )
const convertReadme = async filePath => {

await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START MARK -->', '<!-- PIGEONPOSSE END MARK -->', readmeTemp.mark )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START CONTENT -->', '<!-- PIGEONPOSSE END CONTENT -->', readmeTemp.content )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START INDEX -->', '<!-- PIGEONPOSSE END INDEX -->', readmeTemp.index )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START ORG -->', '<!-- PIGEONPOSSE END ORG -->', readmeTemp.org )
await addTextBetweenAMark( filePath, '<!-- PIGEONPOSSE START HEADER -->', '<!-- PIGEONPOSSE END HEADER -->', readmeTemp.header )

}
await convertReadme( 'README.md' )
await convertReadme( 'packages/_core/README.md' )
await convertReadme( 'packages/_core-react/README.md' )
await convertReadme( 'packages/app/README.md' )
await convertReadme( 'packages/docs/README.md' )
await convertReadme( 'packages/exts/README.md' )

}catch( e ){

throw '📝 ' + e

}

}

try {

dynamicReadme()

}catch( e ){

console.log( '❌ ' + e )

}
37 changes: 37 additions & 0 deletions .dev/templates/links.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* DOWNLOAD LINKS.
*
* @description Create web links.
*/

import { constructorLinks } from '../core/main.mjs'

const dataWebLinks = pkg => {

return [
{
name : 'Web', color : 'grey', url : pkg.data.extra.collective.web,
},
{
name : 'About Us', color : 'grey', url : pkg.data.extra.collective.about,
},
{
name : 'Donate', color : 'pink', url : pkg.data.funding.url,
},
{
name : 'Github', logo : 'github', url : pkg.data.extra.collective.gh,
},
{
name : 'Twitter', logo : 'twitter', url : pkg.data.extra.collective.social.twitter,
},
{
name : 'Instagram', logo : 'instagram', url : pkg.data.extra.collective.social.instagram,
},
{
name : 'Medium', logo : 'medium', url : pkg.data.extra.collective.social.medium,
},
]

}

export const collectiveImgLInks = pkg => constructorLinks( dataWebLinks( pkg ), 'img' )
25 changes: 25 additions & 0 deletions .dev/templates/mark.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* MARK.
*
* @description Create mark string.
*/

import { generateASCII } from '../core/main.mjs'
export const mark = pkg => {

const data = pkg.data
const author = data.author.name
const authorLink = data.author.url
const repoUrl = data.repository.url
// const version = data.version ? data.version : 'UNDEFINDED'

return `${generateASCII( pkg.data.extra.productName.toUpperCase() )}
REPOSITORY: ${repoUrl}
AUTHORS:
- ${author} (${authorLink})
DEVELOPED BY ${author} 🐦🌈
`

}
Loading

0 comments on commit 39588b3

Please sign in to comment.