This repository has been archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
end to end hard-coded test of plugin - reading .scss files and displa…
…ying part of pattern-lab/patternlab-node#432
- Loading branch information
1 parent
f194aec
commit ae18e70
Showing
4 changed files
with
126 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var PluginTab = { | ||
|
||
init: function() { | ||
|
||
Panels.add({ | ||
'id': 'sg-panel-scss', | ||
'name': 'SCSS', | ||
'default': false, | ||
'templateID': 'pl-panel-template-code', | ||
'httpRequest': true, | ||
'httpRequestReplace': '.scss', | ||
'httpRequestCompleted': false, | ||
'prismHighlight': true, | ||
'language': 'markup', | ||
'keyCombo': 'ctrl+shift+z' | ||
}); | ||
|
||
} | ||
}; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,96 @@ | ||
"use strict"; | ||
'use strict'; | ||
|
||
const pluginName = 'plugin-node-tab'; | ||
|
||
var fs = require('fs-extra'), | ||
glob = require('glob'), | ||
path = require('path'); | ||
path = require('path'), | ||
tab_loader = require('./src/tab-loader'); | ||
|
||
function onPatternIterate(patternlab, pattern) { | ||
tab_loader(patternlab, pattern); | ||
} | ||
|
||
/** | ||
* Define what events you wish to listen to here | ||
* @param patternlab - global data store which has the handle to the event emitter | ||
*/ | ||
function registerEvents(patternlab){ | ||
|
||
//TODO: list all possible events | ||
patternlab.events.on('patternlab-pattern-write-end', onPatternIterate); | ||
} | ||
|
||
/** | ||
* A single place to define the frontend configuration | ||
*/ | ||
function getPluginFrontendConfig() { | ||
return { | ||
'name':'pattern-lab\/' + pluginName, | ||
'templates':[], | ||
'stylesheets':[], | ||
'javascripts':['patternlab-components\/pattern-lab\/' + pluginName + '\/js\/' + pluginName + '.js'], | ||
'onready':'PluginTab.init()', | ||
'callback':'' | ||
} | ||
} | ||
|
||
function plugin_init(patternlab) { | ||
/** | ||
* The entry point for the plugin. You should not have to alter this code. | ||
* Instead, alter getPluginFrontendConfig() and registerEvents() methods | ||
*/ | ||
function pluginInit(patternlab) { | ||
|
||
if(!patternlab) { | ||
console.error('patternlab object not provided to plugin-init'); | ||
process.exit(1); | ||
} | ||
|
||
//write the plugin json to public/patternlab-components | ||
var pluginConfig = { | ||
"name":"pattern-lab\/plugin-node-tab", | ||
"templates":[], | ||
"stylesheets":[], | ||
"javascripts":["\/js\/plugin-tab.js"], | ||
"onready":"PluginTab.init()", | ||
"callback":"" | ||
} | ||
|
||
var pluginConfig = getPluginFrontendConfig(); | ||
var pluginConfigPathName = path.resolve(patternlab.config.paths.public.root, 'patternlab-components', 'packages'); | ||
try { | ||
fs.outputFileSync(pluginConfigPathName + '/plugin-tab.json', JSON.stringify(pluginConfig, null, 2)); | ||
fs.outputFileSync(pluginConfigPathName + '/' + pluginName + '.json', JSON.stringify(pluginConfig, null, 2)); | ||
} catch (ex) { | ||
console.trace('Error occurred while writing pluginFile configuration'); | ||
console.trace('plugin-node-tab: Error occurred while writing pluginFile configuration'); | ||
console.log(ex); | ||
} | ||
|
||
//add the plugin config to the patternlab-object | ||
if (!patternlab.plugins) { | ||
patternlab.plugins = []; | ||
} | ||
patternlab.plugins.push(pluginConfig); | ||
|
||
//write the plugin dist folder to public/pattern-lab | ||
var pluginFiles = glob.sync(__dirname +'/dist/**/*'); | ||
var pluginFiles = glob.sync(__dirname + '/dist/**/*'); | ||
|
||
if (pluginFiles && pluginFiles.length > 0) { | ||
for (let i = 0; i < pluginFiles.length; i++) { | ||
try { | ||
var fileStat = fs.statSync(pluginFiles[i]); | ||
if (fileStat.isFile()) { | ||
var relativePath = path.relative(__dirname, pluginFiles[i]).replace('dist', ''); //dist is dropped | ||
var writePath = path.join(patternlab.config.paths.public.root,'patternlab-components', 'pattern-lab', 'plugin-node-tab', relativePath); | ||
var writePath = path.join(patternlab.config.paths.public.root,'patternlab-components', 'pattern-lab', pluginName, relativePath); | ||
fs.copySync(pluginFiles[i], writePath); | ||
} | ||
} catch (ex) { | ||
console.trace('Error occurred while copying pluginFile', pluginFiles[i]); | ||
console.trace('plugin-node-tab: Error occurred while copying pluginFile', pluginFiles[i]); | ||
console.log(ex); | ||
} | ||
} | ||
} | ||
|
||
//setup listeners if not already active | ||
if (patternlab.config[pluginName] !== undefined && !patternlab.config[pluginName]) { | ||
|
||
//register events | ||
registerEvents(patternlab); | ||
|
||
//set the plugin key to true to indicate it is installed and ready | ||
patternlab.config[pluginName] = true; | ||
} | ||
|
||
} | ||
|
||
module.exports = plugin_init; | ||
module.exports = pluginInit; |
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,46 @@ | ||
"use strict"; | ||
|
||
var fs = require('fs-extra'), | ||
path = require('path'); | ||
|
||
function findTab(patternlab, pattern) { | ||
|
||
if (!patternlab) { | ||
console.error('plugin-node-tab: patternlab object not provided to findTab'); | ||
process.exit(1); | ||
} | ||
|
||
if (!pattern) { | ||
console.error('plugin-node-tab: pattern object not provided to findTab'); | ||
process.exit(1); | ||
} | ||
|
||
//derive the custom filetype paths from the pattern relPath | ||
var customFileTypePath = path.join(patternlab.config.paths.source.patterns, pattern.relPath); | ||
customFileTypePath = customFileTypePath.substr(0, customFileTypePath.lastIndexOf(".")) + ".scss"; | ||
var customFileTypeOutputPath = patternlab.config.paths.public.patterns + pattern.getPatternLink(patternlab, 'custom', '.scss'); | ||
|
||
//look for a custom filetype for this template | ||
try { | ||
var tabFileName = path.resolve(customFileTypePath); | ||
try { | ||
var tabFileNameStats = fs.statSync(tabFileName); | ||
} catch (err) { | ||
//not a file | ||
} | ||
if (tabFileNameStats && tabFileNameStats.isFile()) { | ||
if (patternlab.config.debug) { | ||
console.log('plugin-node-tab: copied pattern-specific custom file for ' + pattern.patternPartial); | ||
} | ||
fs.copySync(tabFileName, customFileTypeOutputPath); | ||
} else { | ||
fs.outputFileSync(customFileTypeOutputPath, ''); | ||
} | ||
} | ||
catch (err) { | ||
console.log('plugin-node-tab:There was an error parsing sibling JSON for ' + currentPattern.relPath); | ||
console.log(err); | ||
} | ||
} | ||
|
||
module.exports = findTab; |