summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/recipetool/create_npm.py48
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
18import logging
19import json
20from recipetool.create import RecipeHandler
21
22logger = logging.getLogger('recipetool')
23
24
25class 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
47def register_recipe_handlers(handlers):
48 handlers.append((NpmRecipeHandler(), 60))