Skip to content

Commit

Permalink
fix(pg): read sample chugsplash file instead of copying from source
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jan 6, 2023
1 parent 8d18b0f commit b70b268
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-clocks-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': patch
---

Fix chugsplash-init bug where task attempted to copy from non-existent file
36 changes: 20 additions & 16 deletions packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ import {
getArtifactsFromCanonicalConfig,
} from '@chugsplash/executor'

import { getSampleContractFile } from '../sample-project'
import {
getSampleContractFile,
sampleChugSplashFileJavaScript,
sampleChugSplashFileTypeScript,
} from '../sample-project'
import {
getBuildInfo,
getContractArtifact,
Expand Down Expand Up @@ -1777,29 +1781,29 @@ export const chugsplashInitTask = async (
const isTypeScriptProject =
path.extname(hre.config.paths.configFile) === '.ts'

// Get the path from the current directory to the sample source files
const sampleSrcPath = path.join(
__dirname,
'..',
'..',
'src',
'sample-project'
)

// Check if the sample ChugSplash file already exists.
const chugsplashFileName = isTypeScriptProject
? 'hello-chugsplash.ts'
: 'hello-chugsplash.js'
const chugsplashFilePathDest = path.join(
const chugsplashFilePath = path.join(
hre.config.paths.chugsplash,
chugsplashFileName
)
if (!fs.existsSync(chugsplashFilePathDest)) {
// Copy the sample ChugSplash file to the destination path.
fs.copyFileSync(
path.join(sampleSrcPath, chugsplashFileName),
chugsplashFilePathDest
if (!fs.existsSync(chugsplashFilePath)) {
// Create the sample ChugSplash file.
fs.writeFileSync(
chugsplashFilePath,
isTypeScriptProject
? sampleChugSplashFileTypeScript
: sampleChugSplashFileJavaScript
)

// TODO: rm
// // Copy the sample ChugSplash file to the destination path.
// fs.copyFileSync(
// path.join(sampleSrcPath, chugsplashFileName),
// chugsplashFilePathDest
// )
}

// Next, we'll create the sample contract file.
Expand Down
18 changes: 0 additions & 18 deletions packages/plugins/src/sample-project/hello-chugsplash.js

This file was deleted.

20 changes: 0 additions & 20 deletions packages/plugins/src/sample-project/hello-chugsplash.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/plugins/src/sample-project/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './sample-contract'
export * from './sample-tests'
export * from './sample-chugsplash-files'
41 changes: 41 additions & 0 deletions packages/plugins/src/sample-project/sample-chugsplash-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const sampleChugSplashFileTypeScript = `import { UserChugSplashConfig } from '@chugsplash/core'
const config: UserChugSplashConfig = {
options: {
projectName: 'Hello ChugSplash',
},
contracts: {
MyFirstContract: {
contract: 'HelloChugSplash',
variables: {
number: 1,
stored: true,
storageName: 'First',
otherStorage: '0x1111111111111111111111111111111111111111',
},
},
},
}
export default config
`

export const sampleChugSplashFileJavaScript = `require('@chugsplash/core')
module.exports = {
options: {
projectName: 'Hello ChugSplash',
},
contracts: {
MyFirstContract: {
contract: 'HelloChugSplash',
variables: {
number: 1,
stored: true,
storageName: 'First',
otherStorage: '0x1111111111111111111111111111111111111111',
},
},
},
}
`

0 comments on commit b70b268

Please sign in to comment.