Skip to content

Commit

Permalink
- make publish keep files in files but still dup dist files in
Browse files Browse the repository at this point in the history
   root
 - bump version
  • Loading branch information
zbryikt committed Jan 21, 2022
1 parent ade4495 commit 802b110
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Logs

## v1.1.1

- make `publish` keep files in `files` but still dup `dist` files in root


## v1.1.0

- add `publish` command, which publish `dist` folder as root along with core files such as `package.json`, etc
Expand Down
18 changes: 16 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
var colors, fs, path, os, fsExtra, browserify, yargs, child_process, argv, ret, localModules, cmd, json, k, srcFolder, workFolder, packageJson, exec, useSymlink, fed, slice$ = [].slice;
var colors, fs, path, os, fsExtra, browserify, yargs, child_process, glob, argv, ret, localModules, cmd, json, k, srcFolder, workFolder, packageJson, files, exec, useSymlink, fed, slice$ = [].slice;
colors = require('@plotdb/colors');
fs = require('fs');
path = require('path');
Expand All @@ -8,6 +8,7 @@ fsExtra = require('fs-extra');
browserify = require('browserify');
yargs = require('yargs');
child_process = require('child_process');
glob = require('glob');
argv = yargs.option('symlink', {
alias: 's',
description: "use symlink instead of hard copy to make main folder. default true",
Expand Down Expand Up @@ -80,13 +81,26 @@ if (cmd === 'init') {
});
packageJson = path.join(workFolder, "package.json");
json = JSON.parse(fs.readFileSync(packageJson).toString());
delete json.files;
files = (json.files || []).map(function(item){
var ret;
return ret = glob.sync(item);
}).reduce(function(a, b){
return a.concat(b);
}, []);
files.map(function(f){
var des;
des = path.join(workFolder, f);
fsExtra.ensureDirSync(path.dirname(des));
console.log(f + " -> " + des);
return fsExtra.copySync(f, des);
});
['style', 'module', 'main', 'browser', 'unpkg'].map(function(field){
if (!json[field]) {
return;
}
return json[field] = path.relative(srcFolder, json[field]);
});
delete json.files;
fs.writeFileSync(packageJson, JSON.stringify(json));
exec = function(cmd){
return new Promise(function(res, rej){
Expand Down
21 changes: 17 additions & 4 deletions lib/main.ls
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
require! <[@plotdb/colors fs path os fs-extra browserify yargs child_process]>
require! <[@plotdb/colors fs path os fs-extra browserify yargs child_process glob]>

argv = yargs
.option \symlink, do
Expand Down Expand Up @@ -47,25 +47,38 @@ else if cmd == \publish =>

fs-extra.ensure-dir-sync work-folder
fs-extra.copy-sync src-folder, work-folder

<[README README.md package.json LICENSE CHANGELOG.md]>.map ->
if !fs.exists-sync(it) => return
fs-extra.copy-sync it, path.join(work-folder, it)

package-json = path.join(work-folder, "package.json")
json = JSON.parse(fs.read-file-sync package-json .toString!)
delete json.files

files = (json.files or [])
.map (item) -> ret = glob.sync item
.reduce(((a,b) -> a ++ b),[])

files.map (f) ->
des = path.join(work-folder, f)
fs-extra.ensure-dir-sync path.dirname(des)
console.log "#f -> #des"
fs-extra.copy-sync(f, des)

<[style module main browser unpkg]>.map (field) ->
if !json[field] => return
json[field] = path.relative(src-folder, json[field])

# we still have to delete `files` so npm publish all files in worker-folder
delete json.files
fs.write-file-sync package-json, JSON.stringify(json)

exec = (cmd) -> new Promise (res, rej) ->
proc = child_process.spawn cmd.0, cmd.slice(1), {stdio: 'inherit'}
proc.on \exit, -> if (it > 0) => rej new Error! else res!

exec(<[npm publish]> ++ [work-folder] ++ <[--access public]>)
.then ->
fs.rm-sync work-folder, {recursive: true, force: true}
.then -> fs.rm-sync work-folder, {recursive: true, force: true}

else

Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cli.js"
],
"description": "Frontend dependency installer",
"version": "1.1.0",
"version": "1.1.1",
"homepage": "https://github.com/plotdb/fedep",
"repository": {
"type": "git",
Expand All @@ -20,6 +20,7 @@
"@plotdb/colors": "^0.0.1",
"browserify": "^17.0.0",
"fs-extra": "^9.0.1",
"glob": "^7.2.0",
"yargs": "^16.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit 802b110

Please sign in to comment.