Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto add #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 87 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,114 @@
{
"name": "wml",
"version": "0.0.0",
"description": "Replaces npm link with something that actually works!",
"scripts": {
"test": ":",
"prepublish": ":",
"build": ":",
"release": "npm install wnpm-ci --no-save && wnpm-release -- --no-shrinkwrap"
"_args": [
[
{
"raw": "wml",
"scope": null,
"escapedName": "wml",
"name": "wml",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"/Volumes/Data/Sites/neighborplate/app/app"
]
],
"_from": "wml@latest",
"_id": "[email protected]",
"_inCache": true,
"_location": "/wml",
"_nodeVersion": "6.11.3",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/wml-0.0.83.tgz_1508240157199_0.2210600816179067"
},
"_npmUser": {
"name": "wix-ci",
"email": "[email protected]"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"raw": "wml",
"scope": null,
"escapedName": "wml",
"name": "wml",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_resolved": "https://registry.npmjs.org/wml/-/wml-0.0.83.tgz",
"_shasum": "dac784f24f06c5f007262908d229a4bdbd730457",
"_shrinkwrap": null,
"_spec": "wml",
"_where": "/Volumes/Data/Sites/neighborplate/app/app",
"author": {
"name": "dutzi",
"email": "[email protected]",
"url": "http://github.com/dutzi"
},
"bin": {
"wml": "./src/cli/index.js"
},
"author": "dutzi <[email protected]> (http://github.com/dutzi)",
"license": "MIT",
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git+https://github.com/wix/wml.git"
},
"bugs": {
"url": "https://github.com/wix/wml/issues"
},
"homepage": "https://github.com/wix/wml#readme",
"dependencies": {
"colors": "^1.1.2",
"extend": "^3.0.0",
"fb-watchman": "^1.9.0",
"fs-extra": "^0.30.0",
"fs-utils": "^0.7.0",
"glob": "^7.1.2",
"lodash": "^4.17.4",
"promise-sequential": "^1.1.1",
"inquirer": "^1.2.3",
"is-there": "^4.3.3",
"lodash": "^4.17.4",
"promise-sequential": "^1.1.1",
"q": "^1.4.1",
"untildify": "^3.0.2",
"uuid-js": "^0.7.5",
"yargs": "^4.7.1"
},
"description": "Replaces npm link with something that actually works!",
"devDependencies": {
"babel-eslint": "^6.0.4",
"eslint": "^2.11.1"
},
"directories": {},
"dist": {
"integrity": "sha512-t/atXKIcMLIvMIReoPGELN+JkpjF6B661dWuJjKYNydX3N7M0vUYiy8UP3oxIUyO+b0tOwuRKKW/VsPka0Hfjw==",
"shasum": "dac784f24f06c5f007262908d229a4bdbd730457",
"tarball": "https://registry.npmjs.org/wml/-/wml-0.0.83.tgz"
},
"homepage": "https://github.com/wix/wml#readme",
"license": "MIT",
"maintainers": [
{
"name": "wix-ci",
"email": "[email protected]"
}
],
"name": "wml",
"optionalDependencies": {},
"preferGlobal": true,
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/wix/wml.git"
},
"scripts": {
"build": ":",
"prepublish": ":",
"release": "npm install wnpm-ci --no-save && wnpm-release -- --no-shrinkwrap",
"test": ":"
},
"version": "0.0.83"
}
6 changes: 4 additions & 2 deletions src/cli/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ exports.handler = function (argv) {
for (i in links.data) {
if (links.data[i].src === src &&
links.data[i].dest === dest) {
console.log('Error: link already exists');
console.log(`Error: link already exists ${src} -> ${dest}`);
return;
}
}

promptForIgnoredFolders(src, [{
console.log(`Adding ${src} -> ${dest}`)

return promptForIgnoredFolders(src, [{
name: 'git',
relPath: '.git',
ignore: '.git',
Expand Down
62 changes: 62 additions & 0 deletions src/cli/autoAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';
require('colors');
const fs = require('fs-utils')
const glob = require('glob')
const _ = require('lodash')
var links = require('../links.js');
const add = require('./add.js').handler
const sequential = require('promise-sequential')

exports.command = 'autoAdd';

exports.describe = 'Auto-discovers and creates links';

exports.builder = {};

exports.handler = function () {
links.load();

var found;

console.log('Links:');

let p = new Promise((resolve, reject) => {

})
let sources = []
for (var linkId in links.data) {
var link = links.data[linkId];
var status = link.enabled ? 'enabled'.green : 'disabled'.red;
sources.push(link.src)
}
sources = _.uniqBy(sources, v => v)
let scanners = []
let mappings = {}
_.each(sources, src => {
let pkg = fs.readJSONSync(`${src}/package.json`)
let name = pkg.name
console.log(`Scanning for ${name}`);
let p = new Promise((resolve, reject) => {
let pat = `${process.cwd()}/**/node_modules/${name}`
mappings[src] = []
glob(pat, {}, function (er, files) {
_.each(files, f=>{
mappings[src].push(f)
})
resolve()
})
})
scanners.push(p)
})
Promise.all(scanners).then(()=>{
let adds = []
_.each(mappings, (dsts,src)=>{
_.each(dsts, dest=>{
adds.push(()=>add({src,dest}))
})
})
sequential(adds)
})


}
3 changes: 3 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var start = require('./start.js');
var list = require('./list.js');
var enable = require('./enable.js');
var disable = require('./disable.js');
var autoAdd = require('./autoAdd.js');

require('yargs')
.usage('$0 <cmd> [args]')
Expand All @@ -15,7 +16,9 @@ require('yargs')
.command(start)
.command(list)
.command(enable)
.command(autoAdd)
.command(disable)
.command('aa', false, autoAdd)
.command('a', false, add)
.command('s', false, start)
.command('ls', false, list)
Expand Down
23 changes: 23 additions & 0 deletions src/cli/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ var path = require('path');

var capabilityCheck = require('../capabilityCheck.js');
var watchProject = require('../watchProject.js');
var watchDel = require('../watchDel.js')
var getConfig = require('../getConfig.js');
var subscribe = require('../subscribe.js');
var watchman = require('fb-watchman');
var links = require('../links.js');
var copyHandler = require('../handlers/copy.js');
var fs = require('fs-extra')

exports.command = 'start';

Expand Down Expand Up @@ -51,8 +53,29 @@ function startWatcher(link, linkId) {

watchers[linkId] = client;


capabilityCheck({
client: client
}).then(() => {

console.log('Clean target'.green, link.dest)

return new Promise((resolve,reject)=>{
fs.emptyDir(link.dest);
setTimeout(()=>resolve(), 500)
})

}).then(() => {

console.log('Deleting old watch'.green, link.src)

return watchDel({
client: client,
src: link.src
}).catch((err)=>{
console.log("...already deleted")
});

}).then(() => {

return watchProject({
Expand Down
18 changes: 18 additions & 0 deletions src/watchDel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var Q = require('q');

module.exports = function (params) {
var deferred = Q.defer();

params.client.command(['watch-del', params.src], (error, resp) => {
if (error) {
deferred.reject(error);
} else {
deferred.resolve(resp);
}

});

return deferred.promise;
}
Loading