Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-storybook-loader

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-storybook-loader - npm Package Compare versions

Comparing version 1.5.1 to 1.6.0

30

package.json
{
"name": "react-native-storybook-loader",
"version": "1.5.1",
"version": "1.6.0",
"repository": "https://github.com/elderfo/react-native-storybook-loader.git",

@@ -12,5 +12,6 @@ "bugs": "https://github.com/elderfo/react-native-storybook-loader/issues",

"devDependencies": {
"codecov": "^2.3.0",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.16.1",
"eslint-config-elderfo": "^1.1.1",
"eslint-config-elderfo": "^1.2.3",
"eslint-watch": "^3.0.0",

@@ -20,3 +21,6 @@ "faker": "^4.1.0",

"jest": "^20.0.4",
"lint-staged": "^4.0.2",
"mock-fs": "^4.4.1",
"npm-run-all": "^4.0.2",
"prettier": "^1.5.3",
"semantic-release": "^6.3.2",

@@ -35,2 +39,3 @@ "uuid": "^3.0.1"

"test:watch": "jest --watch",
"test:ci": "jest --coverage && codecov",
"lint": "esw ./",

@@ -41,4 +46,23 @@ "lint:watch": "yarn run lint -- --watch",

"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"precommit": "yarn run lint && yarn run test && yarn start"
"precommit": "lint-staged",
"ci": "npm-run-all test:ci lint start"
},
"lint-staged": {
"*.js": [
"prettier --single-quote --trailing-comma es5 --write",
"eslint --fix",
"git add",
"jest --bail --findRelatedTests"
]
},
"jest": {
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/vendor/**",
"!**/output/**",
"!**/coverage/**"
],
"coverageDirectory": "./coverage/"
},
"config": {

@@ -45,0 +69,0 @@ "react-native-storybook-loader": {

2

README.md

@@ -7,3 +7,3 @@ # react-native-storybook-loader

[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/elderfo/react-native-storybook-loader?svg=true)](https://ci.appveyor.com/project/elderfo/react-native-storybook-loader)
[![codecov](https://codecov.io/gh/elderfo/react-native-storybook-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/elderfo/react-native-storybook-loader)
## Purpose

@@ -10,0 +10,0 @@

@@ -13,3 +13,3 @@ require('colors');

const resolveLogLevel = (level) => {
const resolveLogLevel = level => {
if (Object.prototype.hasOwnProperty.call(logLevels, level)) {

@@ -21,3 +21,3 @@ return logLevels[level];

const setLogLevel = (level) => {
const setLogLevel = level => {
logLevel = level;

@@ -24,0 +24,0 @@ };

@@ -11,11 +11,19 @@ global.console = {

// Have to require for the mocking of console to work
const { debug, setLogLevel, logLevels, error, info, warn, resolveLogLevel } = require('./logger'); // eslint-disable-line import/first
const {
debug,
setLogLevel,
logLevels,
error,
info,
warn,
resolveLogLevel,
} = require('./logger'); // eslint-disable-line import/first
beforeEach(() => jest.resetAllMocks());
const assertTrue = (fn) => {
const assertTrue = fn => {
expect(fn).toHaveBeenCalled();
};
const assertFalse = (fn) => {
const assertFalse = fn => {
expect(fn).not.toHaveBeenCalled();

@@ -68,3 +76,2 @@ };

describe('logger.debug', () => {

@@ -71,0 +78,0 @@ const fn = global.console.log;

const logger = require('../logger');
const cliResolver = (yargv) => {
const cliResolver = yargv => {
logger.debug('cliResolver', yargv);

@@ -5,0 +5,0 @@ if (!yargv || typeof yargv !== 'object') {

@@ -61,4 +61,6 @@ const fs = require('fs');

return {
searchDir: getConfigSetting(pkg, 'searchDir', true) || getDefaultValue('searchDir'),
outputFile: getConfigSetting(pkg, 'outputFile') || getDefaultValue('outputFile'),
searchDir:
getConfigSetting(pkg, 'searchDir', true) || getDefaultValue('searchDir'),
outputFile:
getConfigSetting(pkg, 'outputFile') || getDefaultValue('outputFile'),
pattern: getConfigSetting(pkg, 'pattern') || getDefaultValue('pattern'),

@@ -83,12 +85,23 @@ };

// Locate and read package.json
const packageJsonFile = path.resolve(findup.sync(processDirectory, 'package.json'), 'package.json');
const packageJsonFile = path.resolve(
findup.sync(processDirectory, 'package.json'),
'package.json'
);
const baseDir = path.dirname(packageJsonFile);
const config = Object.assign({}, getConfigSettings(packageJsonFile, baseDir), overrides);
const config = Object.assign(
{},
getConfigSettings(packageJsonFile, baseDir),
overrides
);
const outputFile = path.resolve(baseDir, config.outputFile);
const outputFiles = [{
outputFile,
patterns: config.searchDir.map(dir => path.resolve(baseDir, dir, config.pattern)),
}];
const outputFiles = [
{
outputFile,
patterns: config.searchDir.map(dir =>
path.resolve(baseDir, dir, config.pattern)
),
},
];

@@ -95,0 +108,0 @@ const returnValue = {

@@ -10,3 +10,4 @@ const path = require('path');

config: {
[appName]: { // match name of the project
[appName]: {
// match name of the project
searchDir,

@@ -31,6 +32,8 @@ pattern,

const expected = {
outputFiles: [{
patterns: [path.resolve(baseDir, './storybook/stories/index.js')],
outputFile: path.resolve(baseDir, './storybook/storyLoader.js'),
}],
outputFiles: [
{
patterns: [path.resolve(baseDir, './storybook/stories/index.js')],
outputFile: path.resolve(baseDir, './storybook/storyLoader.js'),
},
],
};

@@ -44,9 +47,15 @@

test('should resolve expected paths with single search dir', () => {
const packageJsonContents = generatePackageJson('./src/storybook', '**/*.stories.js', './storybook/config.js');
const packageJsonContents = generatePackageJson(
'./src/storybook',
'**/*.stories.js',
'./storybook/config.js'
);
mock({ [packageJsonFilePath]: JSON.stringify(packageJsonContents) });
const expected = {
outputFiles: [{
patterns: [path.resolve(baseDir, './src/storybook/**/*.stories.js')],
outputFile: path.resolve(baseDir, './storybook/config.js'),
}],
outputFiles: [
{
patterns: [path.resolve(baseDir, './src/storybook/**/*.stories.js')],
outputFile: path.resolve(baseDir, './storybook/config.js'),
},
],
};

@@ -63,3 +72,3 @@

'**/*.stories.js',
'./storybook/config.js',
'./storybook/config.js'
);

@@ -69,9 +78,11 @@

const expected = {
outputFiles: [{
patterns: [
path.resolve(baseDir, './src/storybook/**/*.stories.js'),
path.resolve(baseDir, './packages/**/*.stories.js'),
],
outputFile: path.resolve(baseDir, './storybook/config.js'),
}],
outputFiles: [
{
patterns: [
path.resolve(baseDir, './src/storybook/**/*.stories.js'),
path.resolve(baseDir, './packages/**/*.stories.js'),
],
outputFile: path.resolve(baseDir, './storybook/config.js'),
},
],
};

@@ -88,3 +99,3 @@

'**/*.stories.js',
'./storybook/config.js',
'./storybook/config.js'
);

@@ -100,9 +111,11 @@

const expected = {
outputFiles: [{
patterns: [
path.resolve(baseDir, './src/*.js'),
path.resolve(baseDir, './package/pkg1/*.js'),
],
outputFile: path.resolve(baseDir, './storyLoader.js'),
}],
outputFiles: [
{
patterns: [
path.resolve(baseDir, './src/*.js'),
path.resolve(baseDir, './package/pkg1/*.js'),
],
outputFile: path.resolve(baseDir, './storyLoader.js'),
},
],
};

@@ -109,0 +122,0 @@

@@ -7,3 +7,2 @@ #!/usr/bin/env node

const args = require('yargs')

@@ -14,6 +13,8 @@ .usage('$0 [options]')

array: true,
desc: 'The directory or directories, relative to the project root, to search for files in.',
desc:
'The directory or directories, relative to the project root, to search for files in.',
},
pattern: {
desc: "Pattern to search the search directories with. Note: if pattern contains '**/*' it must be escaped with quotes",
desc:
"Pattern to search the search directories with. Note: if pattern contains '**/*' it must be escaped with quotes",
type: 'string',

@@ -30,4 +31,3 @@ },

})
.help()
.argv;
.help().argv;

@@ -34,0 +34,0 @@ if (args.silent) {

@@ -11,5 +11,4 @@ const glob = require('glob');

*/
const loadStories = pattern => glob.sync(pattern)
.map(file => formatPath(file));
const loadStories = pattern => glob.sync(pattern).map(file => formatPath(file));
module.exports = { loadStories };

@@ -7,14 +7,19 @@ const logger = require('./logger');

const writeOutStoryLoader = (pathConfig) => {
const writeOutStoryLoader = pathConfig => {
logger.debug('writeOutStoryLoader', pathConfig);
pathConfig.outputFiles.forEach((outputFileConfig) => {
pathConfig.outputFiles.forEach(outputFileConfig => {
logger.info('Output file: ', outputFileConfig.outputFile);
logger.info('Patterns: ', JSON.stringify(outputFileConfig.patterns));
logger.info(
'Patterns: ',
JSON.stringify(outputFileConfig.patterns)
);
const storyFiles = [];
outputFileConfig.patterns.forEach((pattern) => {
outputFileConfig.patterns.forEach(pattern => {
const patternStories = loadStories(pattern);
Array.prototype.push.apply(storyFiles, patternStories);
logger.info(`Located ${patternStories.length} files matching pattern '${pattern}'`);
logger.info(
`Located ${patternStories.length} files matching pattern '${pattern}'`
);
});

@@ -25,5 +30,10 @@

writeFile(sortedFiles, outputFileConfig.outputFile);
logger.info(`Compiled story loader for ${storyFiles.length} files:\n`, ` ${storyFiles.join('\n ')}`);
logger.info(
`Compiled story loader for ${storyFiles.length} files:\n`,
` ${storyFiles.join('\n ')}`
);
} else {
logger.warn('No files were found matching the specified pattern. Story loader was not written.');
logger.warn(
'No files were found matching the specified pattern. Story loader was not written.'
);
}

@@ -30,0 +40,0 @@ });

@@ -14,10 +14,12 @@ const faker = require('faker');

const config = {
outputFiles: [{
outputFile: faker.system.fileName(),
patterns: [faker.system.fileName(), faker.system.fileName()],
},
{
outputFile: faker.system.fileName(),
patterns: [faker.system.fileName()],
}],
outputFiles: [
{
outputFile: faker.system.fileName(),
patterns: [faker.system.fileName(), faker.system.fileName()],
},
{
outputFile: faker.system.fileName(),
patterns: [faker.system.fileName()],
},
],
};

@@ -28,3 +30,4 @@ const firstFiles = generateArray(faker.system.fileName);

storyFinder.loadStories.mockImplementationOnce(() => firstFiles)
storyFinder.loadStories
.mockImplementationOnce(() => firstFiles)
.mockImplementationOnce(() => secondFiles)

@@ -35,13 +38,20 @@ .mockImplementationOnce(() => thirdFiles);

expect(storyFinder.loadStories)
.toHaveBeenCalledWith(config.outputFiles[0].patterns[0]);
expect(storyFinder.loadStories)
.toHaveBeenCalledWith(config.outputFiles[0].patterns[1]);
expect(storyFinder.loadStories)
.toHaveBeenCalledWith(config.outputFiles[1].patterns[0]);
expect(storyFinder.loadStories).toHaveBeenCalledWith(
config.outputFiles[0].patterns[0]
);
expect(storyFinder.loadStories).toHaveBeenCalledWith(
config.outputFiles[0].patterns[1]
);
expect(storyFinder.loadStories).toHaveBeenCalledWith(
config.outputFiles[1].patterns[0]
);
expect(writer.writeFile)
.toHaveBeenCalledWith(firstFiles.concat(secondFiles).sort(), config.outputFiles[0].outputFile);
expect(writer.writeFile)
.toHaveBeenCalledWith(thirdFiles.concat().sort(), config.outputFiles[1].outputFile);
expect(writer.writeFile).toHaveBeenCalledWith(
firstFiles.concat(secondFiles).sort(),
config.outputFiles[0].outputFile
);
expect(writer.writeFile).toHaveBeenCalledWith(
thirdFiles.concat().sort(),
config.outputFiles[1].outputFile
);
});

@@ -11,5 +11,5 @@ const path = require('path');

const hasPathPrefix = relativePath =>
relativePath.substr(0, 2) === '..'
|| relativePath.substr(0, 2) === './'
|| relativePath.substr(0, 2) === '.\\';
relativePath.substr(0, 2) === '..' ||
relativePath.substr(0, 2) === './' ||
relativePath.substr(0, 2) === '.\\';

@@ -37,3 +37,6 @@ /**

// (accounting for using the wrong seps)
let relativePath = path.relative(formatPath(fromDir, path.sep), formatPath(file, path.sep));
let relativePath = path.relative(
formatPath(fromDir, path.sep),
formatPath(file, path.sep)
);

@@ -53,3 +56,3 @@ // Prefix the path if it is not already prefixed

*/
const ensureFileDirectoryExists = (filePath) => {
const ensureFileDirectoryExists = filePath => {
const directory = path.dirname(filePath);

@@ -56,0 +59,0 @@

@@ -7,3 +7,7 @@ const path = require('path');

const { generateArray } = require('../utils/testUtils');
const { getRelativePath, formatPath, ensureFileDirectoryExists } = require('./pathHelper');
const {
getRelativePath,
formatPath,
ensureFileDirectoryExists,
} = require('./pathHelper');

@@ -56,3 +60,6 @@ afterEach(() => mockfs.restore());

const actual = getRelativePath(faker.system.fileName(), faker.system.fileName());
const actual = getRelativePath(
faker.system.fileName(),
faker.system.fileName()
);

@@ -71,3 +78,6 @@ expect(actual).toEqual(`./${relativePath}`);

const actual = getRelativePath(faker.system.fileName(), faker.system.fileName());
const actual = getRelativePath(
faker.system.fileName(),
faker.system.fileName()
);

@@ -86,3 +96,6 @@ expect(actual).toEqual(relativePath);

const actual = getRelativePath(faker.system.fileName(), faker.system.fileName());
const actual = getRelativePath(
faker.system.fileName(),
faker.system.fileName()
);

@@ -101,3 +114,6 @@ expect(actual).toEqual(relativePath);

const actual = getRelativePath(faker.system.fileName(), faker.system.fileName());
const actual = getRelativePath(
faker.system.fileName(),
faker.system.fileName()
);

@@ -174,3 +190,7 @@ expect(actual).toEqual(relativePath);

mockfs({ [sourceFileDir]: { /* fake directory */ } });
mockfs({
[sourceFileDir]: {
/* fake directory */
},
});

@@ -177,0 +197,0 @@ ensureFileDirectoryExists(sourceFile);

@@ -5,3 +5,6 @@ const fs = require('fs');

const { getRelativePath, ensureFileDirectoryExists } = require('../utils/pathHelper');
const {
getRelativePath,
ensureFileDirectoryExists,
} = require('../utils/pathHelper');
const { encoding } = require('../constants');

@@ -12,6 +15,3 @@

function getRelativePaths(fromDir, files) {
return files
.map(file => getRelativePath(file, fromDir))
.concat()
.sort();
return files.map(file => getRelativePath(file, fromDir)).concat().sort();
}

@@ -26,3 +26,2 @@

function loadStories() {
{{~it.files :value:index}}require('{{=value}}');

@@ -32,4 +31,10 @@ {{~}}

const stories = [
{{~it.files :value:index}}'{{=value}}',
{{~}}
];
module.exports = {
loadStories,
stories,
};

@@ -36,0 +41,0 @@ `;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc