Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/commands/theme/component/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import path from 'node:path'
import Args from '../../../utilities/args.js'
import BaseCommand from '../../../utilities/base-command.js'
import Flags from '../../../utilities/flags.js'
import { getLastCommitHash } from '../../../utilities/git.js'
import { ManifestOptions, generateManifestFiles, getManifest } from '../../../utilities/manifest.js'
import { getNameFromPackageJson, getVersionFromPackageJson } from '../../../utilities/package-json.js'

Expand Down Expand Up @@ -74,8 +75,10 @@ export default class Manifest extends BaseCommand {
)

manifest.files = sortObjectKeys(files)
manifest.collections[collectionName] = manifest.collections[collectionName] || {}
manifest.collections[collectionName].version = collectionVersion
manifest.collections[collectionName] = {
commit: getLastCommitHash(collectionDir),
version: collectionVersion
}

fs.writeFileSync(manifestPath, JSON.stringify(sortObjectKeys(manifest), null, 2))
}
Expand Down
1 change: 1 addition & 0 deletions src/utilities/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const flagDefinitions: Record<string, any> = {
}),

[Flags.SETUP_FILES]: OclifFlags.boolean({
allowNo: true,
char: 's',
default: true,
description: 'copy setup files to theme directory',
Expand Down
19 changes: 19 additions & 0 deletions src/utilities/git.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import {execSync} from 'node:child_process'
import path from 'node:path'

export async function cloneTheme(repoUrl: string, targetDir: string): Promise<void> {
execSync(`git clone ${repoUrl} ${targetDir}`, { stdio: 'inherit' })
}

/**
* Gets the last commit hash for a given directory
* @param directory The directory to get the commit hash for
* @returns The last commit hash or null if not in a git repository
*/
export function getLastCommitHash(directory: string): null | string {
try {
const result = execSync('git rev-parse HEAD', {
cwd: path.resolve(directory),
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'ignore']
})
return result.trim()
} catch {
return null
}
}
3 changes: 2 additions & 1 deletion src/utilities/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export interface PackageJSON {
export interface Manifest {
collections: {
[name: string]: {
[version: string]: string;
commit: null | string;
version: string;
};
}
files: {
Expand Down
21 changes: 21 additions & 0 deletions test/commands/theme/component/map.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'
import {execSync} from 'node:child_process'
import * as fs from 'node:fs'
import * as path from 'node:path'
import {fileURLToPath} from 'node:url'
Expand Down Expand Up @@ -310,4 +311,24 @@ describe('theme component map', () => {

expect(data.files.assets['commented-script.js']).to.be.undefined
})

it('adds the last commit hash to the collection in the manifest', async () => {
// Initialize git repo in test collection
execSync('git init', { cwd: testCollectionPath })
execSync('git config user.email "[email protected]"', { cwd: testCollectionPath })
execSync('git config user.name "Test User"', { cwd: testCollectionPath })
execSync('git add .', { cwd: testCollectionPath })
execSync('git commit -m "Initial commit"', { cwd: testCollectionPath })

// Get the commit hash we just created
const expectedHash = execSync('git rev-parse HEAD', {
cwd: testCollectionPath,
encoding: 'utf8'
}).trim()

await runCommand(['theme', 'component', 'map', testThemePath])

const data = JSON.parse(fs.readFileSync(path.join(testThemePath, 'component.manifest.json'), 'utf8'))
expect(data.collections['@archetype-themes/test-collection'].commit).to.equal(expectedHash)
})
})
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts","./src/commands/theme/component/clean.ts","./src/commands/theme/component/copy.ts","./src/commands/theme/component/dev.ts","./src/commands/theme/component/index.ts","./src/commands/theme/component/install.ts","./src/commands/theme/component/map.ts","./src/commands/theme/generate/import-map.ts","./src/commands/theme/generate/template-map.ts","./src/utilities/args.ts","./src/utilities/base-command.ts","./src/utilities/files.ts","./src/utilities/flags.ts","./src/utilities/git.ts","./src/utilities/logger.ts","./src/utilities/manifest.ts","./src/utilities/nodes.ts","./src/utilities/package-json.ts","./src/utilities/types.ts"],"version":"5.7.2"}
{"root":["./src/index.ts","./src/commands/theme/component/clean.ts","./src/commands/theme/component/copy.ts","./src/commands/theme/component/dev.ts","./src/commands/theme/component/index.ts","./src/commands/theme/component/install.ts","./src/commands/theme/component/map.ts","./src/commands/theme/generate/import-map.ts","./src/commands/theme/generate/template-map.ts","./src/utilities/args.ts","./src/utilities/base-command.ts","./src/utilities/files.ts","./src/utilities/flags.ts","./src/utilities/git.ts","./src/utilities/logger.ts","./src/utilities/manifest.ts","./src/utilities/nodes.ts","./src/utilities/objects.ts","./src/utilities/package-json.ts","./src/utilities/setup.ts","./src/utilities/types.ts"],"version":"5.7.2"}