Code Monkey home page Code Monkey logo

generator-skatejs's Introduction

[UNMAINTAINED] generator-skatejs NPM version Build Status Coverage Status

Create Skate.js components with Webpack

This generator sets up a project scaffold that helps with a number of things:

  • Creating an easy-to-use development environment through Storybook
  • Styling components through Sass
  • Localizing text
  • Testing component logic through Karma
  • Bundling a preparing a production package with Webpack 2

Installation

Before you can install yeoman and this generator, make sure you have Node.js 6.7.0 or better installed, as well as the yarn package manager.

With this complete, you can install the command line utilities that you need:

yarn global add yo generator-skatejs

The commands for running, testing and building your project are included in the generated README.

Generating a new project

To generate a new project:

mkdir my-cool-component
cd my-cool-component
yo skatejs

This will walk you through any required configuration.

Adding more components to an existing project

Since the practice of composing multiple components together is so common, this generator also allows you to add new components to an existing project.

yo skatejs:component my-second-component

This will create a new component and test file with the same structure as the first one.

NOTE: The newly created component will be automatically imported for you through a codemod that modifies the src/index.js file. The way that it inserts newlines is not something that I can control; you might want to verify that the file looks okay after generating a new component.

Adding translation files

Depending on your site's needs, you might need to localize your UI so that it can be translated into multiple languages. This project includes a sub-generator for creating YAML files to store your translation keys, and helper functions to render those strings.

You can create a new translation locale using:

yo skatejs:translation en-US

where en-US could be any locale identifier. This identifier is used to match against the value passed into the createTranslationHelper function, which would presumably be the current locale.

The helper that is generated can then be imported and used like so, assuming your component has a locale prop:

import createTranslationHelper from '../../util/translation.js';

const { Component, h } = skate;

export default class extends Component {
  renderCallback({ locale }) {
    const t = createTranslationHelper(locale);

    return (
      <p>
        { t('key') }
      </p>
    );
  }
}

You can also use objects to namespace translation strings to keep things better organized. If you had a YAML file structure like this, for example:

header:
  title: My Site
  about: About me

You could access those values like so:

const t = createTranslationHelper(locale);

t('header.title'); // `My Site`
t('header.about'); // `About me`

License

MIT © Alex LaFroscia

generator-skatejs's People

Contributors

alexlafroscia avatar deini avatar micahscopes avatar renovate-bot avatar renovate[bot] avatar treshugart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

deini micahscopes

generator-skatejs's Issues

Add generator for additional demo pages

  • Move the existing demo page into this new generator
  • Allow generating additional demo pages through the generator
    • Should be able to specify which bundles are available on the page
      • Can we read this data automatically from webpack output files?

Storybook HMR not triggering refresh correctly

Just generated a component but when I make a change in my component the Storybook doesn't reload.
screen shot 2017-07-27 at 4 43 35 pm

Looks like its getting the change but I don't see it reflected unless I refresh.

Am I missing something?

Improve workflow of creating initial project

  • Allow the default app name to be provided as an argument
  • Attempt to merge with an existing package.json file if one exists
    • If it does exist, try to use the project name in this file as the initial component name
  • Generate a default description using the initial component name that the user provides
  • Automatically add basic esdoc configuration, if the default isn't enough (check)
  • Add ESLint configuration

Generated karma config does not work.

Missing lots of plugins.

Here's mine after fixing it:

/* eslint-env node */

'use strict';

const webpackConfig = require('./webpack/test.js');

const testFiles = 'test/**/*-test.js';
const entryPoint = 'src/index.js';

require('karma-mocha');
require('karma-webpack');
require('karma-chrome-launcher');

module.exports = function(config) {
  config.set({
    plugins: [
      require('karma-mocha'),
      require('karma-webpack'),
      require('karma-chrome-launcher')
    ],
    frameworks: [ 'mocha' ],

    browsers: [
      'Chrome'
    ],

    files: [
      {
        pattern: entryPoint,
        watched: true
      },
      {
        pattern: testFiles,
        watched: true
      }
    ],

    preprocessors: {
      [entryPoint]: [ 'webpack' ],
      [testFiles]: [ 'webpack' ]
    },

    webpack: webpackConfig,

    webpackMiddleware: {
      stats: 'errors-only'
    }
  });
};

Generated package.json missing dev dependencies

The generated package.json doesn't include any of the dev dependencies.

Here's what I had to add to my project:

  "devDependencies": {
    "@storybook/addon-actions": "^3.3.3",
    "@storybook/addon-links": "^3.3.3",
    "@storybook/react": "^3.3.3",
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.6.1",
    "babili-webpack-plugin": "^0.1.2",
    "bore": "^2.0.1",
    "chai": "^4.1.2",
    "find-root": "^1.1.0",
    "karma": "^2.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-mocha": "^1.3.0",
    "karma-webpack": "^2.0.9",
    "mocha": "^4.1.0",
    "node-sass": "^4.7.2",
    "path-is-inside": "^1.0.2",
    "raw-loader": "^0.5.1",
    "react": "^16.2.0",
    "sass-loader": "^6.0.6",
    "storybook": "^1.0.0",
    "webpack": "^3.10.0",
    "webpack-merge": "^4.1.1"
  }

Provide list of bundles when generating a demo page

Right now, the generator assumes that you have a single bundle when generating a demo page, and just links to that one. However, it should be possible to actually use Webpack to detect all of the bundles, and provide an interface by which multiple bundles can be selected to link to.

  • Continues to link based on the component name for the index page (we don't have a Webpack config that can be read from at the time of creation)
  • On subsequent generations, use webpack to generate a JSON file that can be read from to provide a multi-select of bundles to include

Create generator for translation files

  • Generate the translation helper with the first translation locale
    • Ensure that we don't accidentally create it twice
  • Allow generating additional translations
    • Automatically import the new translation files
    • Automatically create the merging of multiple locales (?)

Doesn't work out of the box?

Generated new project and after running yarn storybook on http://localhost:6006/ i get:
exports is not defined ReferenceError: exports is not defined at Object.defineProperty.value (http://localhost:6006/static/preview.bundle.js:56010:23) at __webpack_require__ (http://localhost:6006/static/preview.bundle.js:679:30) at fn (http://localhost:6006/static/preview.bundle.js:89:20) at Object.<anonymous> (http://localhost:6006/static/preview.bundle.js:55453:18) at Object.defineProperty.value (http://localhost:6006/static/preview.bundle.js:55470:30) at __webpack_require__ (http://localhost:6006/static/preview.bundle.js:679:30) at fn (http://localhost:6006/static/preview.bundle.js:89:20) at webpackContext (http://localhost:6006/static/preview.bundle.js:55423:9) at http://localhost:6006/static/preview.bundle.js:44243:12 at Array.forEach (<anonymous>)

that is without touching anything.

Generated code broken?

I'm currently evaluating several frameworks to create a styleguide using web components. Skate.js looks very nice. However, when trying to setup a project with the yeoman generator, I encountered several problems.

I created an empty directory, cd'ed in and ran yo skatejs. This step went fine (though I wonder why do you need my email address and why do you ask what to call me).

Without changing anything in the generated files, I ran yarn storybook. The server started, however in the browser I see a big red error message exports is not defined followed by a stacktrace. I have no idea what the problem is. A broken webpack configuration maybe?

I then tried something else. I ran yarn test, but that failed as well

ERROR in ./test/components/my-button-test.js
Module parse failed: Unexpected token (6:17)

The given line and column seem to imply that JSX is unsupported. But shouldn't the generator generate working code and tooling?

source doesn't exists : app/templates/.gitignore

events.js:160
      throw er; // Unhandled 'error' event
      ^
AssertionError: Trying to copy from a source that does not exist: /home/toilal/.config/yarn/global/node_modules/generator-skatejs/generators/app/templates/.gitignore
    at EditionInterface.exports.copy (/home/toilal/.config/yarn/global/node_modules/mem-fs-editor/lib/actions/copy.js:47:3)
    at _moveToProject (/home/toilal/.config/yarn/global/node_modules/generator-skatejs/generators/app/index.js:116:13)
    at writing (/home/toilal/.config/yarn/global/node_modules/generator-skatejs/generators/app/index.js:93:10)
    at Object.<anonymous> (/home/toilal/.config/yarn/global/node_modules/yeoman-generator/lib/index.js:417:23)
    at /home/toilal/.config/yarn/global/node_modules/yeoman-generator/node_modules/run-async/index.js:25:25
    at /home/toilal/.config/yarn/global/node_modules/yeoman-generator/node_modules/run-async/index.js:24:19
    at /home/toilal/.config/yarn/global/node_modules/yeoman-generator/lib/index.js:418:9
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)

Still a packaging problem on 0.3.0

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module '../../lib/classify'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/toilal/.config/yarn/global/node_modules/generator-skatejs/generators/component/index.js:5:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

It works if i install the generator using the github URL instead of the package name

Support TypeScript

  • Prompt user to see if they want TS support
    • Support TS flag as an argument as well
  • Automatically install additional required TS development dependencies
  • Generate TS files for app files
    • index.js
    • Style utility
  • Generate TS files for additional components without asking again for the user's preference

Useful links

Provide option to merge translations

In order to keep translations small, I've been providing only differences from English in my translation files, and then having all locales fall back to the en-US translation file if nothing else can be found.

It would be cool to allow this to be generated automatically through a config option, like:

yo skatejs:translation fr-CA --fallback fr-FR,en-US

or something similar, to do the following in the Translation helper automatically

import enUS from 'whereever';
import frFR from 'whereever';
import frCA from 'whereever';

const translationMap = new Map();
...
translationMap.set('fr-CA', merge(enUS, frFR, frCA));

where merge is like Object.assign except that it supports deep merging of keys with an object for a value. My personal implementation uses deepmerge, which might be an appropriate initial approach.

  • Provide fallback option that allows a locale to fall back to other arbitrary locales
    • Fail if a fallback locale does not exist
  • Automatically install deepmerge and set up the merge function the first time only
  • When the fallback option is provided, generate the map's value by merging locales instead of simply using the imported file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.