Giter Club home page Giter Club logo

pancake's Introduction

The Australian Government Design System has been decommissioned Visit our community page for more information

Pancake

Pancake is a tool to make working with npm on the front end easy and sweet.

The Pancake tool

Npm wrote about the challenges frontend developers face when trying to use npm. Pancake is addressing those by embracing the idea of small individually versioned independent modules. Interdependencies is what npm does really well and Pancake will help you keep them flat and error out on conflicts. Read more about our solution

Pancake will check your "peerDependencies" for conflicts and comes with plugins to compile the contents of your modules for you and lists all available modules for you to select and install.

Contents


Getting started

If you are creating a new project using Pancake you will want to look into creating your own Pancake modules.

Pancake comes installed with Australian Government Design System components. To know if you have pancake installed, check your package.json file for a "pancake": { ... } object. If you have this and you want to change the output look at the Pancake settings section.

If you have issues with using SASS globals in a ReactJS project, please check out the Design System React starter repo for an example.

⬆ back to top


Requirements

  • npm version >= ~3.0.0
  • A package.json file in your root (run npm init --yes)

Pancake alone does not come with any dependencies while all plugins have fixed dependencies to specific versions to keep the security impact as low as possible. We also ship a package-lock.json file.

⬆ back to top


Settings

Pancake comes with two different level of settings. Global settings can persist across projects and local settings that are project specific.

Global settings

To change global settings run Pancake with the --set flag.

npx pancake --set [settingName] [value]
setting value default
npmOrg This is the npm org scope @gov.au
plugins A switch to disable or enable plugins true
ignorePlugins An array of plugins to be ignored []

Example:

npx pancake --set npmOrg yourOrg

Local settings

To change local settings all you have to do is include a pancake object into your package.json file. All possible settings are stated below:

{
  "name": "your-name",
  "version": "0.1.0",
  "pancake": {                       //the pancake config object
    "auto-save": true,               //enable/disable auto saving the settings into your package.json after each run
    "plugins": true,                 //enable/disable plugins
    "ignore": [],                    //ignore specific plugins
    "css": {                         //settings for the @gov.au/pancake-sass plugin
      "minified": true,              //minify the css?
      "modules": false,              //save one css file per module?
      "browsers": [                  //autoprefixer browser matrix
        "last 2 versions",
        "ie 8",
        "ie 9",
        "ie 10"
      ],
      "location": "pancake/css/",    //the location to save the css files to
      "name": "pancake.min.css"      //the name of the css file that includes all modules; set this to false to disable it
    },
    "sass": {                        //settings for the @gov.au/pancake-sass plugin
      "modules": false,              //save one Sass file per module?
      "location": "pancake/sass/",   //the location to save the Sass files to
      "name": "pancake.scss"         //the name of the Sass file that includes all modules; set this to false to disable it
    },
    "js": {                          //settings for the @gov.au/pancake-js plugin
      "minified": true,              //minify the js?
      "modules": false,              //save one js file per module?
      "location": "pancake/js/",     //the location to save the js files to
      "name": "pancake.min.js"       //the name of the js file that includes all modules; set this to false to disable it
    },
    "react": {                       //settings for the @gov.au/pancake-react plugin
      "location": "pancake/react/",  //the location to save the react files to; set this to false to disable it
    },
    "json": {                        //settings for the @gov.au/pancake-json plugin
      "enable": false,               //the pancake-json plugin is off by default
      "location": "pancake/js/",     //the location to save the json files to
      "name": "pancake",             //the name of the json file
      "content": {                   //you can curate what the json file will contain
        "name": true,                //include the name key
        "version": true,             //include the version key
        "dependencies": true,        //include the dependencies key
        "path": true,                //include the path key
        "settings": true             //include the settings key
      }
    }
  }
}

To remove js you can set the value of "name": false and remove the values minified, modules and location.

⬆ back to top


CLI

You can display the help with pancake --help.

Don’t save to package.json

-n, --nosave
Type: <flag>

The command will stop Pancake from merging your local settings, complete them with the defaults and save them into your package.json. This will sort-of shrink-wrap all settings in so you are completely reproducible. You can also opt-out of this behavior by adding "auds": { "auto-save": false } into your package.json.

npx pancake --nosave

Overwrite npm org name

-o, --org
Type: <flag> [value]

You can temporarily overwrite the npm org scope by suppling this flag. This can be useful for testing. Do make sure to use the settings for a permanent change.

npx pancake --org @otherOrg

Overwrite the plugin toggle

-p, --noplugins
Type: <flag>

You can temporarily disable all plugins. This is great for ci integration.

npx pancake --noplugins

Overwrite the plugin ignore list

-i, --ignore
Type: <flag> [comma separated list]

You can temporarily overwrite the list of plugins to be disabled.

npx pancake --ignore @gov.au/pancake-svg,@gov.au/pancake-js

Verbose output

-v, --verbose
Type: <flag>

Run Pancake in verbose silly mode.

npx pancake --verbose

⬆ back to top


Creating your own Pancake modules

💡 You can use Pancake with your own modules. All you have to do in your modules is:

  1. Install Pancake
  2. Add the Pancake module object to your package.json file
  3. Add the Pancake postinstall script and dependency to your package.json file
  4. Add your peer dependencies

1. Install Pancake

To install pancake use node package manager.

npm i @gov.au/pancake

2. Pancake module object

To make sure Pancake can detect your module amongst the other hundred npm packages you have to add the pancake-module object into your pancake object.

{
  "name": "your-module-name",
  "version": "1.0.0",
  "description": "Your description",
+  "pancake": {
+    "pancake-module": {                   //pancake is looking for this object to id your module as a pancake module
+      "version": "1.0.0",                 //the major version of pancake
+      "plugins": [                        //only state the plugins you need here
+        "@gov.au/pancake-sass"
+      ],
+      "org": "@gov.au @nsw.gov.au",       //the npm organisations that will be searched for pancake modules
+      "sass": {                           //sass plugin specific settings
+        "path": "lib/sass/_module.scss",  //where is your sass
+        "sass-versioning": true           //enable sass-versioning. Read more here: https://github.com/dominikwilkowski/sass-versioning
+      },
+      "js": {                             //js plugin specific settings
+        "path": "lib/js/module.js"        //where is your js
+      },
+      "react": {
+        "location": "lib/js/react.js"     //the location to move the react files to
+      }
+    }
+  },
  "dependencies": {},
  "peerDependencies": {},
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

3. The script

The magic of Pancake lies within the postinstall script. To enable Pancake add it as a dependency and add the script:

{
  "name": "your-module-name",
  "version": "1.0.0",
  "description": "Your description",
  "pancake": {
    "pancake-module": {
      "version": "1.0.0",
      "plugins": [
        "@gov.au/pancake-sass"
      ],
      "sass": {
        "path": "lib/sass/_module.scss",
        "sass-versioning": true
      },
      "js": {
        "path": "lib/js/module.js"
      },
      "react": {
        "location": "lib/js/react.js"
      }
    }
  },
  "dependencies": {
+    "@gov.au/pancake": "~1"
  },
  "peerDependencies": {},
  "devDependencies": {},
  "scripts": {
+    "postinstall": "pancake"
  },
  "author": "",
  "license": "ISC"
}

This will run Pancake right after install and make sure you always get the latest version of the release 1.0.0. If you have to change settings (very likely) you don’t actually have to fork this project. You can set those settings globally before running it with your postinstall script.

"postinstall": "pancake --set npmOrg yourOrg && pancake"

4. Peer dependencies

Adding peer dependencies is simple as long as you remember to add it to the dependencies and peerDependencies the same time. That way npm will install the peer dependency and pancake can check if you have conflicts.

{
  "name": "your-module-name",
  "version": "1.0.0",
  "description": "Your description",
  "pancake": {
    "pancake-module": {
      "version": "1.0.0",
      "plugins": [
        "@gov.au/pancake-sass"
      ],
      "sass": {
        "path": "lib/sass/_module.scss",
        "sass-versioning": true
      },
      "js": {
        "path": "lib/js/module.js"
      },
      "react": {
        "location": "lib/js/react.js"
      }
    }
  },
  "dependencies": {
    "@gov.au/pancake": "~1",

+    "@gov.au/core": "^0.1.0"
  },
  "peerDependencies": {
+    "@gov.au/core": "^0.1.0"
  },
  "devDependencies": {},
  "scripts": {
    "postinstall": "pancake"
  },
  "author": "",
  "license": "ISC"
}

Now you’re ready to publish your modules and start using Pancake.

⬆ back to top


Contributing

Hi there 👀,

❤️ We LOVE that you’re looking into this section. We welcome any feedback or pull requests and are super psyched about you putting your own time into this project. To make your contribution count, have a read through the code first and see what our thinking was. We will do the same with yours.

NOTE: If you are looking to build this project on Windows, you'll need to clone this repository with symlinks enabled using an administrator shell.

git clone -c core.symlinks=true https://github.com/govau/pancake

To run this project you'll need to have Yarn installed.

yarn install
yarn build

To develop in one of the modules run the watch inside of it:

cd packages/pancake/
yarn watch

❗️ Make sure you only edit file inside the src/ folder. Files inside the bin/ folder are overwritten by the transpiler.

Please look at the coding style and work with it, not against it. 🌴

⬆ back to top


Taste / Tests

Test modules

We have published four test modules in our scoped npm org to test interdependencies and to debug with verbose mode switched on. Find below a list of what is inside each version:

@gov.au/testmodule1

  • Testmodule1 version

@gov.au/testmodule2

  • Testmodule2 version
    • └── @gov.au/testmodule1: ^15.0.0

@gov.au/testmodule3

  • Testmodule3 version
    • ├── @gov.au/testmodule1: ^15.0.0
    • └── @gov.au/testmodule2: ^19.0.0

@gov.au/testmodule4

  • Testmodule4 version
    • └── @gov.au/testmodule1: ^15.0.0

Software tests

We have an end-to-end test script that will take a number of scenarios and compare the output of pancake against fixtures.

We also use unit tests with jest.

To run all tests use the below command:

npm test

Node support

Pancake has been tested with Ubuntu 16.04, Mac OS 10.11, 10.12 and Windows 10 all node version coming with npm 3 and higher:

  • node v5.0.0
  • node v5.12.0
  • node v6.9.5
  • node v7.0.0
  • node v7.4.0
  • node v7.5.0
  • node v7.6.0
  • node v10.0.0

⬆ back to top


License

Copyright (c) Commonwealth of Australia. Licensed under MIT.

⬆ back to top

};

pancake's People

Contributors

danielbaker avatar dominikwilkowski avatar maxious avatar mrrossmullen avatar pattyde avatar simonschwartz avatar sukhrajghuman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pancake's Issues

Create tests

Write tests for each section:

batter

  • with conflicts
  • without conflicts
  • no modules
  • no node_modules

syrup

  • sass only
  • sass and js
  • no assets at all
  • no folder
  • not writable folder
  • all settings individually

cream

  • mock uikit.json
  • on empty folder
  • on patch changes
  • on minor changes
  • on major changes
  • on modules that don't exist anymore

Make required a setting inside the package.json pancake object

As a user I don't want pancake to create a certain type of file as my project doesn't use it (sass/css/react/js).

Currently users have odd ways of doing this such as setting the "name" value in package.json to false. This works ok but it's not clear to the user that setting "name" to false stops the generation of files. It also doesn't work with the react plugin as that creates unique names per component.

There should be a new value (required) in the package.json pancake object which allows users to choose which types of files they want processed.

This may lead to a further conversation about component dependencies. It would be nice to npm install @gov.au/select and be able to choose if I would like to install pancake-sass, pancake-react which would then create the files.

Give pancake a silent option

The output can be a bit annoying when pancake runs inside a container that doesn't understand ansi escape sequences.

Performance issues on Windows

I'm not sure if it is specific to my work environment but pancake takes an extremely long time to run on Windows using latest LTS of node (currently 8.11.3).

If I use node 6.14.3 it is significantly faster but still a lot slower than on a mac.

React can't be turned off without using ignore

The below pancake objects don't disable react. The second one creates a folder called false. 😭

"pancake": {
	"auto-save": false,
	"plugins": false,
	"ignore": [],
	"css": {
		"name": false
	},
	"sass": {
		"name": false
	},
	"js": {
		"name": false
	},
	"react": {
		"name": false
	},
	"json": {
		"enable": true,
		"location": "./_uikit/",
		"name": "uikit"
	}
}
"pancake": {
	"auto-save": false,
	"plugins": false,
	"ignore": [],
	"css": {
		"name": false
	},
	"sass": {
		"name": false
	},
	"js": {
		"name": false
	},
	"react": {
		"location": false
	},
	"json": {
		"enable": true,
		"location": "./_uikit/",
		"name": "uikit"
	}
}

Fix loading hangup

The loading seems to stop for the loading and start when it finishes... bad!

make sass-versioning optional

Not sure how yet. Maybe check automatically for sass-versioning inside the node_modules folder? Or add a flag to overwrite?

Performance issues with sass

It has been noted that there are obvious performance differences between sass and node-sass. According to the sass-dart repository these issues shouldn't exist however replacing sass with node-sass see's huge performance improvements.

    "build:sass": "sass pancake/sass/pancake.scss sass/style.css --style compressed",
    "build:node-sass": "node-sass pancake/sass/pancake.scss sass/style.css --style compressed",

screen shot 2018-07-05 at 1 12 38 pm

We originally moved to sass to fix corrupt dependencies. node-sass is nearly patched just waiting on node-gyp.

Add more infos to batter

Should include infos of what modules are using the conflicting module and what can be done about it.

Pancake monorepo suppport, allow users to set node_modules directory location

We're using pancake with the govau design systems modules over at https://github.com/terriajs/magda.

Magda is a lerna monorepo, with node_modules at the root and in each subdirectory.

I've been trying to switch over to using yarn instead of npm. Yarn puts most dependencies in the root node_modules directory, but our react web app lives in magda-web-client subdirectory. So when I run pancake from that directory, it says 🔔 INFO: No modules found because it can't find any modules in magda-web-client/node_modules, and doesn't know to recurse upwards.

Looking at the code, it looks like the directory where modules are found has to be process.cwd + 'node_modules' - could that be configurable, or know to keep recursing upwards adding modules until it can't find any more node_modules directories?

Add package.json setting for `auto-save`

Syrup's opt-out save functionality to will automatically save all it's setting inside the package.json. You can opt out via the command line with the --nosave flag. However since syrup runs automatically after batter we need an option to change that behaviour.
auto-save can sit next to the auto-syrup option in the package.json file.

Make pancake plugins

Pancake should only do the flat dependency check and then look into the package.json file of the module and see if there are plugins to run.

Get pancake working in Windows

Windows is the new IE for node devs.
Areas that need attention from looking at initial tests:

  • The bash script in each module won't work naturally
  • Spawning new processes don't go down as they should. Need to look at that
  • The Sass paths need to be adapted to each os
  • Get folder creating to work

Adding your own custom modules to pancake

Currently as a user I want to create a custom component in a folder and deploy it as an NPM package, following pancakes patterns. It is not related to the design system so I don't want to create a pull request and merge it back into the Uikit.

I would like to be able to add this NPM module to my pancake build, or choose the folder/folders I build my components from.

Cannot build when hoisting modules - Undefined variable: "$versioning-glob-dependencies"

It seems that pancake fails when generating pancake.min.css using sass-versioning. This occurs when a user attempts to use yarn workspaces and lerna to hoist sub-packages into a root level node_modules folder.

Config:

  • Yarn: 1.9.4
  • Node: 8.12.0
  • lerna: 3.4.0

A possible cause might be to do with this:

let sassVersioning = true; //let’s assume the pancake module was build with sass-versioning

Steps:

git clone https://github.com/govau/uikit
cd uikit

Modify the following:

# lerna.json
{
	"lerna": "3.4.0",
	"packages": [
		"packages/*"
	],
	"npmClient": "yarn",
	"useWorkspaces": true,
	"version": "independent"
}
# package.json
{
...
	"private": true,
	"workspaces": [
		"packages/*"
	],
...
}

Error:

Infinite loop with:
image

Add syrup

The app should run alone and have pancake as a dependency.
Code can be copied from older implementation

Add error handling

general

  • no node_modules folder
  • no node_modules and package.json file
  • existing node_modules but no package.json file
  • no node_modules but existing package.json file
  • node_modules locked
  • package.json locked
  • output folder for syrup locked/unwritable
  • folder exists already (called what the file name will be)

syrup

  • uglify fail
  • sass fail
  • autoprefixer fail
  • autoprefixer warnings

cream

  • can't get json file / http fail
  • can't install

Add SVG plugin

The plugin should move svgs, create PNG fallbacks and a svg sprit

Add cream

  • Needs to get all modules from repo
  • Needs to display radios
  • Needs to pick up already installed packages
  • Installs what has been selected

Resolve deep dependencies inside sass generation

When we generate Sass inside pancake-sass via GenerateSass we have to look up all dependencies per module.

E.g. it fails when we build the sass file for breadcrumbs which is dependencies are:

.
├─ core
└─ link-list
   ├─ core
   └─ body
      └─ core

Save plugins into the package.json file when enabled

Plugins are currently silently installed. That means the build is still 100% reproducible by package.json but it won't be super fast. :)
If plugins are enabled and we install them we should default to --save.

Have sass plugin use the sass path inside the modules pancake object

Currently we are hardcoding the path to the sass files. There is a path inside the pancake object that we should use here:

pancake: {
	'pancake-module': {
		"version":"1.0.0",
		"plugins": [
			"@gov.au/pancake-sass",
			"@gov.au/pancake-js"
		],
		"sass": {
+ 			"path": "lib/sass/_module.scss",
			"sass-versioning": true
		},
		"js": {
			"path": "lib/js/module.js"
		}
	}
},

This should be used in GenerateSass.

Selecting minified JS option causes bugs on ie8

What happened

When the JS is minified option is selected as true, the side-nav doesn't open or close in ie8 on smaller devices

"js": {
		"minified": true,
		"modules": false,
		"location": "docs/js/",
		"name": "script.js"
	},

What I expected to happen

I expected the side-nav to open and close when I click it

Reproducing

  • Pancake version: v1.2.3

Steps to reproduce:

  1. As an example, run uikit-starter project on ie8 and try to open/close the accordion

  2. Then try setting the minified option to false

Adding syrup

  • Needs to compile assets from installed modules
  • Needs to pick up the settings from the package.json where to save it

When `auto-save` is enabled, pancake-json will save the entire json into the `package.json`

There is some silliness going on here when when I enable auto-save and run pancake I get:

{
	"pancake": {
		"auto-save": true,
		"plugins": true,
		"ignore": [],
		"css": {
			"minified": true,
			"modules": false,
			"browsers": [
				"last 2 versions",
				"ie 8",
				"ie 9",
				"ie 10"
			],
			"location": "pancake/css/",
			"name": "pancake.min.css"
		},
		"sass": {
			"modules": false,
			"location": "pancake/sass/",
			"name": false
		},
		"js": {
			"minified": true,
			"modules": false,
			"location": "pancake/js/",
			"name": "pancake.min.js"
		},
		"json": {
			"enable": true,
			"location": "pancake/",
			"name": "pancake",
			"content": {
				"name": true,
				"version": true,
				"dependencies": true,
				"path": true,
				"settings": true
			}
		},
		"@gov.au/testmodule1": {
			"name": "@gov.au/testmodule1",
			"version": "11.0.1",
			"dependencies": {},
			"path": "/Users/dominikwilkowski/Sites/DTA/pancake/tests/test11/node_modules/@gov.au/testmodule1",
			"settings": {
				"version": "1.0.0",
				"plugins": [
					"@gov.au/pancake-sass",
					"@gov.au/pancake-js",
					"@gov.au/pancake-json"
				],
				"sass": {
					"path": "lib/sass/_module.scss",
					"sass-versioning": true
				},
				"js": {
					"path": "lib/js/module.js"
				}
			}
		},
		"@gov.au/testmodule2": {
			"name": "@gov.au/testmodule2",
			"version": "13.0.0",
			"dependencies": {
				"@gov.au/testmodule1": "^11.0.1"
			},
			"path": "/Users/dominikwilkowski/Sites/DTA/pancake/tests/test11/node_modules/@gov.au/testmodule2",
			"settings": {
				"version": "1.0.0",
				"plugins": [
					"@gov.au/pancake-sass",
					"@gov.au/pancake-js",
					"@gov.au/pancake-json"
				],
				"sass": {
					"path": "lib/sass/_module.scss",
					"sass-versioning": true
				},
				"js": {
					"path": "lib/js/module.js"
				}
			}
		}
	}
}

that's kinda fun but totally not cool!

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.