-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support create component and improve jumpdef (#125)
* feat: support create component and improve jumpdef * chore: add eol
- Loading branch information
Showing
13 changed files
with
298 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const COMMANDS = { | ||
createComponent: 'minapp-vscode.createMiniprogramComponent' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Uri, window, workspace } from 'vscode'; | ||
import * as fs from 'fs/promises'; | ||
import * as path from 'path'; | ||
|
||
import { config } from '../plugin/lib/config'; | ||
|
||
const jsonTpl = | ||
`{ | ||
"component": true | ||
} | ||
`; | ||
|
||
/** | ||
* create a new miniprogram component | ||
* | ||
* my-component | ||
* |- my-component.json | ||
* |- my-component.wxml | ||
* |- my-component.js | ||
* |- my-component.wxss | ||
*/ | ||
export async function createMiniprogramComponent(folderPath: Uri): Promise<void> { | ||
const input = await window.showInputBox({ | ||
prompt: "Enter the component name", | ||
validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Component name must not be empty.", | ||
placeHolder: "Example: avatar (will create 4 files, default is avatar.wxss avatar.json avatar.js avatar.wxml)", | ||
ignoreFocusOut: true, | ||
}) | ||
const componentName = input?.trim(); | ||
if (componentName) { | ||
fs.mkdir(path.join(folderPath.fsPath, componentName)).then(() => { | ||
Promise.all([ | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.jsExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.cssExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.wxmlExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.json'), jsonTpl) | ||
]).then(() => { | ||
const openJsPath = Uri.file(path.join(folderPath.fsPath, componentName, componentName + '.' + config.jsExtname)); | ||
workspace.openTextDocument(openJsPath).then(doc => { | ||
if (doc) { | ||
window.showTextDocument(doc); | ||
} | ||
}); | ||
}).catch(err => { | ||
window.showErrorMessage(`create file error: ${err}`) | ||
}) | ||
}).catch(err => { | ||
window.showErrorMessage(`create folder error: ${err}`) | ||
}) | ||
} | ||
} |
Oops, something went wrong.