File tree 1 file changed +7
-7
lines changed
1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1
1
import * as yargs from 'yargs' ;
2
2
import * as fse from 'fs-extra' ;
3
- import os from 'os' ;
4
3
import path from 'path' ;
5
4
import findComponents from '../api-docs-builder/utils/findComponents' ;
6
5
import findHooks from '../api-docs-builder/utils/findHooks' ;
7
6
8
7
type CommandOptions = { grep ?: string } ;
9
8
10
- const { EOL } = os ;
11
-
12
9
const PROJECTS = [
13
10
{
14
11
name : 'base' ,
@@ -44,14 +41,17 @@ async function processFile(
44
41
filename : string ,
45
42
options : {
46
43
lineToPrepend ?: string ;
47
- truncate ?: boolean ;
48
44
} = { } ,
49
45
) {
50
- const { lineToPrepend = `'use client';${ EOL } ` , truncate = true } = options ;
46
+ const { lineToPrepend = `'use client';` } = options ;
51
47
const contents = await fse . readFile ( filename , 'utf8' ) ;
52
48
53
- const truncatedContents = truncate ? contents . split ( / \r ? \n / ) . slice ( 1 ) . join ( '\n' ) : contents ;
54
- const newContents = `${ lineToPrepend } ${ truncatedContents } ` ;
49
+ const lines = contents . split ( / \r ? \n / ) ;
50
+ if ( lines [ 0 ] === lineToPrepend ) {
51
+ return ;
52
+ }
53
+
54
+ const newContents = `${ lineToPrepend } \n${ contents } ` ;
55
55
56
56
await fse . writeFile ( filename , newContents ) ;
57
57
}
You can’t perform that action at this time.
0 commit comments