1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | 'use strict';
|
26 |
|
27 | var _fs = require('fs');
|
28 |
|
29 | var _path = require('path');
|
30 |
|
31 | var _chalk = require('chalk');
|
32 |
|
33 | var _findRoot = require('find-root');
|
34 |
|
35 | var _findRoot2 = _interopRequireDefault(_findRoot);
|
36 |
|
37 | var _updateNotifier = require('update-notifier');
|
38 |
|
39 | var _updateNotifier2 = _interopRequireDefault(_updateNotifier);
|
40 |
|
41 | var _commander = require('commander');
|
42 |
|
43 | var _commander2 = _interopRequireDefault(_commander);
|
44 |
|
45 | var _utils = require('./utils');
|
46 |
|
47 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function getThemeRoot(directory) {
|
55 | try {
|
56 | return (0, _path.normalize)((0, _findRoot2.default)(directory));
|
57 | } catch (err) {
|
58 | return null;
|
59 | }
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | function checkForSlateTools(themeRoot) {
|
68 | var pkgPath = (0, _path.join)(themeRoot, 'package.json');
|
69 | var pkg = require(pkgPath);
|
70 |
|
71 | return (0, _utils.hasDependency)('@shopify/slate-tools', pkg);
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function outputSlateThemeCheck(isSlateTheme) {
|
80 | if (isSlateTheme) {
|
81 | console.log(' Slate theme: ' + (0, _chalk.green)('✓') + ' inside slate theme directory');
|
82 | console.log('');
|
83 | } else {
|
84 | console.log(' Slate theme: ' + (0, _chalk.red)('✗') + ' switch to a slate theme directory for full list of commands');
|
85 | console.log('');
|
86 | }
|
87 | }
|
88 |
|
89 | var currentDirectory = __dirname;
|
90 | var workingDirectory = process.cwd();
|
91 | var pkg = require((0, _path.join)(currentDirectory, (0, _path.normalize)('../package.json')));
|
92 |
|
93 | (0, _updateNotifier2.default)({
|
94 | pkg: pkg,
|
95 | updateCheckInterval: 1000 * 60 * 60 * 24 * 7 }).notify();
|
96 |
|
97 |
|
98 | require('./commands/theme').default(_commander2.default);
|
99 | require('./commands/version').default(_commander2.default);
|
100 |
|
101 |
|
102 | var themeRoot = getThemeRoot(workingDirectory);
|
103 | var isSlateTheme = themeRoot && checkForSlateTools(themeRoot);
|
104 |
|
105 | if (isSlateTheme) {
|
106 | (function () {
|
107 | var slateToolsCommands = (0, _path.join)(themeRoot, (0, _path.normalize)('/node_modules/@shopify/slate-tools/lib/commands'));
|
108 |
|
109 | (0, _fs.readdirSync)(slateToolsCommands).filter(function (file) {
|
110 | return ~file.search(/^[^\.].*\.js$/);
|
111 | }).forEach(function (file) {
|
112 | return require((0, _path.join)(slateToolsCommands, file)).default(_commander2.default);
|
113 | });
|
114 | })();
|
115 | }
|
116 |
|
117 |
|
118 | _commander2.default.on('--help', function () {
|
119 | outputSlateThemeCheck(isSlateTheme);
|
120 | });
|
121 |
|
122 |
|
123 | _commander2.default.on('*', function () {
|
124 | console.log('');
|
125 | console.log(' Unknown command: ' + (0, _chalk.red)(_commander2.default.args.join(' ')));
|
126 | console.log('');
|
127 | _commander2.default.help();
|
128 | outputSlateThemeCheck(isSlateTheme);
|
129 | });
|
130 |
|
131 | _commander2.default.parse(process.argv); |
\ | No newline at end of file |