You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

762 lines
19 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. /*******************************
  2. Set-up
  3. *******************************/
  4. var
  5. fs = require('fs'),
  6. path = require('path'),
  7. defaults = require('../defaults'),
  8. release = require('./release'),
  9. requireDotFile = require('require-dot-file')
  10. ;
  11. /*******************************
  12. When to Ask
  13. *******************************/
  14. /* Preconditions for install questions */
  15. var when = {
  16. // path
  17. changeRoot: function(questions) {
  18. return (questions.useRoot !== undefined && questions.useRoot !== true);
  19. },
  20. // permissions
  21. changePermissions: function(questions) {
  22. return (questions.changePermissions && questions.changePermissions === true);
  23. },
  24. // install
  25. hasConfig: function() {
  26. return requireDotFile('semantic.json');
  27. },
  28. allowOverwrite: function(questions) {
  29. return (questions.overwrite === undefined || questions.overwrite == 'yes');
  30. },
  31. notAuto: function(questions) {
  32. return (questions.install !== 'auto' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  33. },
  34. custom: function(questions) {
  35. return (questions.install === 'custom' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  36. },
  37. express: function(questions) {
  38. return (questions.install === 'express' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
  39. },
  40. // customize
  41. customize: function(questions) {
  42. return (questions.customize === true);
  43. },
  44. primaryColor: function(questions) {
  45. return (questions.primaryColor);
  46. },
  47. secondaryColor: function(questions) {
  48. return (questions.secondaryColor);
  49. }
  50. };
  51. /*******************************
  52. Response Filters
  53. *******************************/
  54. /* Filters to user input from install questions */
  55. var filter = {
  56. removeTrailingSlash: function(path) {
  57. return path.replace(/(\/$|\\$)+/mg, '');
  58. }
  59. };
  60. /*******************************
  61. Configuration
  62. *******************************/
  63. module.exports = {
  64. // check whether install is setup
  65. isSetup: function() {
  66. return when.hasConfig();
  67. },
  68. // checks if files are in a PM directory
  69. getPackageManager: function(directory) {
  70. var
  71. // returns last matching result (avoid sub-module detection)
  72. walk = function(directory) {
  73. var
  74. pathArray = directory.split(path.sep),
  75. folder = pathArray[pathArray.length - 1],
  76. nextDirectory = path.join(directory, path.sep, '..')
  77. ;
  78. if( folder == 'bower_components') {
  79. return {
  80. name: 'Bower',
  81. root: nextDirectory
  82. };
  83. }
  84. else if(folder == 'node_modules') {
  85. return {
  86. name: 'NPM',
  87. root: nextDirectory
  88. };
  89. }
  90. else if(folder == 'composer') {
  91. return {
  92. name: 'Composer',
  93. root: nextDirectory
  94. };
  95. }
  96. if(path.resolve(directory) == path.resolve(nextDirectory)) {
  97. return false;
  98. }
  99. // recurse downward
  100. return walk(nextDirectory);
  101. }
  102. ;
  103. // start walk from current directory if none specified
  104. directory = directory || (__dirname + path.sep);
  105. return walk(directory);
  106. },
  107. // checks if files is PMed submodule
  108. isSubModule: function(directory) {
  109. var
  110. moduleFolders = 0,
  111. walk = function(directory) {
  112. var
  113. pathArray = directory.split(path.sep),
  114. folder = pathArray[pathArray.length - 2],
  115. nextDirectory = path.join(directory, path.sep, '..')
  116. ;
  117. if( folder == 'bower_components') {
  118. moduleFolders++;
  119. }
  120. else if(folder == 'node_modules') {
  121. moduleFolders++;
  122. }
  123. else if(folder == 'composer') {
  124. moduleFolders++;
  125. }
  126. if(path.resolve(directory) == path.resolve(nextDirectory)) {
  127. return (moduleFolders > 1);
  128. }
  129. // recurse downward
  130. return walk(nextDirectory);
  131. }
  132. ;
  133. // start walk from current directory if none specified
  134. directory = directory || (__dirname + path.sep);
  135. return walk(directory);
  136. },
  137. createJSON: function(answers) {
  138. var
  139. json = {
  140. paths: {
  141. source: {},
  142. output: {}
  143. }
  144. }
  145. ;
  146. // add components
  147. if(answers.components) {
  148. json.components = answers.components;
  149. }
  150. // add rtl choice
  151. if(answers.rtl) {
  152. json.rtl = answers.rtl;
  153. }
  154. // add permissions
  155. if(answers.permission) {
  156. json.permission = answers.permission;
  157. }
  158. // add path to semantic
  159. if(answers.semanticRoot) {
  160. json.base = path.normalize(answers.semanticRoot);
  161. }
  162. // record version number to avoid re-installing on same version
  163. json.version = release.version;
  164. // add dist folder paths
  165. if(answers.dist) {
  166. answers.dist = path.normalize(answers.dist);
  167. json.paths.output = {
  168. packaged : path.normalize(answers.dist + '/'),
  169. uncompressed : path.normalize(answers.dist + '/components/'),
  170. compressed : path.normalize(answers.dist + '/components/'),
  171. themes : path.normalize(answers.dist + '/themes/')
  172. };
  173. }
  174. // add site path
  175. if(answers.site) {
  176. json.paths.source.site = path.normalize(answers.site + '/');
  177. }
  178. if(answers.packaged) {
  179. json.paths.output.packaged = path.normalize(answers.packaged + '/');
  180. }
  181. if(answers.compressed) {
  182. json.paths.output.compressed = path.normalize(answers.compressed + '/');
  183. }
  184. if(answers.uncompressed) {
  185. json.paths.output.uncompressed = path.normalize(answers.uncompressed + '/');
  186. }
  187. return json;
  188. },
  189. // files cleaned up after install
  190. setupFiles: [
  191. './src/theme.config.example',
  192. './semantic.json.example',
  193. './src/_site'
  194. ],
  195. regExp: {
  196. // used to match siteFolder variable in theme.less
  197. siteVariable: /@siteFolder .*\'(.*)/mg
  198. },
  199. // source paths (relative to tasks/install.js )
  200. source: {
  201. config : './semantic.json.example',
  202. definitions : './src/definitions',
  203. gulpFile : './gulpfile.js',
  204. lessImport : './src/semantic.less',
  205. site : './src/_site',
  206. tasks : './tasks',
  207. themeConfig : './src/theme.config.example',
  208. themeImport : './src/theme.less',
  209. themes : './src/themes',
  210. userGulpFile : './tasks/config/npm/gulpfile.js'
  211. },
  212. // expected final filenames
  213. files: {
  214. config : 'semantic.json',
  215. lessImport : 'src/semantic.less',
  216. site : 'src/site',
  217. themeConfig : 'src/theme.config',
  218. themeImport : 'src/theme.less'
  219. },
  220. // folder paths to files relative to root
  221. folders: {
  222. config : './',
  223. definitions : 'src/definitions/',
  224. lessImport : 'src/',
  225. modules : 'node_modules/',
  226. site : 'src/site/',
  227. tasks : 'tasks/',
  228. themeConfig : 'src/',
  229. themeImport : 'src/',
  230. themes : 'src/themes/'
  231. },
  232. // questions asked during install
  233. questions: {
  234. root: [
  235. {
  236. type : 'list',
  237. name : 'useRoot',
  238. message :
  239. ' \n' +
  240. ' {packageMessage} \n' +
  241. ' \n' +
  242. ' Is this your project folder?\n' +
  243. ' \033[92m{root}\033[0m \n' +
  244. ' \n ' +
  245. '\n',
  246. choices: [
  247. {
  248. name : 'Yes',
  249. value : true
  250. },
  251. {
  252. name : 'No, let me specify',
  253. value : false
  254. }
  255. ]
  256. },
  257. {
  258. type : 'input',
  259. name : 'customRoot',
  260. message : 'Please enter the absolute path to your project root',
  261. default : '/my/project/path',
  262. when : when.changeRoot
  263. },
  264. {
  265. type : 'input',
  266. name : 'semanticRoot',
  267. message : 'Where should we put Semantic UI inside your project?',
  268. default : 'semantic/'
  269. }
  270. ],
  271. setup: [
  272. {
  273. type: 'list',
  274. name: 'overwrite',
  275. message: 'It looks like you have a semantic.json file already.',
  276. when: when.hasConfig,
  277. choices: [
  278. {
  279. name: 'Yes, extend my current settings.',
  280. value: 'yes'
  281. },
  282. {
  283. name: 'Skip install',
  284. value: 'no'
  285. }
  286. ]
  287. },
  288. {
  289. type: 'list',
  290. name: 'install',
  291. message: 'Set-up Semantic UI',
  292. when: when.allowOverwrite,
  293. choices: [
  294. {
  295. name: 'Automatic (Use defaults locations and all components)',
  296. value: 'auto'
  297. },
  298. {
  299. name: 'Express (Set components and output folder)',
  300. value: 'express'
  301. },
  302. {
  303. name: 'Custom (Customize all src/dist values)',
  304. value: 'custom'
  305. }
  306. ]
  307. },
  308. {
  309. type: 'checkbox',
  310. name: 'components',
  311. message: 'What components should we include in the package?',
  312. // duplicated manually from tasks/defaults.js with additional property
  313. choices: [
  314. { name: "reset", checked: true },
  315. { name: "site", checked: true },
  316. { name: "button", checked: true },
  317. { name: "container", checked: true },
  318. { name: "divider", checked: true },
  319. { name: "flag", checked: true },
  320. { name: "header", checked: true },
  321. { name: "icon", checked: true },
  322. { name: "image", checked: true },
  323. { name: "input", checked: true },
  324. { name: "label", checked: true },
  325. { name: "list", checked: true },
  326. { name: "loader", checked: true },
  327. { name: "rail", checked: true },
  328. { name: "reveal", checked: true },
  329. { name: "segment", checked: true },
  330. { name: "step", checked: true },
  331. { name: "breadcrumb", checked: true },
  332. { name: "form", checked: true },
  333. { name: "grid", checked: true },
  334. { name: "menu", checked: true },
  335. { name: "message", checked: true },
  336. { name: "table", checked: true },
  337. { name: "ad", checked: true },
  338. { name: "card", checked: true },
  339. { name: "comment", checked: true },
  340. { name: "feed", checked: true },
  341. { name: "item", checked: true },
  342. { name: "statistic", checked: true },
  343. { name: "accordion", checked: true },
  344. { name: "checkbox", checked: true },
  345. { name: "dimmer", checked: true },
  346. { name: "dropdown", checked: true },
  347. { name: "modal", checked: true },
  348. { name: "nag", checked: true },
  349. { name: "popup", checked: true },
  350. { name: "progress", checked: true },
  351. { name: "rating", checked: true },
  352. { name: "search", checked: true },
  353. { name: "shape", checked: true },
  354. { name: "sidebar", checked: true },
  355. { name: "sticky", checked: true },
  356. { name: "tab", checked: true },
  357. { name: "transition", checked: true },
  358. { name: "video", checked: true },
  359. { name: "api", checked: true },
  360. { name: "form", checked: true },
  361. { name: "state", checked: true },
  362. { name: "visibility", checked: true }
  363. ],
  364. when: when.notAuto
  365. },
  366. {
  367. type: 'list',
  368. name: 'changePermisions',
  369. when: when.notAuto,
  370. message: 'Should we set permissions on outputted files?',
  371. choices: [
  372. {
  373. name: 'No',
  374. value: false
  375. },
  376. {
  377. name: 'Yes',
  378. value: true
  379. },
  380. ]
  381. },
  382. {
  383. type: 'input',
  384. name: 'permission',
  385. message: 'What octal file permission should outputted files receive?',
  386. default: defaults.permission,
  387. when: when.changePermissions
  388. },
  389. {
  390. type: 'list',
  391. name: 'rtl',
  392. message: 'Do you use a RTL (Right-To-Left) language?',
  393. when: when.notAuto,
  394. choices: [
  395. {
  396. name: 'No',
  397. value: false
  398. },
  399. {
  400. name: 'Yes',
  401. value: true
  402. },
  403. ]
  404. },
  405. {
  406. type: 'input',
  407. name: 'dist',
  408. message: 'Where should we output Semantic UI?',
  409. default: defaults.paths.output.packaged,
  410. filter: filter.removeTrailingSlash,
  411. when: when.express
  412. },
  413. {
  414. type: 'input',
  415. name: 'site',
  416. message: 'Where should we put your site folder?',
  417. default: defaults.paths.source.site,
  418. filter: filter.removeTrailingSlash,
  419. when: when.custom
  420. },
  421. {
  422. type: 'input',
  423. name: 'packaged',
  424. message: 'Where should we output a packaged version?',
  425. default: defaults.paths.output.packaged,
  426. filter: filter.removeTrailingSlash,
  427. when: when.custom
  428. },
  429. {
  430. type: 'input',
  431. name: 'compressed',
  432. message: 'Where should we output compressed components?',
  433. default: defaults.paths.output.compressed,
  434. filter: filter.removeTrailingSlash,
  435. when: when.custom
  436. },
  437. {
  438. type: 'input',
  439. name: 'uncompressed',
  440. message: 'Where should we output uncompressed components?',
  441. default: defaults.paths.output.uncompressed,
  442. filter: filter.removeTrailingSlash,
  443. when: when.custom
  444. }
  445. ],
  446. cleanup: [
  447. {
  448. type: 'list',
  449. name: 'cleanup',
  450. message: 'Should we remove set-up files?',
  451. choices: [
  452. {
  453. name: 'Yes (re-install will require redownloading semantic).',
  454. value: 'yes'
  455. },
  456. {
  457. name: 'No Thanks',
  458. value: 'no'
  459. }
  460. ]
  461. },
  462. {
  463. type: 'list',
  464. name: 'build',
  465. message: 'Do you want to build Semantic now?',
  466. choices: [
  467. {
  468. name: 'Yes',
  469. value: 'yes'
  470. },
  471. {
  472. name: 'No',
  473. value: 'no'
  474. }
  475. ]
  476. },
  477. ],
  478. site: [
  479. {
  480. type: 'list',
  481. name: 'customize',
  482. message: 'You have not yet customized your site, can we help you do that?',
  483. choices: [
  484. {
  485. name: 'Yes, ask me a few questions',
  486. value: true
  487. },
  488. {
  489. name: 'No I\'ll do it myself',
  490. value: false
  491. }
  492. ]
  493. },
  494. {
  495. type: 'list',
  496. name: 'headerFont',
  497. message: 'Select your header font',
  498. choices: [
  499. {
  500. name: 'Helvetica Neue, Arial, sans-serif',
  501. value: 'Helvetica Neue, Arial, sans-serif;'
  502. },
  503. {
  504. name: 'Lato (Google Fonts)',
  505. value: 'Lato'
  506. },
  507. {
  508. name: 'Open Sans (Google Fonts)',
  509. value: 'Open Sans'
  510. },
  511. {
  512. name: 'Source Sans Pro (Google Fonts)',
  513. value: 'Source Sans Pro'
  514. },
  515. {
  516. name: 'Droid (Google Fonts)',
  517. value: 'Droid'
  518. },
  519. {
  520. name: 'I\'ll choose on my own',
  521. value: false
  522. }
  523. ],
  524. when: when.customize
  525. },
  526. {
  527. type: 'list',
  528. name: 'pageFont',
  529. message: 'Select your page font',
  530. choices: [
  531. {
  532. name: 'Helvetica Neue, Arial, sans-serif',
  533. value: 'Helvetica Neue, Arial, sans-serif;'
  534. },
  535. {
  536. name: 'Lato (Import from Google Fonts)',
  537. value: 'Lato'
  538. },
  539. {
  540. name: 'Open Sans (Import from Google Fonts)',
  541. value: 'Open Sans'
  542. },
  543. {
  544. name: 'Source Sans Pro (Import from Google Fonts)',
  545. value: 'Source Sans Pro'
  546. },
  547. {
  548. name: 'Droid (Google Fonts)',
  549. value: 'Droid'
  550. },
  551. {
  552. name: 'I\'ll choose on my own',
  553. value: false
  554. }
  555. ],
  556. when: when.customize
  557. },
  558. {
  559. type: 'list',
  560. name: 'fontSize',
  561. message: 'Select your base font size',
  562. default: '14px',
  563. choices: [
  564. {
  565. name: '12px',
  566. },
  567. {
  568. name: '13px',
  569. },
  570. {
  571. name: '14px (Recommended)',
  572. value: '14px'
  573. },
  574. {
  575. name: '15px',
  576. },
  577. {
  578. name: '16px',
  579. },
  580. {
  581. name: 'I\'ll choose on my own',
  582. value: false
  583. }
  584. ],
  585. when: when.customize
  586. },
  587. {
  588. type: 'list',
  589. name: 'primaryColor',
  590. message: 'Select the closest name for your primary brand color',
  591. default: '14px',
  592. choices: [
  593. {
  594. name: 'Blue'
  595. },
  596. {
  597. name: 'Green'
  598. },
  599. {
  600. name: 'Orange'
  601. },
  602. {
  603. name: 'Pink'
  604. },
  605. {
  606. name: 'Purple'
  607. },
  608. {
  609. name: 'Red'
  610. },
  611. {
  612. name: 'Teal'
  613. },
  614. {
  615. name: 'Yellow'
  616. },
  617. {
  618. name: 'Black'
  619. },
  620. {
  621. name: 'I\'ll choose on my own',
  622. value: false
  623. }
  624. ],
  625. when: when.customize
  626. },
  627. {
  628. type: 'input',
  629. name: 'PrimaryHex',
  630. message: 'Enter a hexcode for your primary brand color',
  631. when: when.primaryColor
  632. },
  633. {
  634. type: 'list',
  635. name: 'secondaryColor',
  636. message: 'Select the closest name for your secondary brand color',
  637. default: '14px',
  638. choices: [
  639. {
  640. name: 'Blue'
  641. },
  642. {
  643. name: 'Green'
  644. },
  645. {
  646. name: 'Orange'
  647. },
  648. {
  649. name: 'Pink'
  650. },
  651. {
  652. name: 'Purple'
  653. },
  654. {
  655. name: 'Red'
  656. },
  657. {
  658. name: 'Teal'
  659. },
  660. {
  661. name: 'Yellow'
  662. },
  663. {
  664. name: 'Black'
  665. },
  666. {
  667. name: 'I\'ll choose on my own',
  668. value: false
  669. }
  670. ],
  671. when: when.customize
  672. },
  673. {
  674. type: 'input',
  675. name: 'secondaryHex',
  676. message: 'Enter a hexcode for your secondary brand color',
  677. when: when.secondaryColor
  678. }
  679. ]
  680. },
  681. settings: {
  682. /* Rename Files */
  683. rename: {
  684. json : { extname : '.json' },
  685. },
  686. /* Copy Install Folders */
  687. wrench: {
  688. // copy during npm update (default theme / definition)
  689. update: {
  690. forceDelete : true,
  691. excludeHiddenUnix : true,
  692. preserveFiles : false
  693. },
  694. // copy during first npm install
  695. install: {
  696. forceDelete : true,
  697. excludeHiddenUnix : true,
  698. preserveFiles : false
  699. },
  700. // copy for node_modules
  701. modules: {
  702. forceDelete : true,
  703. excludeHiddenUnix : true,
  704. preserveFiles : false
  705. },
  706. // copy for site theme
  707. site: {
  708. forceDelete : false,
  709. excludeHiddenUnix : true,
  710. preserveFiles : true
  711. }
  712. }
  713. }
  714. };