1- import { runCommand } from '@oclif/test'
2- import { expect } from 'chai'
1+ import { runCommand } from '@oclif/test'
2+ import { expect } from 'chai'
33import * as fs from 'node:fs'
44import * as path from 'node:path'
5- import { fileURLToPath } from 'node:url'
5+ import { fileURLToPath } from 'node:url'
66
77const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
88const fixturesPath = path . join ( __dirname , '../../../fixtures' )
@@ -13,34 +13,34 @@ const testThemePath = path.join(fixturesPath, 'test-theme')
1313
1414describe ( 'theme component copy' , ( ) => {
1515 beforeEach ( ( ) => {
16- fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
17- fs . cpSync ( themePath , testThemePath , { recursive : true } )
16+ fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
17+ fs . cpSync ( themePath , testThemePath , { recursive : true } )
1818 process . chdir ( testCollectionPath )
1919 } )
2020
2121 afterEach ( ( ) => {
22- fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
23- fs . rmSync ( testThemePath , { force : true , recursive : true } )
22+ fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
23+ fs . rmSync ( testThemePath , { force : true , recursive : true } )
2424 } )
2525
2626 it ( 'throws an error if the cwd is not a component collection' , async ( ) => {
2727 process . chdir ( testThemePath )
28- const { error} = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
28+ const { error } = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
2929 expect ( error ) . to . be . instanceOf ( Error )
3030 expect ( error ?. message ) . to . include ( 'Warning: Current directory does not appear to be a component collection.' )
3131 } )
3232
3333 it ( 'throws an error if the component.manifest.json file is not found in the theme directory' , async ( ) => {
3434 process . chdir ( testCollectionPath )
35- fs . rmSync ( path . join ( testThemePath , 'component.manifest.json' ) , { force : true } )
36- const { error} = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
35+ fs . rmSync ( path . join ( testThemePath , 'component.manifest.json' ) , { force : true } )
36+ const { error } = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
3737 expect ( error ) . to . be . instanceOf ( Error )
3838 expect ( error ?. message ) . to . include ( 'Error: component.manifest.json file not found in the theme directory.' )
3939 } )
4040
4141 it ( 'throws an error if the version of the component collection does not match the version in the component.manifest.json file' , async ( ) => {
4242 process . chdir ( testCollectionPath )
43- const { error} = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
43+ const { error } = await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
4444 expect ( error ) . to . be . instanceOf ( Error )
4545 expect ( error ?. message ) . to . include ( 'Version mismatch:' )
4646 } )
@@ -59,4 +59,36 @@ describe('theme component copy', () => {
5959
6060 expect ( fs . existsSync ( path . join ( testThemePath , 'snippets' , 'not-to-be-copied.liquid' ) ) ) . to . be . false
6161 } )
62+
63+ it ( 'adds copyright information to copied files' , async ( ) => {
64+ const packageJsonPath = path . join ( testCollectionPath , 'package.json' )
65+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) )
66+
67+ packageJson . copyright = {
68+ author : 'Test Author' ,
69+ license : 'MIT'
70+ }
71+
72+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) )
73+
74+ const manifestPath = path . join ( testThemePath , 'component.manifest.json' )
75+ const manifest = JSON . parse ( fs . readFileSync ( manifestPath , 'utf8' ) )
76+ manifest . collections [ "@archetype-themes/test-collection" ] . version = "1.0.1"
77+ fs . writeFileSync ( manifestPath , JSON . stringify ( manifest , null , 2 ) )
78+
79+ await runCommand ( [ 'theme' , 'component' , 'copy' , testThemePath ] )
80+
81+ const cssContent = fs . readFileSync ( path . join ( testThemePath , 'assets' , 'to-be-copied.css' ) , 'utf8' )
82+ const year = new Date ( ) . getFullYear ( )
83+ const cssExpectedHeader = `/* @archetype-themes/test-collection v1.0.1 | Copyright © ${ year } Test Author | MIT */`
84+ expect ( cssContent . startsWith ( cssExpectedHeader ) ) . to . be . true
85+
86+ const jsContent = fs . readFileSync ( path . join ( testThemePath , 'assets' , 'to-be-copied.js' ) , 'utf8' )
87+ const jsExpectedHeader = `// @archetype-themes/test-collection v1.0.1 | Copyright © ${ year } Test Author | MIT`
88+ expect ( jsContent . startsWith ( jsExpectedHeader ) ) . to . be . true
89+
90+ const liquidContent = fs . readFileSync ( path . join ( testThemePath , 'snippets' , 'to-be-copied.liquid' ) , 'utf8' )
91+ const liquidExpectedHeader = `{% # @archetype-themes/test-collection v1.0.1 | Copyright © ${ year } Test Author | MIT %}`
92+ expect ( liquidContent . startsWith ( liquidExpectedHeader ) ) . to . be . true
93+ } )
6294} )
0 commit comments