-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: override.files neo work * feat: update * Feat/prop types auto complete (#902) * feat: complete proptypes * feat: code snippets (#903) * feat: auto fill content in store's files * docs: update changelog (#909) * refactor: variable rename * fix: dashboard error in external (#911) * feat: import auto complete (#905) * feat: import-auto-complete * feat: export types (#904) * feat: import auto completion (#914) * feat: import auto complete * feat: update release (#913) * fix: code snippets (#915) * fix: code snippets * feat: update registry Co-authored-by: GiveMe-A-Name <[email protected]> Co-authored-by: Hengchang Lu <[email protected]> Co-authored-by: GiveMe-A-Name <[email protected]>
- Loading branch information
1 parent
2c3e7e4
commit dfe740b
Showing
48 changed files
with
6,340 additions
and
5,717 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
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
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
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,32 @@ | ||
{ | ||
"lazy import": { | ||
"prefix": "lazy", | ||
"body": "const ${2:componentName} = lazy(() => import('${1:component}'));" | ||
}, | ||
"lazy import with chunkName": { | ||
"prefix": "lazy", | ||
"body": "const ${3:componentName} = lazy(() => import(/* webpackChunkName: '${2:chunkName}' */ '${1:component}'));" | ||
}, | ||
"useRequest": { | ||
"prefix": "useRequest", | ||
"body": "const { data, error, loading, request } = useRequest(${1:service});" | ||
}, | ||
"mtopRequest": { | ||
"prefix": "mtopRequest", | ||
"body": [ | ||
"Mtop.request({", | ||
"\tapi: '${1:api}',", | ||
"\tv: '${2:version}',", | ||
"\tdata: ${3:data},", | ||
"}).then(", | ||
"\t(value) => { ${4}}", | ||
").catch(", | ||
"\t(error) => { ${5}}", | ||
");" | ||
] | ||
}, | ||
"mtopConfig": { | ||
"prefix": "mtopConfig", | ||
"body": "Mtop.config('${1:configKey}', '${2:configValue}')" | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
extensions/material-helper/src/autoFillContent/autoFillInStore.ts
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,109 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { getProjectFramework } from '@appworks/project-service'; | ||
import * as ejs from 'ejs'; | ||
import * as util from 'util'; | ||
import * as fs from 'fs'; | ||
|
||
const renderFileAsync = util.promisify(ejs.renderFile); | ||
const writeFileAsync = util.promisify(fs.writeFile); | ||
|
||
enum CreateFileTypes { | ||
Null, | ||
Store, | ||
Models, | ||
} | ||
|
||
function checkIsTsorJsFile(filename: string) { | ||
return ['.js', '.ts'].includes(path.extname(filename)); | ||
} | ||
|
||
|
||
/** | ||
* check the file is or not validate Store.[t|j]s file | ||
* conditions: | ||
* 1. the filename must is store.[t|j]s | ||
* 2. the filePath must start with xxx/src or xxx/src/pages/xxx; | ||
*/ | ||
|
||
function checkIsValidateStoreFile(srcDir: string, filePath: string, filename: string): boolean { | ||
const pagesDir = 'src/pages'; | ||
// the file's directory is or not xxx/src | xxx/src/pages/xxx/ | ||
const isInValidateDir = !!vscode.workspace.workspaceFolders?.find((workspaceFolder) => { | ||
return ( | ||
// It prevent user create store.[t|j]s file in models folder, | ||
!filePath.endsWith('/models') && | ||
( | ||
path.join(workspaceFolder.uri.fsPath, srcDir) === filePath || | ||
filePath.startsWith(path.join(workspaceFolder.uri.fsPath, pagesDir)) | ||
) | ||
); | ||
}); | ||
|
||
const storeFilenames = ['store.ts', 'store.js']; | ||
return storeFilenames.includes(filename) && isInValidateDir; | ||
} | ||
|
||
|
||
/** | ||
* check the file is or not validate model file | ||
* conditions: | ||
* 1. file must .js or .ts filename extension; | ||
* | ||
*/ | ||
function checkIsValidateInModelsFolder(srcDir: string, filePath: string, filename: string): boolean { | ||
// models folder | ||
// Example: xxx/models/xx.[t|j]s; | ||
const modelsDir = '/models'; | ||
const isInValidateModelsDir = !!vscode.workspace.workspaceFolders?.find((workspaceFolder) => { | ||
return ( | ||
filePath.includes(path.join(workspaceFolder.uri.fsPath, srcDir)) && | ||
filePath.endsWith(modelsDir) | ||
); | ||
}); | ||
return isInValidateModelsDir && checkIsTsorJsFile(filename); | ||
} | ||
|
||
function getCreateFileType(file: vscode.Uri): CreateFileTypes { | ||
const { fsPath } = file; | ||
const srcDir = 'src'; | ||
const filename = path.basename(fsPath); | ||
const filePath = path.dirname(fsPath); | ||
if (checkIsValidateStoreFile(srcDir, filePath, filename)) { | ||
return CreateFileTypes.Store; | ||
} else if (checkIsValidateInModelsFolder(srcDir, filePath, filename)) { | ||
return CreateFileTypes.Models; | ||
} else { | ||
return CreateFileTypes.Null; | ||
} | ||
} | ||
|
||
async function checkIsValidate(file: vscode.Uri, projectFramework: string): Promise<[CreateFileTypes, boolean]> { | ||
if (['rax-app', 'icejs'].includes(projectFramework)) { | ||
const createFileType = getCreateFileType(file); | ||
return [createFileType, createFileType !== CreateFileTypes.Null]; | ||
} | ||
return [CreateFileTypes.Null, false]; | ||
} | ||
|
||
async function fillContent( | ||
file: vscode.Uri, | ||
projectFramework: string, | ||
createFileType: CreateFileTypes, | ||
) { | ||
const { fsPath: newFsPath } = file; | ||
const dependency = projectFramework === 'icejs' ? 'ice' : 'rax-app'; | ||
const templateName = createFileType === CreateFileTypes.Models ? 'models' : 'store'; | ||
const templatePath = path.join(__dirname, `${templateName}.ts.ejs`); | ||
const content = await renderFileAsync(templatePath, { dependency }); | ||
await writeFileAsync(newFsPath, content); | ||
} | ||
|
||
export default async (file: vscode.Uri) => { | ||
const projectFramework = await getProjectFramework(); | ||
const [createFileType, isValidate] = await checkIsValidate(file, projectFramework); | ||
if (isValidate) { | ||
// auto fill content with the type of file; | ||
await fillContent(file, projectFramework, createFileType); | ||
} | ||
}; |
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
28 changes: 28 additions & 0 deletions
28
extensions/material-helper/src/importAutoComplete/getAlreadyImportSet.ts
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,28 @@ | ||
import * as vscode from 'vscode'; | ||
import getBabelParserPlugins from '../utils/getBabelParserPlugins'; | ||
import { parse } from '@babel/parser'; | ||
import traverse, { NodePath } from '@babel/traverse'; | ||
import { ImportDeclaration } from '@babel/types'; | ||
import { join } from 'path'; | ||
|
||
export default (doc: vscode.TextDocument): Set<string> => { | ||
const importSet: Set<string> = new Set(); | ||
const documentText = doc.getText(); | ||
try { | ||
const ast = parse(documentText, { | ||
sourceType: 'module', | ||
plugins: getBabelParserPlugins('jsx'), | ||
}); | ||
traverse(ast, { | ||
ImportDeclaration(path: NodePath<ImportDeclaration>) { | ||
const { node } = path; | ||
const moduleName = node.source.value; | ||
importSet.add(join(moduleName)); | ||
}, | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|
||
return importSet; | ||
}; |
14 changes: 14 additions & 0 deletions
14
extensions/material-helper/src/importAutoComplete/getCompletionItem.ts
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,14 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import getFilenameWithoutExtname from './getFilenameWithoutExtname'; | ||
|
||
export default function getCompletionItem(itemText: string, moduleValue?: string): vscode.CompletionItem { | ||
// if moduleName is undefined, get it from filename; | ||
const moduleName = moduleValue || getFilenameWithoutExtname(path.basename(itemText)); | ||
const completionItem = new vscode.CompletionItem(`import ${moduleName} from '${itemText}';`, vscode.CompletionItemKind.Variable); | ||
// special deal with { }; | ||
moduleValue = moduleValue === '{ }' ? '{ ${1} }' : `\${1:${moduleName}}`; | ||
completionItem.detail = 'AppWorks'; | ||
completionItem.insertText = new vscode.SnippetString(`import ${moduleValue} from '${itemText}';`); | ||
return completionItem; | ||
} |
Oops, something went wrong.