Skip to content

Commit

Permalink
fix: remove dependency on dot
Browse files Browse the repository at this point in the history
fix: remove dependency on dot
  • Loading branch information
elderfo authored Sep 18, 2019
2 parents d300c57 + a250b1f commit 29fe381
Show file tree
Hide file tree
Showing 8 changed files with 5,504 additions and 2,891 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

28 changes: 19 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ cache:
notifications:
email: false
node_js:
- '12'
- '10'
- '8'
- '7'
- '6'
script:
- yarn run ci
after_success:
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/

jobs:
include:
- stage: test
script:
yarn run ci
# Define the release stage that runs semantic-release
- stage: release
node_js: lts/*
# Advanced: optionally overwrite your default `script` step to skip the tests
# script: skip
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release

4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
environment:
matrix:
- nodejs_version: "12"
- nodejs_version: "10"
- nodejs_version: "8"
- nodejs_version: "7"
- nodejs_version: "6"

# Install scripts. (runs after repo cloning)
install:
Expand Down
27 changes: 8 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,36 @@
"rnstl": "./src/rnstl-cli.js"
},
"devDependencies": {
"codecov": "^2.3.0",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.16.1",
"eslint-config-elderfo": "^1.2.3",
"eslint-watch": "^3.0.0",
"codecov": "^3.5.0",
"faker": "^4.1.0",
"husky": "^0.13.1",
"jest": "^20.0.4",
"lint-staged": "^4.0.2",
"husky": "^3.0.5",
"jest": "^24.9.0",
"lint-staged": "^9.2.5",
"mock-fs": "^4.4.1",
"npm-run-all": "^4.1.2",
"prettier": "^1.5.3",
"semantic-release": "^6.3.2",
"semantic-release": "^15.13.24",
"uuid": "^3.0.1"
},
"dependencies": {
"colors": "^1.1.2",
"dot": "^1.1.1",
"findup": "^0.1.5",
"glob": "^7.1.1",
"yargs": "^8.0.2"
"yargs": "^14.0.0"
},
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --coverage && codecov",
"lint": "esw ./",
"lint:watch": "yarn run lint -- --watch",
"start": "node src/rnstl-cli.js",
"start:help": "node src/rnstl-cli.js --help",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"semantic-release": "semantic-release",
"precommit": "lint-staged",
"ci": "npm-run-all test:ci lint start"
"ci": "npm-run-all test:ci start"
},
"lint-staged": {
"*.js": [
"prettier --single-quote --trailing-comma es5 --write",
"eslint --fix",
"git add",
"jest --bail --findRelatedTests"
]
Expand All @@ -69,9 +61,6 @@
],
"pattern": "**/*.js",
"outputFile": "./output/storyLoader.js"
},
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
32 changes: 14 additions & 18 deletions src/writer/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`writeFile generate story loader 1`] = `
"
// Auto-generated file created by react-native-storybook-loader
"// Auto-generated file created by react-native-storybook-loader
// Do not edit.
//
// https://github.com/elderfo/react-native-storybook-loader.git
function loadStories() {
require('./parent/file3');
require('./src/file1');
require('./src/sub/file2');
require('./src/writer/sub/file4');
require('./src/writer/sub/sub/file5');
require('./parent/file3');
require('./src/file1');
require('./src/sub/file2');
require('./src/writer/sub/file4');
require('./src/writer/sub/sub/file5');
}
const stories = [
'./parent/file3',
'./src/file1',
'./src/sub/file2',
'./src/writer/sub/file4',
'./src/writer/sub/sub/file5',
'./parent/file3',
'./src/file1',
'./src/sub/file2',
'./src/writer/sub/file4',
'./src/writer/sub/sub/file5'
];
module.exports = {
Expand All @@ -33,18 +30,17 @@ module.exports = {
`;

exports[`writeFile should generate dummy story loader if no stories were found 1`] = `
"
// Auto-generated file created by react-native-storybook-loader
"// Auto-generated file created by react-native-storybook-loader
// Do not edit.
//
// https://github.com/elderfo/react-native-storybook-loader.git
function loadStories() {
}
const stories = [
];
module.exports = {
Expand Down
34 changes: 17 additions & 17 deletions src/writer/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
const fs = require('fs');
const path = require('path');
const dot = require('dot');

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

dot.templateSettings.strip = false;

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

const templateContents = `
// Auto-generated file created by react-native-storybook-loader
const formatter = (files, frms, separator) => {
const formatted = files.map(f => frms(f));
return formatted.join(separator);
};

const template = files =>
`// Auto-generated file created by react-native-storybook-loader
// Do not edit.
//
// https://github.com/elderfo/react-native-storybook-loader.git
function loadStories() {
{{~it.files :value:index}}require('{{=value}}');
{{~}}
${formatter(files, file => `\trequire('${file}');`, '\n')}
}
const stories = [
{{~it.files :value:index}}'{{=value}}',
{{~}}
${formatter(files, file => `\t'${file}'`, ',\n')}
];
module.exports = {
Expand All @@ -37,20 +40,17 @@ module.exports = {
`;

const writeFile = (files, outputFile) => {
const template = dot.template(templateContents);
const relativePaths = getRelativePaths(
path.dirname(outputFile),
files
).map(file => file.substring(0, file.lastIndexOf('.'))); // strip file extensions
const relativePaths = getRelativePaths(path.dirname(outputFile), files).map(
file => file.substring(0, file.lastIndexOf('.'))
); // strip file extensions

const output = template({ files: relativePaths });
const output = template(relativePaths);

ensureFileDirectoryExists(outputFile);

fs.writeFileSync(outputFile, output, { encoding });
};

module.exports = {
templateContents,
writeFile,
};
Loading

0 comments on commit 29fe381

Please sign in to comment.