File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
packages/@apphosting/common Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @apphosting/common" ,
3- "version" : " 0.0.5 " ,
3+ "version" : " 0.0.6 " ,
44 "description" : " Shared library code for App Hosting framework adapters" ,
55 "author" : {
66 "name" : " Firebase" ,
1717 },
1818 "scripts" : {
1919 "build" : " tsc" ,
20+ "test" : " ts-mocha -p tsconfig.json 'src/**/*.spec.ts' 'src/*.spec.ts'" ,
2021 "localregistry:start" : " npx verdaccio --config ../publish-dev/verdaccio-config.yaml" ,
2122 "localregistry:publish" : " (npm view --registry=http://localhost:4873 @apphosting/common && npm unpublish --@apphosting:registry=http://localhost:4873 --force); npm publish --@apphosting:registry=http://localhost:4873"
2223 },
Original file line number Diff line number Diff line change 1+ import assert from "assert" ;
2+ import fs from "fs" ;
3+ import path from "path" ;
4+ import os from "os" ;
5+ import { updateOrCreateGitignore } from "./index" ;
6+
7+ describe ( "update or create .gitignore" , ( ) => {
8+ let tmpDir : string ;
9+ beforeEach ( ( ) => {
10+ tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "test-gitignore" ) ) ;
11+ } ) ;
12+
13+ afterEach ( ( ) => {
14+ fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
15+ } ) ;
16+
17+ it ( ".gitignore file exists and is correctly updated with missing paths" , ( ) => {
18+ fs . writeFileSync ( path . join ( tmpDir , ".gitignore" ) , "existingpath/" ) ;
19+
20+ updateOrCreateGitignore ( tmpDir , [ "existingpath/" , "newpath/" ] ) ;
21+
22+ const gitignoreContent = fs . readFileSync ( path . join ( tmpDir , ".gitignore" ) , "utf-8" ) ;
23+ assert . equal ( `existingpath/\nnewpath/` , gitignoreContent ) ;
24+ } ) ;
25+ it ( ".gitignore file does not exist and is created" , ( ) => {
26+ updateOrCreateGitignore ( tmpDir , [ "chickenpath/" , "newpath/" ] ) ;
27+ const gitignoreContent = fs . readFileSync ( path . join ( tmpDir , ".gitignore" ) , "utf-8" ) ;
28+ assert . equal ( `chickenpath/\nnewpath/` , gitignoreContent ) ;
29+ } ) ;
30+ } ) ;
Original file line number Diff line number Diff line change 11import { spawn } from "child_process" ;
2+ import * as fs from "node:fs" ;
3+ import * as path from "node:path" ;
24
35// Output bundle metadata specifications to be written to bundle.yaml
46export interface OutputBundleConfig {
@@ -139,3 +141,26 @@ export function getBuildOptions(): BuildOptions {
139141 projectDirectory : process . cwd ( ) ,
140142 } ;
141143}
144+
145+ /**
146+ * Updates or creates a .gitignore file with the given entries in the given path
147+ */
148+ export function updateOrCreateGitignore ( dirPath : string , entries : string [ ] ) {
149+ const gitignorePath = path . join ( dirPath , ".gitignore" ) ;
150+
151+ if ( ! fs . existsSync ( gitignorePath ) ) {
152+ console . log ( `creating ${ gitignorePath } with entries: ${ entries . join ( "\n" ) } ` ) ;
153+ fs . writeFileSync ( gitignorePath , entries . join ( "\n" ) ) ;
154+ return ;
155+ }
156+
157+ let content = fs . readFileSync ( gitignorePath , "utf-8" ) ;
158+ for ( const entry of entries ) {
159+ if ( ! content . split ( "\n" ) . includes ( entry ) ) {
160+ console . log ( `adding ${ entry } to ${ gitignorePath } ` ) ;
161+ content += `\n${ entry } ` ;
162+ }
163+ }
164+
165+ fs . writeFileSync ( gitignorePath , content ) ;
166+ }
You can’t perform that action at this time.
0 commit comments