diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-03-01 00:48:26 +1300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-03-02 23:08:51 +0000 |
| commit | 5c5c13d77783e96b9acbbe460bf7060722f436cb (patch) | |
| tree | 266518e31803eca52ceca1f98541b573e31b80fd /scripts/lib/recipetool/create_npm.py | |
| parent | 2be37a93738a8562e2958bc57b144a73ad96fae2 (diff) | |
| download | poky-5c5c13d77783e96b9acbbe460bf7060722f436cb.tar.gz | |
recipetool: create: add basic support for new npm fetcher/class
Add detection for npm modules and support for extracting the name and
version from package.json as is usually part of an npm module contents.
Note: this will likely only produce a buildable recipe if you use an
npm:// URL; simply pointing to a node.js source repository isn't going
to fetch the module's dependencies. It also doesn't set up the
shrinkwrap/lockdown automatically, so there is some room for improvement
later.
Implements [YOCTO #8690].
(From OE-Core rev: 41d0e4d75f13b53a6c1b6a8df9be4742be7534e0)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool/create_npm.py')
| -rw-r--r-- | scripts/lib/recipetool/create_npm.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py new file mode 100644 index 0000000000..0e33cc9a1e --- /dev/null +++ b/scripts/lib/recipetool/create_npm.py | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | # Recipe creation tool - node.js NPM module support plugin | ||
| 2 | # | ||
| 3 | # Copyright (C) 2016 Intel Corporation | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify | ||
| 6 | # it under the terms of the GNU General Public License version 2 as | ||
| 7 | # published by the Free Software Foundation. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | |||
| 18 | import logging | ||
| 19 | import json | ||
| 20 | from recipetool.create import RecipeHandler | ||
| 21 | |||
| 22 | logger = logging.getLogger('recipetool') | ||
| 23 | |||
| 24 | |||
| 25 | class NpmRecipeHandler(RecipeHandler): | ||
| 26 | def process(self, srctree, classes, lines_before, lines_after, handled, extravalues): | ||
| 27 | if 'buildsystem' in handled: | ||
| 28 | return False | ||
| 29 | |||
| 30 | files = RecipeHandler.checkfiles(srctree, ['package.json']) | ||
| 31 | if files: | ||
| 32 | with open(files[0], 'r') as f: | ||
| 33 | data = json.loads(f.read()) | ||
| 34 | if 'name' in data and 'version' in data: | ||
| 35 | extravalues['PN'] = data['name'] | ||
| 36 | extravalues['PV'] = data['version'] | ||
| 37 | classes.append('npm') | ||
| 38 | handled.append('buildsystem') | ||
| 39 | if 'description' in data: | ||
| 40 | lines_before.append('SUMMARY = "%s"' % data['description']) | ||
| 41 | if 'homepage' in data: | ||
| 42 | lines_before.append('HOMEPAGE = "%s"' % data['homepage']) | ||
| 43 | return True | ||
| 44 | |||
| 45 | return False | ||
| 46 | |||
| 47 | def register_recipe_handlers(handlers): | ||
| 48 | handlers.append((NpmRecipeHandler(), 60)) | ||
