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

add-dist-header

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-dist-header - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

36

bin/cli.js

@@ -6,17 +6,18 @@ #!/usr/bin/env node

// "scripts": {
// "validate": "add-dist-header docs/*.html flyer.html",
// "all": "add-dist-header"
// "add-headers": "add-dist-header build/*.js dist"
// },
//
// Usage from command line:
// $ npx add-dist-header docs/*.html flyer.html
// $ npx add-dist-header #validate all html files in project
// $ npx add-dist-header "build" "dist"
// $ npx add-dist-header #same as above since "build/*" "dist" are the default parameters
// $ npx add-dist-header "target/app.js" #creates "dist/app.js" prepended with a comment header
//
// Contributors to this project:
// $ cd add-dist-header
// $ node bin/cli.js spec/**/*.html
// $ node bin/cli.js "spec/fixtures/to-kebab.js" "spec/fixtures/dist" #run on sample file
// $ node bin/cli.js #update distribution files for this project
// Imports
import glob from 'glob';
import { lstatSync } from 'fs';
import { existsSync, statSync } from 'fs';
import { addDistHeader } from '../dist/add-dist-header.js';

@@ -30,12 +31,15 @@

// Prepend
console.log('add-dist-header');
if (flags.length)
console.log('Flags not supported:', flags.join(' '));
const keep = (filename) => !filename.includes('node_modules/');
const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
const expandFolder = (file) => lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
const filenames = files.length ? getFilenames() : readFolder('');
console.log('files:', filenames.length);
const param = {
filename: files[0] ?? 'build/*',
dist: files[1] ?? 'dist',
};
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^[-]*/, '').split('=')));
const setVersion = flagMap.version !== 'false';
const isFolder = existsSync(param.filename) && statSync(param.filename).isDirectory();
const pattern = isFolder ? param.filename + '/*' : param.filename;
const filenames = glob.sync(pattern, { nodir: true }).sort();
const log = (result) => console.log('[add-dist-header]', result.file, '~ length:', result.length);
if (!filenames.length)
console.error('[add-dist-header] File not found:', param.filename);
filenames.forEach(file =>
addDistHeader.prepend({ filename: file }).then(console.log));
log(addDistHeader.prepend({ filename: file, dist: param.dist, setVersion: setVersion })));

@@ -0,1 +1,3 @@

//! add-dist-header v0.0.2 ~ github:center-key/add-dist-header ~ MIT License
export declare type Options = {

@@ -2,0 +4,0 @@ filename: string;

@@ -0,1 +1,3 @@

//! add-dist-header v0.0.2 ~ github:center-key/add-dist-header ~ MIT License
import { format, parse } from 'path';

@@ -2,0 +4,0 @@ import { readFileSync, writeFileSync } from 'fs';

{
"name": "add-dist-header",
"version": "0.0.1",
"version": "0.0.2",
"description": "Adds a header comment to a file and saves it to your distribution folder (written in TypeScript)",

@@ -32,2 +32,3 @@ "license": "MIT",

"dist",
"distribution",
"file",

@@ -39,3 +40,3 @@ "folder",

"jshintConfig": {
"esversion": 9,
"esversion": 11,
"strict": "implied",

@@ -76,2 +77,3 @@ "eqeqeq": true,

"step:07": "cpy 'build/*' dist",
"step:08": "node bin/cli.js --version=false build dist",
"pretest": "npm-run-all step:*",

@@ -78,0 +80,0 @@ "test": "mocha spec/*.spec.js"

@@ -11,2 +11,10 @@ # Add Dist Header

**add-dist-header** uses the `name`, `repository`, and `license` from your
project's **package.json** file to create a header comment.
Example header comment:
```javascript
//! my-app v0.3.7 ~ github:my-organization/my-app ~ MIT License
```
## 1) Setup

@@ -20,6 +28,28 @@

### Import
Import into your application:
```javascript
import { addDistHeader } from 'add-dist-header';
## 2) Usage
Call `add-dist-header` from the `"scripts"` section of your **package.json** file.
For example:
```json
"scripts": {
"add-headers": "add-dist-header build dist"
},
```
Or, run from the terminal in your project home folder, such as:
```shell
$ ls package.json
package.json
$ npx add-dist-header "build" "dist"
[add-dist-header] dist/my-app.d.ts ~ length: 413
[add-dist-header] dist/my-app.js ~ length: 1569
```
The parameters are optional:
```shell
$ npx add-dist-header #same as above since "build/*" "dist" are the default parameters
[add-dist-header] dist/my-app.d.ts ~ length: 413
[add-dist-header] dist/my-app.js ~ length: 1569
$ npx add-dist-header "target/my-app-cli.js" #creates "dist/my-app.js" prepended with a comment header
[add-dist-header] dist/my-app-cli.js ~ length: 413
```

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