ueno-code-menu
Advanced tools
Comparing version 0.0.3 to 1.0.0
128
package.json
{ | ||
"name": "ueno-code-menu", | ||
"displayName": "ueno-code-menu", | ||
"description": "Ueno tree-view menu items", | ||
"version": "0.0.3", | ||
"publisher": "ueno", | ||
"engines": { | ||
"vscode": "^1.16.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
"name": "ueno-code-menu", | ||
"displayName": "ueno-code-menu", | ||
"description": "Ueno tree-view menu items", | ||
"version": "1.0.0", | ||
"publisher": "ueno", | ||
"engines": { | ||
"vscode": "^1.8.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"onCommand:extension.new-component" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ueno-llc/ueno-code-menu" | ||
}, | ||
"main": "./out/extension", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "extension.new-component", | ||
"title": "New component" | ||
} | ||
], | ||
"activationEvents": [ | ||
"onCommand:extension.new-component" | ||
], | ||
"main": "./out/extension", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "extension.new-component", | ||
"title": "New component" | ||
} | ||
], | ||
"menus": { | ||
"explorer/context": [ | ||
{ | ||
"when": "explorerResourceIsFolder", | ||
"command": "extension.new-component", | ||
"group": "UenoCodeMenu@1" | ||
} | ||
] | ||
"menus": { | ||
"explorer/context": [ | ||
{ | ||
"when": "explorerResourceIsFolder", | ||
"command": "extension.new-component", | ||
"group": "UenoCodeMenu@1" | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"copy": "rm -rf out/templates; cp -R src/templates out/templates", | ||
"compile": "npm run copy; tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install", | ||
"test": "npm run compile && node ./node_modules/vscode/bin/test" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "5.2.0", | ||
"@types/node": "10.1.1", | ||
"typescript": "2.8.3", | ||
"vscode": "1.1.17" | ||
}, | ||
"dependencies": { | ||
"directory-tree": "2.1.0", | ||
"lodash": "4.17.10" | ||
"configuration": { | ||
"type": "object", | ||
"title": "ueno-code-menu", | ||
"properties": { | ||
"UCM.directory": { | ||
"type": "string", | ||
"default": "src/components", | ||
"description": "The default location to create components from the command panel." | ||
}, | ||
"UCM.platform": { | ||
"type": "string", | ||
"enum": [ | ||
"react", | ||
"react-native" | ||
], | ||
"default": "react", | ||
"description": "Either your work under `react` or `react-native`." | ||
}, | ||
"UCM.styles": { | ||
"type": "string", | ||
"enum": [ | ||
"scss", | ||
"less", | ||
"sass", | ||
"css", | ||
"none" | ||
], | ||
"default": "scss", | ||
"description": "What type of file you need for the styles." | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"copy": "rm -rf out/templates; mkdir -p out; cp -R src/templates out/templates", | ||
"compile": "npm run copy; tsc -p ./", | ||
"watch": "mkdir -p out; cp -R src/templates out/templates; tsc -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install", | ||
"test": "npm run compile && node ./node_modules/vscode/bin/test" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "5.2.3", | ||
"@types/node": "10.3.4", | ||
"typescript": "2.9.2", | ||
"vscode": "1.1.34" | ||
}, | ||
"dependencies": { | ||
"directory-tree": "2.1.0", | ||
"lodash": "4.17.10" | ||
} | ||
} |
@@ -1,5 +0,14 @@ | ||
# ueno-code-menu | ||
[![logo](https://user-images.githubusercontent.com/937328/50184775-edc3c880-030d-11e9-9ea5-749d677b7357.png)](https://ueno.co/?utm_source=github&utm_campaign=ueno-code-menu) | ||
<br /><br /> | ||
![banner](https://user-images.githubusercontent.com/937328/50184764-e56b8d80-030d-11e9-88e1-ff92c94762ed.png) | ||
<br /><br /> | ||
[![about](https://user-images.githubusercontent.com/937328/50184746-da186200-030d-11e9-8edb-3227e9300524.png)](https://ueno.co/contact/?utm_source=github&utm_campaign=ueno-code-menu) | ||
<br /><br /> | ||
Adds new component menu in file explorer. | ||
## ueno-code-menu | ||
React and React Native support. | ||
![](https://img.shields.io/vscode-marketplace/d/ueno.ueno-code-menu.svg) | ||
- Adds new component menu in file explorer. | ||
- React and React Native support. | ||
- JavaScript, SCSS, SASS, LESS, and Stylus extensions. |
'use strict'; | ||
import * as vscode from 'vscode'; | ||
@@ -8,122 +9,89 @@ import * as _ from 'lodash'; | ||
const styleTypes = [{ | ||
name: 'SCSS', | ||
ext: 'scss', | ||
}, { | ||
name: 'LESS', | ||
ext: 'less', | ||
}, { | ||
name: 'SASS', | ||
ext: 'sass', | ||
}, { | ||
name: 'CSS', | ||
ext: 'css', | ||
}, { | ||
name: 'None', | ||
ext: null, | ||
}]; | ||
function getConfig() { | ||
return vscode.workspace.getConfiguration('UCM') as any; | ||
} | ||
export function activate(context: vscode.ExtensionContext) { | ||
let disposable = vscode.commands.registerCommand('extension.new-component', async (file) => { | ||
let disposable = vscode.commands.registerCommand('extension.new-component', async (file) => { | ||
const { directory, platform, styles } = getConfig(); | ||
let filePath = file && (file.fsPath || file.path); | ||
let filePath = file && (file.fsPath || file.path); | ||
if (!filePath) { | ||
filePath = `${vscode.workspace.rootPath}/${directory}`; | ||
} | ||
if (!filePath) { | ||
// Show file dialog | ||
const dir = await vscode.window.showOpenDialog({ | ||
canSelectFiles: false, | ||
canSelectFolders: true, | ||
canSelectMany: false, | ||
openLabel: 'Select folder', | ||
}); | ||
} | ||
if (filePath) { | ||
// Ask for name | ||
const nameInput = await vscode.window.showInputBox({ prompt: 'What is the name of the component?' }); | ||
const name = _.deburr(nameInput); | ||
if (filePath) { | ||
// Ask for name | ||
let styleType; | ||
const nameInput = await vscode.window.showInputBox({ prompt: 'What is the name of the component?' }); | ||
const name = _.deburr(nameInput); | ||
// Ask for platform | ||
const platform = await vscode.window.showQuickPick(['React', 'React Native'], { | ||
placeHolder: 'What platform?', | ||
}); | ||
// Which type | ||
const componentType = await vscode.window.showQuickPick(['PureComponent', 'Component'], { | ||
placeHolder: 'Which component type?', | ||
}); | ||
// Create camel case type of component | ||
const props = { | ||
name, | ||
nameKebabCase: _.kebabCase(name), | ||
nameUpperCase: _.upperFirst(_.camelCase(name)), | ||
nameCamelCase: _.camelCase(name), | ||
nameSnakeCase: _.snakeCase(name), | ||
platform: _.kebabCase(platform), | ||
stylesExtension: styles !== 'none' ? styles : null, | ||
}; | ||
if (platform === 'React') { | ||
styleType = await vscode.window.showQuickPick(styleTypes.map(type => type.name), { | ||
placeHolder: 'What kind of style?', | ||
}); | ||
styleType = styleTypes.find(type => type.name === styleType); | ||
} | ||
// Get a directory tree of the template | ||
const treeRoot = dirTree(path.resolve(__dirname, 'templates', props.platform)); | ||
const depth = []; | ||
// Create camel case type of component | ||
const props = { | ||
name, | ||
nameKebabCase: _.kebabCase(name), | ||
nameCamelCase: _.upperFirst(_.camelCase(name)), | ||
nameSnakeCase: _.snakeCase(name), | ||
platform: _.kebabCase(platform), | ||
componentType, | ||
stylesExtension: styleType ? styleType.ext : null, | ||
}; | ||
const replaceFileName = (input, ext = '') => { | ||
let fileName = input; | ||
// Get a directory tree of the template | ||
const treeRoot = dirTree(path.resolve(__dirname, 'templates', props.platform)); | ||
const depth = []; | ||
for (let key in props) { | ||
const propsKey = `__${key}__`; | ||
const replaceFileName = (input, ext = '') => { | ||
let fileName = input; | ||
for (let key in props) { | ||
const propsKey = `__${key}__`; | ||
if (fileName.indexOf(propsKey) >= 0) { | ||
if (props[key] === null) return null; | ||
fileName = fileName.replace(propsKey, props[key]); | ||
} | ||
} | ||
return fileName; | ||
} | ||
if (fileName.indexOf(propsKey) >= 0) { | ||
if (props[key] === null) return null; | ||
fileName = fileName.replace(propsKey, props[key]); | ||
} | ||
} | ||
const processTree = file => { | ||
try { | ||
const { name, size, type, children, extension } = file; | ||
const newName = replaceFileName(name, extension); | ||
if (!newName) return; | ||
if (type === 'directory') { | ||
// Create new directory | ||
depth.push(newName); | ||
const newPath = path.resolve(filePath, ...depth); | ||
console.log('Create folder:', newPath); | ||
fs.mkdirSync(newPath); | ||
children.forEach(processTree); | ||
depth.pop(); | ||
} else { | ||
const newPath = path.resolve(filePath, ...depth, newName); | ||
const contents = fs.readFileSync(file.path, 'utf8'); | ||
const compiled = _.template(contents); | ||
const transformedContents = compiled(props); | ||
console.log('Create file:', newPath); | ||
fs.writeFileSync(newPath, transformedContents); | ||
} | ||
} catch (err) { | ||
console.log('Failed creating file/folder', err); | ||
} | ||
}; | ||
return fileName; | ||
} | ||
if (treeRoot) { | ||
// Walk through tree, rename folders and files. | ||
treeRoot.children.forEach(processTree); | ||
} | ||
const processTree = file => { | ||
try { | ||
const { name, size, type, children, extension } = file; | ||
const newName = replaceFileName(name, extension); | ||
return; | ||
if (!newName) return; | ||
if (type === 'directory') { | ||
// Create new directory | ||
depth.push(newName); | ||
const newPath = path.resolve(filePath, ...depth); | ||
fs.mkdirSync(newPath); | ||
children.forEach(processTree); | ||
depth.pop(); | ||
} else { | ||
const newPath = path.resolve(filePath, ...depth, newName); | ||
const contents = fs.readFileSync(file.path, 'utf8'); | ||
const compiled = _.template(contents); | ||
const transformedContents = compiled(props); | ||
fs.writeFileSync(newPath, transformedContents); | ||
} | ||
} catch (err) { | ||
console.log('Failed creating file/folder', err); | ||
} | ||
}; | ||
vscode.window.showInformationMessage('No location for component'); | ||
}); | ||
if (treeRoot) { | ||
// Walk through tree, rename folders and files. | ||
treeRoot.children.forEach(processTree); | ||
} | ||
context.subscriptions.push(disposable); | ||
return; | ||
} | ||
vscode.window.showInformationMessage('No location for component'); | ||
}); | ||
context.subscriptions.push(disposable); | ||
} | ||
@@ -130,0 +98,0 @@ |
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": [ | ||
"es6" | ||
], | ||
"sourceMap": true, | ||
"rootDir": "src" | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
".vscode-test" | ||
] | ||
} | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"lib": ["es6"], | ||
"sourceMap": true, | ||
"rootDir": "src" | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
".vscode-test", | ||
"src/templates/**/*", | ||
"out/**/*" | ||
] | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
15
0
11644
230
1