1.3.2 • Published 3 years ago

some-dev-chain v1.3.2

Weekly downloads
1
License
ISC
Repository
-
Last release
3 years ago

Some dev chain

Flexible handling and parsing of project sources

Install

$ npm i --save-dev some-dev-chain

CLI

Help
$ node_modules/.bin/dev-chain --help
Serve (servering handling from config)
$ node_modules/.bin/dev-chain serve :path-to-config

Documentation

Configure tasks

Todo...

Parser tools
NameDescriptionConfiguration
SassSass parserglobalVars ::string[] - Insert global variables into root of main sass module
paths ::string[] - Custom paths for import modules inside sass
BabelParsing to ES5-
MinifyMinify js (ES5) or css-
BrowserifyBuilder of js modulesglobalVars ::string[] - Insert global variables into root of main js module
paths ::string[] - Custom paths for require modules inside js
LivereloadLivereload triggertype ::string - Use "reload" value for reload page
type ::string - Use "change" value for insert changes
Read/write files tools
NameDescriptionConfiguration
getFilesGet files for inserting into chainREQUIRED path ::string - Path as minmatch
ignoreByFilename ::RegExp - Use for ignoring files by name of file
globOptions ::object - Glob params. See https://www.npmjs.com/package/glob
getWatchedFilesGet changed file from watcher-
writeFilesGet changed file from watcherpath ::string - Write file with absolute path. Use for single file
dir ::string - Change dir path of files
afterDir ::string - Add path after files dir paths. Relative paths like "../../" is supported
fileName ::string - Change name of files
prefix ::string - Insert prefix after name of file into files
ext ::string - Change ext of files
Inner tools
NameDescriptionConfiguration
TODO--

Run as service

Todo...

Examples

Configuration example
const Path = require('path');
const staticServiceDir = '../static';

module.exports = {
	'js-page': {
		description: 'Parse js places in views/pages/**/*.js',
		watch: {minmatch: 'src/views/pages/**/*.js', ignoreByFilename: /^\_/},
		chain: [
			{name: 'getWatchedFile'},
			{name: 'browserify'},
			{
				name: 'setVariable',
				alias: '$moduleName',
				value: ({inputFilePaths}) => `${_parseModuleName(inputFilePaths[0])}.${Path.parse(inputFilePaths[0]).name}.js`
			},
			{name: 'writeFiles', path: `${staticServiceDir}/scripts/($moduleName)`},
			{name: 'livereload', type: 'reload'}
		]
	},
	'pack-scripts': {
		description: 'Parse result of all js modules with babel',
		runFromCli: true,
		chain: [
			{name: 'getFiles', path: ['src/views/pages/**/*.js', 'src/views/js-modules/*.js'], ignoreByFilename: /^\_/},
			{name: 'babel'},
			{name: 'browserify', globalVars: {}},
			{name: 'minify'},
			{
				name: 'middleware', 
				handler: ({files}) => {
					files.forEach(file => {
						const {dir, name, full} = file.pathSegments;

						if (dir.indexOf('views/js-modules') > -1) return file.setName(`_module.${name}`);

						const moduleName = _parseModuleName(full);
						return file.setName(`${moduleName}.${name}`);
					});
				}
			},
			{name: 'writeFiles', dir: `${staticServiceDir}/scripts`},
			{name: 'livereload', type: 'reload'}
		]
	},

	'scss-module': {
		description: 'Parse scss modules places in views/scss-modules/*.scss',
		watch: {minmatch: 'src/views/scss-modules/*.scss', ignoreByFilename: /^\_/},
		chain: [
			{name: 'getWatchedFile'},
			{name: 'sass'},
			{name: 'minify'},
			{
				name: 'setVariable',
				alias: '$moduleName',
				value: ({inputFilePaths}) => `_module.${Path.parse(inputFilePaths[0]).name}`
			},
			{name: 'writeFiles', path: `${staticServiceDir}/css/($moduleName).css`, ignoreRemoveFiles: /.*/},
			{name: 'livereload', type: 'change'}
		]
	},
	'scss-page': {
		description: 'Parse scss places in views/pages/**/*.scss',
		watch: {minmatch: 'src/views/pages/**/*.scss', ignoreByFilename: /^\_/},
		chain: [
			{name: 'getWatchedFile'},
			{name: 'sass'},
			{name: 'minify'},
			{
				name: 'setVariable',
				alias: '$moduleName',
				value: ({inputFilePaths}) => `${_parseModuleName(inputFilePaths[0])}.${Path.parse(inputFilePaths[0]).name}.css`
			},
			{name: 'writeFiles', path: `${staticServiceDir}/css/($moduleName)`, ignoreRemoveFiles: /.*/},
			{name: 'livereload', type: 'change'}
		]
	}
};


function _parseModuleName(filePath) {
	filePath = Path.normalize(filePath);

	const componentPathSegments = Path.parse(filePath);
	const pathSegments = componentPathSegments.dir.split(Path.sep);
	let result = '';

	for (const key in pathSegments) {
		const segment = pathSegments[pathSegments.length - key - 1];
		if (segment == 'views') break;

		result += `${segment}.`;
	}

	return result.replace(/\.$/, '');
}
1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago