set template filles

pull/2262/head
yann300 3 years ago
parent 61ae69415e
commit 6995cc33fa
  1. 10
      libs/remix-ui/workspace/src/lib/actions/index.ts
  2. 37
      libs/remix-ui/workspace/src/lib/templates/default.ts
  3. 1
      libs/remix-ui/workspace/src/lib/templates/examples.ts

@ -5,6 +5,7 @@ import { customAction } from '@remixproject/plugin-api/lib/file-system/file-pane
import { displayNotification, displayPopUp, fetchDirectoryError, fetchDirectoryRequest, fetchDirectorySuccess, focusElement, fsInitializationCompleted, hidePopUp, removeInputFieldSuccess, setCurrentWorkspace, setExpandPath, setMode, setWorkspaces } from './payload'
import { listenOnPluginEvents, listenOnProviderEvents } from './events'
import { createWorkspaceTemplate, getWorkspaces, loadWorkspacePreset, setPlugin } from './workspace'
import { defaultContract, defaultScript } from '../templates/default'
import { QueryParams } from '@remix-project/remix-lib'
import JSZip from 'jszip'
@ -172,7 +173,14 @@ export const clearPopUp = async () => {
export const createNewFile = async (path: string, rootDir: string) => {
const fileManager = plugin.fileManager
const newName = await createNonClashingNameAsync(path, fileManager)
const createFile = await fileManager.writeFile(newName, '')
let content = ''
if (newName.endsWith('.sol')) {
content = defaultContract
}
if (newName.endsWith('.js') || newName.endsWith('.ts')) {
content = defaultScript
}
const createFile = await fileManager.writeFile(newName, content)
if (!createFile) {
return dispatch(displayPopUp('Failed to create file ' + newName))

@ -0,0 +1,37 @@
'use strict'
export const defaultContract = `// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title ContractName
* @dev ContractDescription
* @custom:dev-run-script ./scripts/<file name>.ts
*/
contract ContractName {
/**
* @dev function_1 description
*/
function function_1() public {
// code
}
/**
* @dev function_2 description
*/
function function_2() public {
// code
}
}`
export const defaultScript = `
(async () => {
try {
console.log('running script ...')
} catch (e) {
console.log(e.message)
}
})()
`

@ -7,6 +7,7 @@ pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract Storage {

Loading…
Cancel
Save