From 7c348e5b4a36970341370574c2c9a6b3dc1e34eb Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Fri, 19 Aug 2016 21:17:39 -0700 Subject: [PATCH 01/17] update the the latest esdocs to fix tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c59ff68..2576f99 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "devDependencies": { "babel": "^5.8.20", "coveralls": "~2.11.2", - "esdoc": "^0.2.0", + "esdoc": "^0.4.8", "espower-babel": "^3.2.0", "fs-extra": "^0.22.1", "istanbul": "~0.3.16", From 4da82836036dd84a1a2ea8d293c9b0c7cf511ebc Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Fri, 19 Aug 2016 21:18:14 -0700 Subject: [PATCH 02/17] allow package name only if importPath does not exist --- src/Plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.js b/src/Plugin.js index 64852d5..7c16957 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -52,7 +52,7 @@ export function onHandleTag(ev) { if (importPath === mainPath) { tag.importPath = packageName; } else if (packageName) { - tag.importPath = `${packageName}/${importPath}`; + tag.importPath = importPath ? `${packageName}/${importPath}` : packageName; } else { tag.importPath = importPath; } From 2b44669b2290434be7644cb212c6119c7c87bcb0 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Mon, 22 Aug 2016 23:55:01 -0700 Subject: [PATCH 03/17] clarify the esdoc import path logic --- src/Plugin.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Plugin.js b/src/Plugin.js index 7c16957..3ab2314 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -40,21 +40,33 @@ export function onHandleTag(ev) { } for (let tag of ev.data.tag) { - if (!tag.importPath) continue; + if (tag.importPath) { + tag.importPath = getImportPath(tag.importPath, packageName, mainPath); + } + } +} - let importPath = tag.importPath; - if (packageName) importPath = importPath.replace(new RegExp(`^${packageName}/`), ''); +function getImportPath(tagImportPath, packageName, mainPath) { + if (mainPath) { + // defines the import name defined by "main" + // https://docs.npmjs.com/files/package.json#main + return mainPath; + } - for (let item of option.replaces) { - importPath = importPath.replace(item.from, item.to); - } + let importPath = tagImportPath; + if (packageName) { + importPath = importPath.replace(new RegExp(`^${packageName}/`), ''); + } - if (importPath === mainPath) { - tag.importPath = packageName; - } else if (packageName) { - tag.importPath = importPath ? `${packageName}/${importPath}` : packageName; - } else { - tag.importPath = importPath; - } + // process the user's replace config. + for (let item of option.replaces) { + importPath = importPath.replace(item.from, item.to); } + + // add the package name to the beginning of the import path + if (packageName) { + return `${packageName}/${importPath}`; + } + + return importPath; } From 3b4d10f4657222d0b5c2f306f21447396cf79f6a Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 02:34:01 -0700 Subject: [PATCH 04/17] ignore esdoc* --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eda638e..28c2c2e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules out npm-debug.log /coverage -/test/fixture/esdoc +/test/fixture/esdoc* From 99579e202d7710431ea7a3ba9fa47976dbf8fb23 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 02:35:06 -0700 Subject: [PATCH 05/17] allow packageObj to defined as an object --- src/Plugin.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Plugin.js b/src/Plugin.js index 3ab2314..2b2140f 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -1,7 +1,7 @@ import fs from 'fs'; let option; -let packagePath = './package.json'; +let packageObj; /** * take option @@ -19,7 +19,15 @@ export function onStart(ev) { * @param {Object} ev - handle event. */ export function onHandleConfig(ev) { - if (ev.data.config.package) packagePath = ev.data.config.package; + packageObj = ev.data.config.package; + if (typeof ev.data.config.package === 'string') { + try { + const packageJSON = fs.readFileSync(packageObj).toString(); + packageObj = JSON.parse(packageJSON); + } catch (e) { + // ignore + } + } } /** @@ -28,20 +36,12 @@ export function onHandleConfig(ev) { */ export function onHandleTag(ev) { // get package.json - let packageName = ''; - let mainPath = ''; - try { - const packageJSON = fs.readFileSync(packagePath).toString(); - const packageObj = JSON.parse(packageJSON); - packageName = packageObj.name; - if(packageObj.main) mainPath = packageObj.main; - } catch (e) { - // ignore - } + let packageName = packageObj.name; + let mainPath = packageObj.main; for (let tag of ev.data.tag) { if (tag.importPath) { - tag.importPath = getImportPath(tag.importPath, packageName, mainPath); + tag.importPath = getImportPath(tag.importPath, packageName, mainPath || option.main); } } } From 5161502f743133dc2dd7f9cf7cd90e1a1852248c Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 02:35:35 -0700 Subject: [PATCH 06/17] update the esdocs tests to generate docs on the fly --- esdoc.json | 18 -------- package.json | 2 +- test/fixture/esdoc.json | 16 ------- test/fixture/package.json | 4 -- test/fixture/src/MyClass.js | 2 - test/src/000init.js | 14 ------ test/src/ImportPathTest.js | 87 +++++++++++++++++++++++++++++++++---- 7 files changed, 79 insertions(+), 64 deletions(-) delete mode 100644 esdoc.json delete mode 100644 test/fixture/esdoc.json delete mode 100644 test/fixture/package.json delete mode 100644 test/fixture/src/MyClass.js delete mode 100644 test/src/000init.js diff --git a/esdoc.json b/esdoc.json deleted file mode 100644 index 837d4fc..0000000 --- a/esdoc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "source": "./src", - "destination": "./out/esdoc", - "test": { - "type": "mocha", - "source": "./test/src" - }, - "plugins": [ - { - "name": "./out/src/Plugin.js", - "option": { - "replaces": [ - {"from": "^src/", "to": "out/src/"} - ] - } - } - ] -} diff --git a/package.json b/package.json index 2576f99..98feb17 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "scripts": { "build": "node ./script/build.js", - "test": "node ./script/test.js", + "test": "rm -rf ./test/fixture/esdoc* && node ./script/test.js", "test-es5": "node ./script/test-es5.js", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, diff --git a/test/fixture/esdoc.json b/test/fixture/esdoc.json deleted file mode 100644 index c03a7c8..0000000 --- a/test/fixture/esdoc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "source": "./test/fixture/src", - "destination": "./test/fixture/esdoc", - "package": "./test/fixture/package.json", - "plugins": [ - { - "name": "./src/Plugin.js", - "option": { - "replaces": [ - {"from": "^src/", "to": "lib/"}, - {"from": "^lib/FooClass.js", "to": "lib/foo"} - ] - } - } - ] -} diff --git a/test/fixture/package.json b/test/fixture/package.json deleted file mode 100644 index 3ab9619..0000000 --- a/test/fixture/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "esdoc-importpath-plugin", - "main": "lib/Index.js" -} diff --git a/test/fixture/src/MyClass.js b/test/fixture/src/MyClass.js deleted file mode 100644 index a313b29..0000000 --- a/test/fixture/src/MyClass.js +++ /dev/null @@ -1,2 +0,0 @@ -export default class MyClass { -} diff --git a/test/src/000init.js b/test/src/000init.js deleted file mode 100644 index 6d8f2b0..0000000 --- a/test/src/000init.js +++ /dev/null @@ -1,14 +0,0 @@ -import fs from 'fs-extra'; -import path from 'path'; -import ESDoc from 'esdoc/out/src/ESDoc.js'; -import publisher from 'esdoc/out/src/Publisher/publish.js'; - -const configFilePath = './test/fixture/esdoc.json'; -const configJSON = fs.readFileSync(configFilePath, {encode: 'utf8'}); -const config = JSON.parse(configJSON); - -const selfPath = path.relative('./', __filename); -if (selfPath.indexOf('out/test/src/') === 0) config.plugins[0].name = './out/src/Plugin.js'; - -fs.removeSync(config.destination); -ESDoc.generate(config, publisher); diff --git a/test/src/ImportPathTest.js b/test/src/ImportPathTest.js index 373a21b..cc5e375 100644 --- a/test/src/ImportPathTest.js +++ b/test/src/ImportPathTest.js @@ -1,22 +1,91 @@ import fs from 'fs-extra'; import assert from 'power-assert'; +import ESDoc from 'esdoc/out/src/ESDoc.js'; +import defaultPublisher from 'esdoc/out/src/Publisher/publish.js'; + /** * @test {onHandleTag} */ describe('Import Path', ()=> { - it('simply convert', ()=> { - const html = fs.readFileSync('./test/fixture/esdoc/class/src/MyClass.js~MyClass.html').toString(); - assert(html.includes('>esdoc-importpath-plugin/lib/MyClass.js<')); + function assertPath(config, assertion) { + ESDoc.generate(config, defaultPublisher); + const html = fs.readFileSync(config.destination + '/class/src/FooClass.js~FooClass.html').toString(); + assert(html.includes(assertion)); + } + + it('should convert using package name only', ()=> { + assertPath({ + "source": "./test/fixture/src", + "destination": "./test/fixture/esdoc1", + "package": { + "name": "esdoc-importpath-plugin" + } + }, '>esdoc-importpath-plugin/src/FooClass.js<'); + }); + + it('should convert using custom replacement', ()=> { + assertPath({ + "source": "./test/fixture/src", + "destination": "./test/fixture/esdoc2", + "package": { + "name": "esdoc-importpath-plugin" + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + "replaces": [ + {"from": "^src/", "to": "lib/"}, + {"from": "^lib/FooClass.js", "to": "lib/foo"} + ] + } + } + ] + }, '>esdoc-importpath-plugin/lib/foo<'); }); - it('multiple convert', ()=>{ - const html = fs.readFileSync('./test/fixture/esdoc/class/src/FooClass.js~FooClass.html').toString(); - assert(html.includes('>esdoc-importpath-plugin/lib/foo<')); + it('should convert using custom main', ()=> { + assertPath({ + "source": "./test/fixture/src", + "destination": "./test/fixture/esdoc3", + "package": { + "name": "MyPackageName" + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + "main": "esdoc-importpath-plugin", + // ignores these replacements + "replaces": [ + {"from": "^src/", "to": "lib/"}, + ] + } + } + ] + }, '>esdoc-importpath-plugin<'); }); - it('package name convert', ()=>{ - const html = fs.readFileSync('./test/fixture/esdoc/class/src/Index.js~Index.html').toString(); - assert(html.includes('>esdoc-importpath-plugin<')); + it('should convert using package main property', ()=>{ + assertPath({ + "source": "./test/fixture/src", + "destination": "./test/fixture/esdoc4", + "package": { + "name": "MyPackageName", + "main": "esdoc-importpath-plugin" + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + // ignores these replacements + "replaces": [ + {"from": "^src/", "to": "lib/"}, + ] + } + } + ] + }, '>esdoc-importpath-plugin<'); }); }); From 58dc2afd3601b904809742743dafdbfcc69eb575 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 02:35:46 -0700 Subject: [PATCH 07/17] update the README --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b187e18..6aa6fe5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Therefore, convert the import path by using following setting. { "name": "esdoc-importpath-plugin", "option": { + // setting the main ignores the replace + "main": "my-import-override", "replaces": [ {"from": "^src/", "to": "lib/"} ] @@ -30,21 +32,23 @@ Therefore, convert the import path by using following setting. } ``` -``from`` is regular expression and ``to``is letter. In the internal ``from`` and ``to`` are used with ``String#replace(new RegExp (from), to)``. +### main [string] -When writing multi rules, it will also be carried out transformation many times. -For example, ``[{from: "^src/", to: "lib/"}, {from: "MyFooClass", to: "my-foo"}]`` converted as follows: +Prefer setting your project's `package.json` main property instead of using this override to better adhere to [npm docs's main spec](https://docs.npmjs.com/files/package.json#main). -- `` my-module/src/MyFooClass.js`` => `` my-module/lib/MyFooClass.js`` => ``my-module/lib/my-foo`` +**note:** Anytime main is set, the `option.replaces` transformation will be ignored. This includes either in esdoc-importpath-plugin's `option.main` or the package.json's `main` option. -# Install and Usage -```sh -npm install esdoc-importpath-plugin -``` +### replaces [array] + +Each item in the replaces should be an object consisting of `from` and `to` properties. + +``from`` is regular expression and ``to``is letter. In the internal ``from`` and ``to`` are used with ``String#replace(new RegExp (from), to)``. -setup ``plugin`` property in ``esdoc.json`` +When writing multi rules, the `replaces` transformations will be executed in the exact order that is defined in the array. +For example, ``my-module/src/MyFooClass.js`` => `` my-module/lib/MyFooClass.js`` => ``my-module/lib/my-foo`` with the following config: ```json +// esdocs.json { "source": "./src", "destination": "./doc", @@ -52,8 +56,10 @@ setup ``plugin`` property in ``esdoc.json`` { "name": "esdoc-importpath-plugin", "option": { + "main": "my-import-override", "replaces": [ - {"from": "^src/", "to": "lib"} + { from: "^src/", to: "lib/" }, + { from: "MyFooClass", to: "my-foo" } ] } } @@ -61,11 +67,33 @@ setup ``plugin`` property in ``esdoc.json`` } ``` -execute ESDoc +# Setup -```json -esdoc -c esdoc.json -``` +1. Install `esdoc-importpath-plugin`. + ```sh + $ npm install esdoc-importpath-plugin --save-dev + ``` +1. setup ``plugin`` property in ``esdoc.json`` + ```json + { + "source": "./src", + "destination": "./doc", + "plugins": [ + { + "name": "esdoc-importpath-plugin", + "option": { + "replaces": [ + {"from": "^src/", "to": "lib"} + ] + } + } + ] + } + ``` +1. Execute ESDoc + ```sh + $ esdoc -c esdoc.json + ``` # LICENSE MIT From ce0e776d89e1a3e2444fd9de2f677b1d0c6d5b68 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 03:24:12 -0700 Subject: [PATCH 08/17] add in more flexibility --- README.md | 37 +++++++++++---- src/Plugin.js | 44 ++++++++++-------- test/src/ImportPathTest.js | 94 ++++++++++++++++++++++++++++---------- 3 files changed, 123 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 6aa6fe5..a229097 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ Therefore, convert the import path by using following setting. { "name": "esdoc-importpath-plugin", "option": { - // setting the main ignores the replace - "main": "my-import-override", + // replaces will be ignored when setting the packageProp + "packageProp": "main", "replaces": [ {"from": "^src/", "to": "lib/"} ] @@ -32,15 +32,37 @@ Therefore, convert the import path by using following setting. } ``` -### main [string] +### packageProp [string] -Prefer setting your project's `package.json` main property instead of using this override to better adhere to [npm docs's main spec](https://docs.npmjs.com/files/package.json#main). +Resolves property inside the `package.json' file. Generally set to either `main` or `name`. Anytime packageProp is set, the `option.replaces` transformation will be ignored. -**note:** Anytime main is set, the `option.replaces` transformation will be ignored. This includes either in esdoc-importpath-plugin's `option.main` or the package.json's `main` option. +**note:** Prefer setting your project's `package.json` main property instead of using this override to better adhere to [npm docs's main spec](https://docs.npmjs.com/files/package.json#main). -### replaces [array] +### replaces [array] or [string] -Each item in the replaces should be an object consisting of `from` and `to` properties. +Replaces can be either an array or string. + +#### replaces [string] + +If replaces is a string, then the import path will always be that defined string. +```json +// esdocs.json +{ + "source": "./src", + "destination": "./doc", + "plugins": [ + { + "name": "esdoc-importpath-plugin", + "option": { + "replaces": "my-import-override", + } + } + ] +} +``` + +#### replaces [array] +Otherwise, if replaces is an array, then each item in the replaces must be an object consisting of `from` and `to` properties. ``from`` is regular expression and ``to``is letter. In the internal ``from`` and ``to`` are used with ``String#replace(new RegExp (from), to)``. @@ -56,7 +78,6 @@ For example, ``my-module/src/MyFooClass.js`` => `` my-module/lib/MyFooClass.js`` { "name": "esdoc-importpath-plugin", "option": { - "main": "my-import-override", "replaces": [ { from: "^src/", to: "lib/" }, { from: "MyFooClass", to: "my-foo" } diff --git a/src/Plugin.js b/src/Plugin.js index 2b2140f..f0466fa 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -9,8 +9,17 @@ let packageObj; */ export function onStart(ev) { option = ev.data.option; - for (let item of option.replaces) { - item.from = new RegExp(item.from); + + if (Array.isArray(option.replaces)) { + option.appendPackageName = option.appendPackageName; + option.replaces = option.replaces.map((item) => { + return { + to: item.to, + from: new RegExp(item.from), + }; + }); + } else if (typeof option.replaces === 'string') { + option.name = option.replaces; } } @@ -28,6 +37,9 @@ export function onHandleConfig(ev) { // ignore } } + if (typeof option.packageProp === 'string') { + option.name = packageObj[option.packageProp]; + } } /** @@ -36,36 +48,30 @@ export function onHandleConfig(ev) { */ export function onHandleTag(ev) { // get package.json - let packageName = packageObj.name; - let mainPath = packageObj.main; - for (let tag of ev.data.tag) { if (tag.importPath) { - tag.importPath = getImportPath(tag.importPath, packageName, mainPath || option.main); + tag.importPath = getImportPath(tag.importPath); } } } -function getImportPath(tagImportPath, packageName, mainPath) { - if (mainPath) { - // defines the import name defined by "main" - // https://docs.npmjs.com/files/package.json#main - return mainPath; +function getImportPath(tagImportPath) { + if (option.name) { + return option.name; } + // process the user's replace config. let importPath = tagImportPath; - if (packageName) { - importPath = importPath.replace(new RegExp(`^${packageName}/`), ''); + if (packageObj && packageObj.name) { + importPath = importPath.replace(new RegExp(`^${packageObj.name}/`), ''); } - - // process the user's replace config. - for (let item of option.replaces) { + (option.replaces || []).forEach((item) => { importPath = importPath.replace(item.from, item.to); - } + }); // add the package name to the beginning of the import path - if (packageName) { - return `${packageName}/${importPath}`; + if (option.appendPackageName) { + return `${packageObj.name}/${importPath}`; } return importPath; diff --git a/test/src/ImportPathTest.js b/test/src/ImportPathTest.js index cc5e375..0abd9c7 100644 --- a/test/src/ImportPathTest.js +++ b/test/src/ImportPathTest.js @@ -8,26 +8,34 @@ import defaultPublisher from 'esdoc/out/src/Publisher/publish.js'; * @test {onHandleTag} */ describe('Import Path', ()=> { - function assertPath(config, assertion) { + let id = 0; + function generateDocs(config, assertion) { + id += 1; + config.source = "./test/fixture/src"; + config.destination = `./test/fixture/esdoc_${ id }` ESDoc.generate(config, defaultPublisher); - const html = fs.readFileSync(config.destination + '/class/src/FooClass.js~FooClass.html').toString(); - assert(html.includes(assertion)); + return fs.readFileSync(config.destination + '/class/src/FooClass.js~FooClass.html').toString(); } - it('should convert using package name only', ()=> { - assertPath({ - "source": "./test/fixture/src", - "destination": "./test/fixture/esdoc1", + it('should show only path to file', ()=> { + const html = generateDocs({ "package": { "name": "esdoc-importpath-plugin" - } - }, '>esdoc-importpath-plugin/src/FooClass.js<'); + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + "appendPackageName": false, + } + } + ] + }); + assert(html.includes('>src/FooClass.js<')); }); - it('should convert using custom replacement', ()=> { - assertPath({ - "source": "./test/fixture/src", - "destination": "./test/fixture/esdoc2", + it('should append package name', ()=> { + const html = generateDocs({ "package": { "name": "esdoc-importpath-plugin" }, @@ -35,6 +43,41 @@ describe('Import Path', ()=> { { "name": "./src/Plugin.js", "option": { + "appendPackageName": true, + } + } + ] + }); + assert(html.includes('>esdoc-importpath-plugin/src/FooClass.js<')); + }); + + it('should convert using custom replacement string', ()=> { + const html = generateDocs({ + "package": { + "name": "MyPackageName" + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + "replaces": "esdoc-importpath-plugin", + } + } + ] + }); + assert(html.includes('>esdoc-importpath-plugin<')); + }); + + it('should convert using custom replacement array', ()=> { + const html = generateDocs({ + "package": { + "name": "esdoc-importpath-plugin" + }, + "plugins": [ + { + "name": "./src/Plugin.js", + "option": { + "appendPackageName": true, "replaces": [ {"from": "^src/", "to": "lib/"}, {"from": "^lib/FooClass.js", "to": "lib/foo"} @@ -42,21 +85,21 @@ describe('Import Path', ()=> { } } ] - }, '>esdoc-importpath-plugin/lib/foo<'); + }); + assert(html.includes('>esdoc-importpath-plugin/lib/foo<')); }); - it('should convert using custom main', ()=> { - assertPath({ - "source": "./test/fixture/src", - "destination": "./test/fixture/esdoc3", + it('should convert using package property name', ()=> { + const html = generateDocs({ "package": { - "name": "MyPackageName" + "name": "esdoc-importpath-plugin", + "main": "MyPackageMain" }, "plugins": [ { "name": "./src/Plugin.js", "option": { - "main": "esdoc-importpath-plugin", + packageProp: "name", // ignores these replacements "replaces": [ {"from": "^src/", "to": "lib/"}, @@ -64,13 +107,12 @@ describe('Import Path', ()=> { } } ] - }, '>esdoc-importpath-plugin<'); + }); + assert(html.includes('>esdoc-importpath-plugin<')); }); it('should convert using package main property', ()=>{ - assertPath({ - "source": "./test/fixture/src", - "destination": "./test/fixture/esdoc4", + const html = generateDocs({ "package": { "name": "MyPackageName", "main": "esdoc-importpath-plugin" @@ -79,6 +121,7 @@ describe('Import Path', ()=> { { "name": "./src/Plugin.js", "option": { + packageProp: "main", // ignores these replacements "replaces": [ {"from": "^src/", "to": "lib/"}, @@ -86,6 +129,7 @@ describe('Import Path', ()=> { } } ] - }, '>esdoc-importpath-plugin<'); + }); + assert(html.includes('>esdoc-importpath-plugin<')); }); }); From 277ed2b7e155047b921fd7b39857df75b61c9bc4 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 03:25:32 -0700 Subject: [PATCH 09/17] add the appendPackageName doc --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a229097..b3f61fd 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,9 @@ Therefore, convert the import path by using following setting. { "name": "esdoc-importpath-plugin", "option": { - // replaces will be ignored when setting the packageProp + // appendPackageName and replaces will be ignored when setting the packageProp "packageProp": "main", + "appendPackageName": true, "replaces": [ {"from": "^src/", "to": "lib/"} ] @@ -38,6 +39,10 @@ Resolves property inside the `package.json' file. Generally set to either `main` **note:** Prefer setting your project's `package.json` main property instead of using this override to better adhere to [npm docs's main spec](https://docs.npmjs.com/files/package.json#main). +### appendPackageName [boolean] + +Appends the package name to the import path. + ### replaces [array] or [string] Replaces can be either an array or string. From 63323a6bfdec1a57ef52e8c594753184c3044e21 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 21:59:46 -0700 Subject: [PATCH 10/17] remove es5 tests since it makes no sense --- package.json | 2 -- script/build.js | 11 ----------- script/test-es5.js | 14 -------------- 3 files changed, 27 deletions(-) delete mode 100644 script/build.js delete mode 100755 script/test-es5.js diff --git a/package.json b/package.json index 98feb17..597c817 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,7 @@ "url": "https://github.com/esdoc/esdoc-importpath-plugin" }, "scripts": { - "build": "node ./script/build.js", "test": "rm -rf ./test/fixture/esdoc* && node ./script/test.js", - "test-es5": "node ./script/test-es5.js", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, "devDependencies": { diff --git a/script/build.js b/script/build.js deleted file mode 100644 index 7ee2356..0000000 --- a/script/build.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node -var sh = require('./sh'); - -sh.rm('./out/src'); -sh.mkdir('./out/src'); -sh.exec('./node_modules/.bin/babel --out-dir out/src src'); - -// build test -sh.rm('./out/test/src'); -sh.mkdir('./out/test/src'); -sh.exec('./node_modules/.bin/babel --out-dir out/test/src test/src'); diff --git a/script/test-es5.js b/script/test-es5.js deleted file mode 100755 index 23670c9..0000000 --- a/script/test-es5.js +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env node -var sh = require('./sh'); - -var mochaOption=" -t 10000 --recursive ./out/test/src -R spec"; - -sh.exec('node ./script/build.js'); - -if (process.env.TRAVIS) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'); -} else if(process.argv.indexOf('--coverage') !== -1) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption); -} else { - sh.exec('./node_modules/.bin/mocha' + mochaOption); -} From 6aad9bcb265974382f5100d0d61a2ba431807398 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 22:56:09 -0700 Subject: [PATCH 11/17] remove es5 tests since it makes no sense (reverted from commit 63323a6bfdec1a57ef52e8c594753184c3044e21) --- package.json | 2 ++ script/build.js | 11 +++++++++++ script/test-es5.js | 14 ++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 script/build.js create mode 100755 script/test-es5.js diff --git a/package.json b/package.json index 597c817..98feb17 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "url": "https://github.com/esdoc/esdoc-importpath-plugin" }, "scripts": { + "build": "node ./script/build.js", "test": "rm -rf ./test/fixture/esdoc* && node ./script/test.js", + "test-es5": "node ./script/test-es5.js", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, "devDependencies": { diff --git a/script/build.js b/script/build.js new file mode 100644 index 0000000..7ee2356 --- /dev/null +++ b/script/build.js @@ -0,0 +1,11 @@ +#!/usr/bin/env node +var sh = require('./sh'); + +sh.rm('./out/src'); +sh.mkdir('./out/src'); +sh.exec('./node_modules/.bin/babel --out-dir out/src src'); + +// build test +sh.rm('./out/test/src'); +sh.mkdir('./out/test/src'); +sh.exec('./node_modules/.bin/babel --out-dir out/test/src test/src'); diff --git a/script/test-es5.js b/script/test-es5.js new file mode 100755 index 0000000..23670c9 --- /dev/null +++ b/script/test-es5.js @@ -0,0 +1,14 @@ +#!/usr/bin/env node +var sh = require('./sh'); + +var mochaOption=" -t 10000 --recursive ./out/test/src -R spec"; + +sh.exec('node ./script/build.js'); + +if (process.env.TRAVIS) { + sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'); +} else if(process.argv.indexOf('--coverage') !== -1) { + sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption); +} else { + sh.exec('./node_modules/.bin/mocha' + mochaOption); +} From e45d198fca7897f0826b5cbe4edce2dc48c58261 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 23:37:46 -0700 Subject: [PATCH 12/17] update babel to v6 --- .babelrc | 3 +++ package.json | 13 ++++++++----- script/build.js | 11 ----------- script/sh.js | 35 ----------------------------------- script/test-es5.js | 14 -------------- script/test.js | 12 ------------ test/espower-babel-loader.js | 4 ---- 7 files changed, 11 insertions(+), 81 deletions(-) create mode 100644 .babelrc delete mode 100644 script/build.js delete mode 100644 script/sh.js delete mode 100755 script/test-es5.js delete mode 100755 script/test.js delete mode 100644 test/espower-babel-loader.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/package.json b/package.json index 98feb17..c657dfd 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,19 @@ "url": "https://github.com/esdoc/esdoc-importpath-plugin" }, "scripts": { - "build": "node ./script/build.js", - "test": "rm -rf ./test/fixture/esdoc* && node ./script/test.js", - "test-es5": "node ./script/test-es5.js", + "build": "rm -rf out && mkdir -p out/src && babel -d out/src src", + "test": "rm -rf ./test/fixture/esdoc* && mocha -t 10000 -R spec --compilers js:babel-core/register --recursive ./test/src", + "coverage": "istanbul cover _mocha --report lcovonly -- -t 10000 --compilers js:babel-core/register --recursive ./test/src -R spec", + "travis": "npm build -s && npm coverage -s && cat ./coverage/lcov.info | coveralls", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, "devDependencies": { - "babel": "^5.8.20", + "babel-cli": "^6.9.0", + "babel-core": "^6.13.2", + "babel-eslint": "^6.1.0", + "babel-preset-es2015": "^6.1.18", "coveralls": "~2.11.2", "esdoc": "^0.4.8", - "espower-babel": "^3.2.0", "fs-extra": "^0.22.1", "istanbul": "~0.3.16", "mocha": "~2.2.5", diff --git a/script/build.js b/script/build.js deleted file mode 100644 index 7ee2356..0000000 --- a/script/build.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node -var sh = require('./sh'); - -sh.rm('./out/src'); -sh.mkdir('./out/src'); -sh.exec('./node_modules/.bin/babel --out-dir out/src src'); - -// build test -sh.rm('./out/test/src'); -sh.mkdir('./out/test/src'); -sh.exec('./node_modules/.bin/babel --out-dir out/test/src test/src'); diff --git a/script/sh.js b/script/sh.js deleted file mode 100644 index 4b9408f..0000000 --- a/script/sh.js +++ /dev/null @@ -1,35 +0,0 @@ -var fs = require('fs-extra'); -var path = require('path'); -var child_process = require('child_process'); - -function rm(path) { - fs.removeSync(path); -} - -function mkdir(path) { - fs.mkdirs(path); -} - -function exec(cmd) { - cmd = cmd.replace(/\//g, path.sep); - child_process.execSync(cmd, {stdio: 'inherit'}); -} - -function chmod(path, mode) { - fs.chmodSync(path, mode); -} - -function cp(src, dst) { - fs.copySync(src, dst); -} - -function cd(dst) { - process.chdir(dst); -} - -module.exports.rm = rm; -module.exports.mkdir = mkdir; -module.exports.exec = exec; -module.exports.chmod = chmod; -module.exports.cp = cp; -module.exports.cd = cd; diff --git a/script/test-es5.js b/script/test-es5.js deleted file mode 100755 index 23670c9..0000000 --- a/script/test-es5.js +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env node -var sh = require('./sh'); - -var mochaOption=" -t 10000 --recursive ./out/test/src -R spec"; - -sh.exec('node ./script/build.js'); - -if (process.env.TRAVIS) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'); -} else if(process.argv.indexOf('--coverage') !== -1) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption); -} else { - sh.exec('./node_modules/.bin/mocha' + mochaOption); -} diff --git a/script/test.js b/script/test.js deleted file mode 100755 index ee0bfa9..0000000 --- a/script/test.js +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node -var sh = require('./sh'); - -var mochaOption=" -t 10000 --require ./node_modules/babel/register.js --require ./test/espower-babel-loader.js --recursive ./test/src -R spec"; - -if (process.env.TRAVIS) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- ' + mochaOption + ' && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'); -} else if(process.argv.indexOf('--coverage') !== -1) { - sh.exec('./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- ' + mochaOption); -} else { - sh.exec('./node_modules/.bin/mocha' + mochaOption); -} diff --git a/test/espower-babel-loader.js b/test/espower-babel-loader.js deleted file mode 100644 index 554bb58..0000000 --- a/test/espower-babel-loader.js +++ /dev/null @@ -1,4 +0,0 @@ -require('espower-babel')({ - cwd: process.cwd(), - pattern: 'test/src/**/*Test.js' -}); From 6c949746d4615d6f7761e26b047217308e1a8d34 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Tue, 23 Aug 2016 23:41:17 -0700 Subject: [PATCH 13/17] update the travis build --- .travis.yml | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8e103bf..3d008af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,10 @@ language: node_js sudo: false node_js: - "0.12" + script: - - TRAVIS=1 npm run test-es5 + - npm run build + - npm run coverage:travis + install: - npm install diff --git a/package.json b/package.json index c657dfd..bc9bd3d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "rm -rf out && mkdir -p out/src && babel -d out/src src", "test": "rm -rf ./test/fixture/esdoc* && mocha -t 10000 -R spec --compilers js:babel-core/register --recursive ./test/src", "coverage": "istanbul cover _mocha --report lcovonly -- -t 10000 --compilers js:babel-core/register --recursive ./test/src -R spec", - "travis": "npm build -s && npm coverage -s && cat ./coverage/lcov.info | coveralls", + "coverage:travis": "npm coverage -s && cat ./coverage/lcov.info | coveralls", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, "devDependencies": { From 968c0cb4887bc0e02db319fcc48403d761493c81 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Wed, 24 Aug 2016 00:41:19 -0700 Subject: [PATCH 14/17] fix the coverage:travis task --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc9bd3d..376feda 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "rm -rf out && mkdir -p out/src && babel -d out/src src", "test": "rm -rf ./test/fixture/esdoc* && mocha -t 10000 -R spec --compilers js:babel-core/register --recursive ./test/src", "coverage": "istanbul cover _mocha --report lcovonly -- -t 10000 --compilers js:babel-core/register --recursive ./test/src -R spec", - "coverage:travis": "npm coverage -s && cat ./coverage/lcov.info | coveralls", + "coverage:travis": "npm run coverage -s && cat ./coverage/lcov.info | coveralls", "esdoc": "./node_modules/.bin/esdoc -c esdoc.json" }, "devDependencies": { From eea4809c9a0dc332f33453187faf1d27d98fbae5 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Wed, 24 Aug 2016 00:42:48 -0700 Subject: [PATCH 15/17] add check whether packageObj exists --- src/Plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.js b/src/Plugin.js index f0466fa..1d3b344 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -37,7 +37,7 @@ export function onHandleConfig(ev) { // ignore } } - if (typeof option.packageProp === 'string') { + if (typeof option.packageProp === 'string' && packageObj) { option.name = packageObj[option.packageProp]; } } From 31b6d59fe38f67c39859f74659f8ed90730505ad Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Wed, 24 Aug 2016 09:25:52 -0700 Subject: [PATCH 16/17] update travis.yml to node v6.3.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3d008af..2243f80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js sudo: false node_js: - - "0.12" + - "6.3.1" script: - npm run build From 7e8cfc70a289a3b4d8dc21fc2d6ffba2370c7fb7 Mon Sep 17 00:00:00 2001 From: Bret Ikehara Date: Wed, 24 Aug 2016 23:19:01 -0700 Subject: [PATCH 17/17] add test packages --- test/src/ImportPathTest.js | 38 ++++++++++++------------------------- test/src/pkg--calcium.json | 3 +++ test/src/pkg--hydrogen.json | 3 +++ test/src/pkg--lysine.json | 4 ++++ 4 files changed, 22 insertions(+), 26 deletions(-) create mode 100644 test/src/pkg--calcium.json create mode 100644 test/src/pkg--hydrogen.json create mode 100644 test/src/pkg--lysine.json diff --git a/test/src/ImportPathTest.js b/test/src/ImportPathTest.js index 0abd9c7..5dc43e9 100644 --- a/test/src/ImportPathTest.js +++ b/test/src/ImportPathTest.js @@ -19,9 +19,7 @@ describe('Import Path', ()=> { it('should show only path to file', ()=> { const html = generateDocs({ - "package": { - "name": "esdoc-importpath-plugin" - }, + "package": './test/src/pkg--calcium.json', "plugins": [ { "name": "./src/Plugin.js", @@ -36,9 +34,7 @@ describe('Import Path', ()=> { it('should append package name', ()=> { const html = generateDocs({ - "package": { - "name": "esdoc-importpath-plugin" - }, + "package": './test/src/pkg--calcium.json', "plugins": [ { "name": "./src/Plugin.js", @@ -48,31 +44,27 @@ describe('Import Path', ()=> { } ] }); - assert(html.includes('>esdoc-importpath-plugin/src/FooClass.js<')); + assert(html.includes('>calcium/src/FooClass.js<')); }); it('should convert using custom replacement string', ()=> { const html = generateDocs({ - "package": { - "name": "MyPackageName" - }, + "package": './test/src/pkg--hydrogen.json', "plugins": [ { "name": "./src/Plugin.js", "option": { - "replaces": "esdoc-importpath-plugin", + "replaces": "calcium", } } ] }); - assert(html.includes('>esdoc-importpath-plugin<')); + assert(html.includes('>calcium<')); }); it('should convert using custom replacement array', ()=> { const html = generateDocs({ - "package": { - "name": "esdoc-importpath-plugin" - }, + "package": './test/src/pkg--calcium.json', "plugins": [ { "name": "./src/Plugin.js", @@ -86,15 +78,12 @@ describe('Import Path', ()=> { } ] }); - assert(html.includes('>esdoc-importpath-plugin/lib/foo<')); + assert(html.includes('>calcium/lib/foo<')); }); it('should convert using package property name', ()=> { const html = generateDocs({ - "package": { - "name": "esdoc-importpath-plugin", - "main": "MyPackageMain" - }, + "package": './test/src/pkg--lysine.json', "plugins": [ { "name": "./src/Plugin.js", @@ -108,15 +97,12 @@ describe('Import Path', ()=> { } ] }); - assert(html.includes('>esdoc-importpath-plugin<')); + assert(html.includes('>lysine<')); }); it('should convert using package main property', ()=>{ const html = generateDocs({ - "package": { - "name": "MyPackageName", - "main": "esdoc-importpath-plugin" - }, + "package": './test/src/pkg--lysine.json', "plugins": [ { "name": "./src/Plugin.js", @@ -130,6 +116,6 @@ describe('Import Path', ()=> { } ] }); - assert(html.includes('>esdoc-importpath-plugin<')); + assert(html.includes('>lib/lysine.js<')); }); }); diff --git a/test/src/pkg--calcium.json b/test/src/pkg--calcium.json new file mode 100644 index 0000000..676a105 --- /dev/null +++ b/test/src/pkg--calcium.json @@ -0,0 +1,3 @@ +{ + "name": "calcium" +} \ No newline at end of file diff --git a/test/src/pkg--hydrogen.json b/test/src/pkg--hydrogen.json new file mode 100644 index 0000000..7c7aa21 --- /dev/null +++ b/test/src/pkg--hydrogen.json @@ -0,0 +1,3 @@ +{ + "name": "hydrogen" +} \ No newline at end of file diff --git a/test/src/pkg--lysine.json b/test/src/pkg--lysine.json new file mode 100644 index 0000000..937e7a0 --- /dev/null +++ b/test/src/pkg--lysine.json @@ -0,0 +1,4 @@ +{ + "name": "lysine", + "main": "lib/lysine.js" +} \ No newline at end of file